npmize
Version:
Let's create an npm package without worrying about anything.
78 lines (77 loc) • 3.63 kB
JavaScript
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const app = __importStar(require("./app"));
const dev_1 = __importDefault(require("./program/dev"));
const init_1 = __importDefault(require("./program/init"));
const build_1 = __importDefault(require("./program/build"));
const utils_1 = require("./utils");
const ansi_colors_1 = __importDefault(require("ansi-colors"));
const tsconfig_1 = require("./scripts/tsconfig");
app.app.on((_, flags) => {
if (flags.version) {
console.log((0, utils_1.getVersion)());
}
else
app.app.renderHelp();
});
app.init.on(([name = '.'], flags) => {
const root = path_1.default.resolve(name);
(0, init_1.default)(root, {
writeSample: flags.sample,
writePackageJSON: flags.pkg,
installPackages: flags.install,
writeGitIgnore: flags.ignore && flags.gitignore,
writeNpmIgnore: flags.ignore && flags.npmignore,
writeTSConfig: flags.tsconfig,
ghWorkflow: flags.workflow,
});
});
app.dev.on(([root = '.', railingArgs], options) => {
const rootPath = path_1.default.resolve(root);
const tsConfig = (0, tsconfig_1.readTSConfig)(rootPath);
if (!tsConfig) {
return console.log(ansi_colors_1.default.bgRed(' ERROR: '), 'Could not find "tsconfig.json"');
}
if (!(tsConfig === null || tsConfig === void 0 ? void 0 : tsConfig.outDir)) {
return console.log(ansi_colors_1.default.bgRed(' ERROR: '), 'The "outDir" option is required in "tsconfig.json"');
}
(0, dev_1.default)(rootPath, Object.assign(Object.assign({}, options), { tsc: railingArgs, tsConfig: Object.assign(Object.assign({}, tsConfig), { outDir: tsConfig.outDir }) }));
});
app.build.on(([root = '.', railingArgs], options) => {
const rootPath = path_1.default.resolve(root);
const tsConfig = (0, tsconfig_1.readTSConfig)(rootPath);
if (!tsConfig) {
return console.log(ansi_colors_1.default.bgRed(' ERROR: '), 'Could not find "tsconfig.json"');
}
if (!(tsConfig === null || tsConfig === void 0 ? void 0 : tsConfig.outDir)) {
return console.log(ansi_colors_1.default.bgRed(' ERROR: '), 'The "outDir" option is required in "tsconfig.json"');
}
(0, build_1.default)(rootPath, Object.assign(Object.assign({}, options), { tsc: railingArgs, tsConfig: Object.assign(Object.assign({}, tsConfig), { outDir: tsConfig.outDir }) }));
});
;