burdy
Version:
Open Source Headless Platform
133 lines (132 loc) • 6.92 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const chalk_1 = __importDefault(require("chalk"));
const commander_1 = require("commander");
const fs_extra_1 = __importDefault(require("fs-extra"));
const package_json_1 = __importDefault(require("../package.json"));
const path_util_1 = __importDefault(require("./scripts/util/path.util"));
const console_output_util_1 = __importDefault(require("./scripts/util/console-output.util"));
const path_1 = __importDefault(require("path"));
const program = new commander_1.Command();
const start = () => __awaiter(void 0, void 0, void 0, function* () {
var _a;
process.env.NODE_ENV = (_a = process.env.NODE_ENV) !== null && _a !== void 0 ? _a : 'production';
const scriptPath = path_util_1.default.build('main.js');
const scriptExists = yield fs_extra_1.default.pathExists(scriptPath);
if (!scriptExists) {
console_output_util_1.default.error(`Build has not been found. Try running ${chalk_1.default.magentaBright('burdy build')} before.`);
process.exit(1);
}
require(scriptPath);
});
const build = () => __awaiter(void 0, void 0, void 0, function* () {
var _b;
process.env.NODE_ENV = (_b = process.env.NODE_ENV) !== null && _b !== void 0 ? _b : 'production';
yield require("./scripts/build").default();
});
const dev = () => __awaiter(void 0, void 0, void 0, function* () {
var _c;
process.env.NODE_ENV = (_c = process.env.NODE_ENV) !== null && _c !== void 0 ? _c : 'development';
yield require("./scripts/dev").default();
});
const db = () => __awaiter(void 0, void 0, void 0, function* () {
var _d, _e, _f;
process.env.NODE_ENV = (_d = process.env.NODE_ENV) !== null && _d !== void 0 ? _d : 'development';
process.env.TYPEORM_MIGRATIONS = (_e = process.env.TYPEORM_MIGRATIONS) !== null && _e !== void 0 ? _e : path_1.default.join('burdy', 'migrations', '*.[tj]s');
process.env.TYPEORM_MIGRATIONS_DIR = (_f = process.env.TYPEORM_MIGRATIONS_DIR) !== null && _f !== void 0 ? _f : path_1.default.join('burdy', 'migrations');
const dbScriptPath = path_util_1.default.cache('db-build', 'main.js');
yield require("./scripts/db-cli").default();
process.argv.splice(2, 1);
process.argv[1] = 'burdy db';
if (process.argv[2] === 'migration:generate') {
process.argv.push('-o');
}
require(dbScriptPath);
});
const exportContentTypes = () => __awaiter(void 0, void 0, void 0, function* () {
var _g, _h, _j;
process.env.NODE_ENV = (_g = process.env.NODE_ENV) !== null && _g !== void 0 ? _g : 'development';
const ctScriptPath = path_util_1.default.cache('ct-build', 'main.js');
yield require("./scripts/content-types").default((_j = (_h = process.argv) === null || _h === void 0 ? void 0 : _h[3]) !== null && _j !== void 0 ? _j : 'export', process.argv.slice(4));
require(ctScriptPath);
});
const handleDbAction = (action) => __awaiter(void 0, void 0, void 0, function* () {
var _k;
process.env.NODE_ENV = (_k = process.env.NODE_ENV) !== null && _k !== void 0 ? _k : 'development';
const script = path_util_1.default.cache('db-actions', 'main.js');
yield require("./scripts/db-actions").default(action);
require(script);
});
const importContent = (file, options) => __awaiter(void 0, void 0, void 0, function* () {
return handleDbAction({
type: 'import',
payload: {
force: (options === null || options === void 0 ? void 0 : options.force) || false,
publish: (options === null || options === void 0 ? void 0 : options.publish) || false,
file
}
});
});
const exportContent = (file, options) => __awaiter(void 0, void 0, void 0, function* () {
return handleDbAction({
type: 'export',
payload: {
force: (options === null || options === void 0 ? void 0 : options.force) || false,
file
}
});
});
const generateApiKey = (name) => __awaiter(void 0, void 0, void 0, function* () {
return handleDbAction({
type: 'generateApiKey',
payload: { name }
});
});
// Initial program setup
program.storeOptionsAsProperties(false).allowUnknownOption(true);
program.helpOption('-h, --help', 'Display help for command');
program.addHelpCommand('help [command]', 'Display help for command');
// `$ burdy version` (--version synonym)
program.version(package_json_1.default.version, '-v, --version', 'Output the version number');
program
.command('version')
.description('Output your version of Burdy')
.action(() => {
process.stdout.write(`${package_json_1.default.version}\n`);
process.exit(0);
});
program.command('start').description('Start your Burdy application').action(start);
program.command('build').description('Build your Burdy application').action(build);
program.command('dev').description('Develop your Burdy server').action(dev);
program.command('db').allowUnknownOption(true).helpOption(false).description('Run TypeORM commands').action(db);
program.command('export')
.addArgument(new commander_1.Argument('<file>', 'name of the export file (zip).').argOptional())
.addOption(new commander_1.Option('-f, --force', 'force overwrite existing file during export').default(false))
.action(exportContent);
program.command('import')
.addArgument(new commander_1.Argument('<file>', 'input file to be restored.').argOptional())
.addOption(new commander_1.Option('-p, --publish', 'publishes the imported pages and posts').default(false))
.addOption(new commander_1.Option('-f, --force', 'force overwrite existing file during export').default(false))
.action(importContent);
program.command('generate:key')
.addArgument(new commander_1.Argument('<name>', 'api key name.').argRequired())
.action(generateApiKey);
const contentTypeCommands = program.command('ct').description('Content type helpers');
contentTypeCommands
.command('export')
.description('Exports content type defined in components')
.action(exportContentTypes);
program.parseAsync(process.argv);