create-new-express-app
Version:
A CLI tool to create a TypeScript Express application with best practices
52 lines (51 loc) • 1.76 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.install = install;
/* eslint-disable import/no-extraneous-dependencies */
const picocolors_1 = require("picocolors");
const cross_spawn_1 = __importDefault(require("cross-spawn"));
/**
* Spawn a package manager installation based on user preference.
*
* @returns A Promise that resolves once the installation is finished.
*/
async function install(
/** Indicate which package manager to use. */
packageManager,
/** Indicate whether there is an active Internet connection.*/
isOnline) {
const args = ["install"];
if (!isOnline) {
console.log((0, picocolors_1.yellow)("You appear to be offline.\nFalling back to the local cache."));
args.push("--offline");
}
/**
* Return a Promise that resolves once the installation is finished.
*/
return new Promise((resolve, reject) => {
/**
* Spawn the installation process.
*/
const child = (0, cross_spawn_1.default)(packageManager, args, {
stdio: "inherit",
env: {
...process.env,
ADBLOCK: "1",
// we set NODE_ENV to development as pnpm skips dev
// dependencies when production
NODE_ENV: "development",
DISABLE_OPENCOLLECTIVE: "1",
},
});
child.on("close", (code) => {
if (code !== 0) {
reject({ command: `${packageManager} ${args.join(" ")}` });
return;
}
resolve();
});
});
}