Merge branch 'main' of github.com:outline/outline
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
require("dotenv").config({ silent: true });
|
||||
|
||||
const errors = [];
|
||||
const boxen = require("boxen");
|
||||
const chalk = require("chalk");
|
||||
const throng = require("throng");
|
||||
|
||||
// If the DataDog agent is installed and the DD_API_KEY environment variable is
|
||||
// in the environment then we can safely attempt to start the DD tracer
|
||||
@@ -66,7 +66,7 @@ if (!process.env.URL) {
|
||||
);
|
||||
}
|
||||
|
||||
if (!process.env.DATABASE_URL) {
|
||||
if (!process.env.DATABASE_URL && !process.env.DATABASE_CONNECTION_POOL_URL) {
|
||||
errors.push(
|
||||
`The ${chalk.bold(
|
||||
"DATABASE_URL"
|
||||
@@ -95,11 +95,10 @@ if (errors.length) {
|
||||
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
console.log(
|
||||
boxen(
|
||||
chalk.green(
|
||||
`
|
||||
Is your team enjoying Outline? Consider supporting future development by sponsoring the project:\n\nhttps://github.com/sponsors/outline
|
||||
`,
|
||||
{ padding: 1, margin: 1, borderStyle: "double", borderColor: "green" }
|
||||
`
|
||||
)
|
||||
);
|
||||
} else if (process.env.NODE_ENV === "development") {
|
||||
@@ -112,4 +111,11 @@ Is your team enjoying Outline? Consider supporting future development by sponsor
|
||||
);
|
||||
}
|
||||
|
||||
require("./main");
|
||||
const { start } = require("./main");
|
||||
|
||||
throng({
|
||||
worker: start,
|
||||
|
||||
// The number of workers to run, defaults to the number of CPUs available
|
||||
count: process.env.WEB_CONCURRENCY || undefined,
|
||||
});
|
||||
|
||||
@@ -234,10 +234,12 @@ server.on("listening", () => {
|
||||
console.log(`\n> Listening on http://localhost:${address.port}\n`);
|
||||
});
|
||||
|
||||
(async () => {
|
||||
export async function start(id: string) {
|
||||
console.log(`Started worker ${id}`);
|
||||
|
||||
await checkMigrations();
|
||||
server.listen(process.env.PORT || "3000");
|
||||
})();
|
||||
}
|
||||
|
||||
export const socketio = io;
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import Sequelize, { Transaction } from "sequelize";
|
||||
import MarkdownSerializer from "slate-md-serializer";
|
||||
import isUUID from "validator/lib/isUUID";
|
||||
import { MAX_TITLE_LENGTH } from "../../shared/constants";
|
||||
import getTasks from "../../shared/utils/getTasks";
|
||||
import parseTitle from "../../shared/utils/parseTitle";
|
||||
import { SLUG_URL_REGEX } from "../../shared/utils/routeHelpers";
|
||||
import unescape from "../../shared/utils/unescape";
|
||||
@@ -106,6 +107,9 @@ const Document = sequelize.define(
|
||||
const slugifiedTitle = slugify(this.title);
|
||||
return `/doc/${slugifiedTitle}-${this.urlId}`;
|
||||
},
|
||||
tasks: function () {
|
||||
return getTasks(this.text || "");
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
@@ -430,3 +430,79 @@ describe("#findByPk", () => {
|
||||
expect(response.id).toBe(document.id);
|
||||
});
|
||||
});
|
||||
|
||||
describe("tasks", () => {
|
||||
test("should consider all the possible checkTtems", async () => {
|
||||
const document = await buildDocument({
|
||||
text: `- [x] test
|
||||
- [X] test
|
||||
- [ ] test
|
||||
- [-] test
|
||||
- [_] test`,
|
||||
});
|
||||
|
||||
const tasks = document.tasks;
|
||||
|
||||
expect(tasks.completed).toBe(4);
|
||||
expect(tasks.total).toBe(5);
|
||||
});
|
||||
|
||||
test("should return tasks keys set to 0 if checkItems isn't present", async () => {
|
||||
const document = await buildDocument({
|
||||
text: `text`,
|
||||
});
|
||||
|
||||
const tasks = document.tasks;
|
||||
|
||||
expect(tasks.completed).toBe(0);
|
||||
expect(tasks.total).toBe(0);
|
||||
});
|
||||
|
||||
test("should return tasks keys set to 0 if the text contains broken checkItems", async () => {
|
||||
const document = await buildDocument({
|
||||
text: `- [x ] test
|
||||
- [ x ] test
|
||||
- [ ] test`,
|
||||
});
|
||||
|
||||
const tasks = document.tasks;
|
||||
|
||||
expect(tasks.completed).toBe(0);
|
||||
expect(tasks.total).toBe(0);
|
||||
});
|
||||
|
||||
test("should return tasks", async () => {
|
||||
const document = await buildDocument({
|
||||
text: `- [x] list item
|
||||
- [ ] list item`,
|
||||
});
|
||||
|
||||
const tasks = document.tasks;
|
||||
|
||||
expect(tasks.completed).toBe(1);
|
||||
expect(tasks.total).toBe(2);
|
||||
});
|
||||
|
||||
test("should update tasks on save", async () => {
|
||||
const document = await buildDocument({
|
||||
text: `- [x] list item
|
||||
- [ ] list item`,
|
||||
});
|
||||
|
||||
const tasks = document.tasks;
|
||||
|
||||
expect(tasks.completed).toBe(1);
|
||||
expect(tasks.total).toBe(2);
|
||||
|
||||
document.text = `- [x] list item
|
||||
- [ ] list item
|
||||
- [ ] list item`;
|
||||
|
||||
await document.save();
|
||||
|
||||
const newTasks = document.tasks;
|
||||
|
||||
expect(newTasks.completed).toBe(1);
|
||||
expect(newTasks.total).toBe(3);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -44,6 +44,7 @@ export default async function present(document: Document, options: ?Options) {
|
||||
title: document.title,
|
||||
text,
|
||||
emoji: document.emoji,
|
||||
tasks: document.tasks,
|
||||
createdAt: document.createdAt,
|
||||
createdBy: undefined,
|
||||
updatedAt: document.updatedAt,
|
||||
|
||||
@@ -12,16 +12,19 @@ export const encryptedFields = () =>
|
||||
export const DataTypes = Sequelize;
|
||||
export const Op = Sequelize.Op;
|
||||
|
||||
export const sequelize = new Sequelize(process.env.DATABASE_URL, {
|
||||
logging: debug("sql"),
|
||||
typeValidation: true,
|
||||
dialectOptions: {
|
||||
ssl:
|
||||
isProduction && !isSSLDisabled
|
||||
? {
|
||||
// Ref.: https://github.com/brianc/node-postgres/issues/2009
|
||||
rejectUnauthorized: false,
|
||||
}
|
||||
: false,
|
||||
},
|
||||
});
|
||||
export const sequelize = new Sequelize(
|
||||
process.env.DATABASE_URL || process.env.DATABASE_CONNECTION_POOL_URL,
|
||||
{
|
||||
logging: debug("sql"),
|
||||
typeValidation: true,
|
||||
dialectOptions: {
|
||||
ssl:
|
||||
isProduction && !isSSLDisabled
|
||||
? {
|
||||
// Ref.: https://github.com/brianc/node-postgres/issues/2009
|
||||
rejectUnauthorized: false,
|
||||
}
|
||||
: false,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user