ghostify
Version:
A ghost theme deployer
93 lines (92 loc) • 3.68 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const minimist_1 = __importDefault(require("minimist"));
const path_1 = require("path");
const fs_1 = require("fs");
// @ts-ignore
const logging_1 = __importDefault(require("@tryghost/logging"));
const _1 = __importDefault(require("."));
// @ts-ignore
const errors_1 = __importDefault(require("@tryghost/errors"));
let args = (0, minimist_1.default)(process.argv.slice(2), {
alias: {
c: "config",
h: "help",
q: "quiet",
p: "preserve"
}
});
if (args.help) {
console.log("ghostify help\n\n"
+ "Usage: ghostify <config file or theme path> [options]\n\n"
+ "Basic options:\n\n"
+ "-c, --config <filename> the ghostify.json config containing your admin api key and url and others theme informations \n"
+ "-q, --quiet do not output the deployment logs: default is false\n"
+ "-p, --preserve whever to keep the zip theme after deploy : default is false\n"
+ "-h, --help output this help and exit\n\n"
+ "Exemples: \n\n"
+ "# use in theme base directory\n$ ghostify \n\n"
+ "# specify the config file\n$ ghostify -c[onfig] <file path>\n$ ghostify <config file path>\n\n"
+ "# specify the theme base path containing the config file and package.json\n"
+ "$ ghostify <theme path>");
process.exit(0);
}
let configPath = (0, path_1.resolve)(args.config || args._[0] || process.cwd());
let debug = !args.quiet;
let basePath, pkgPath;
if ((0, fs_1.statSync)(configPath).isDirectory()) {
basePath = configPath;
configPath = (0, path_1.resolve)(basePath, "ghostify.js");
if (!(0, fs_1.existsSync)(configPath)) {
configPath = (0, path_1.resolve)(basePath, "ghostify.json");
}
}
else {
basePath = (0, path_1.dirname)(configPath);
}
pkgPath = (0, path_1.resolve)(basePath, "package.json");
if (!(0, fs_1.existsSync)(configPath)) {
logging_1.default.error("there is no config file");
process.exit(1);
}
let { apiKey, apiUrl, themeName, excludes, preserve } = require(configPath.replace(/\\/g, "/"));
themeName = themeName || (() => { try {
return require(pkgPath.replace(/\\/g, "/"));
}
catch (err) {
return {};
} })().name;
if (!(apiKey && apiUrl && themeName)) {
logging_1.default.error("those value are required: apiKey, apiUrl, and themeName but seam to be absent");
process.exit(1);
}
preserve = args.preserve !== undefined ? args.preserve : preserve;
let startTime = Date.now();
logging_1.default.info("starting deploy of theme " + themeName);
(0, _1.default)({
apiKey,
apiUrl,
themeName,
basePath,
excludes,
preserve,
debug
}).then((res) => {
let elipsed = ((Date.now() - startTime) / 1000).toFixed(3);
if (res === null || res === void 0 ? void 0 : res.errors) {
logging_1.default.error(res.errors);
return;
}
return logging_1.default.info("deploy finished successfuly withing " + elipsed + " s.");
}).catch(error => {
if (!errors_1.default.utils.isGhostError(error)) {
if (error.type && errors_1.default[error.type]) {
error = new errors_1.default[error.type](Object.assign(Object.assign({}, error), { message: error.message, errorDetails: error.details }));
}
return logging_1.default.error(error);
}
logging_1.default.error(error);
});