|
|
@@ -111,25 +111,29 @@ function readJsonFile(path, encoding = 'utf8') {
|
|
|
try {
|
|
|
const projectRootDir = path_1.default.resolve(process.cwd());
|
|
|
if (!fs_1.default.existsSync(path_1.default.resolve(projectRootDir, 'package.json'))) {
|
|
|
+ console.log(cli.blue('[INFO]'), 'Not an NPM project yet - initializing...');
|
|
|
yield exec('npm init -y', process.stdout, process.stderr);
|
|
|
}
|
|
|
const cloneDir = path_1.default.resolve(projectRootDir, '.clone');
|
|
|
if (fs_1.default.existsSync(cloneDir)) {
|
|
|
+ console.log(cli.blue('[WARNING]'), `There's an old .clone directory. Removing first...`);
|
|
|
yield util_1.default.promisify(fs_1.default.rm)(cloneDir, { force: true, recursive: true });
|
|
|
}
|
|
|
+ console.log(cli.blue('[INFO]'), 'Cloning boilerplate repository (via SSH)...');
|
|
|
yield exec(`git clone ssh://git@bitbucket.siriusonline.de:7999/tsc/express-starter.git "${cloneDir}"`, process.stdout, process.stderr);
|
|
|
- const pkgJson = yield readJsonFile(path_1.default.resolve(cloneDir, 'package.json'));
|
|
|
+ let pkgJson = yield readJsonFile(path_1.default.resolve(cloneDir, 'package.json'));
|
|
|
+ console.log(cli.blue('[INFO]'), 'Installing module dependencies...');
|
|
|
let dependencies = Object.keys(pkgJson.dependencies).join('" "');
|
|
|
yield exec(`npm install "${dependencies}"`, process.stdout, process.stderr);
|
|
|
dependencies = Object.keys(pkgJson.devDependencies).join('" "');
|
|
|
yield exec(`npm install --save-dev "${dependencies}"`, process.stdout, process.stderr);
|
|
|
+ console.log(cli.blue('[INFO]'), 'Copying project files...');
|
|
|
const copyFiles = ['.env', '.gitignore', '.prettierrc.js', 'tsconfig.json', '.vscode/settings.json', 'src'];
|
|
|
for (const cpFile of copyFiles) {
|
|
|
const sourceFile = path_1.default.resolve(cloneDir, cpFile);
|
|
|
const targetFile = path_1.default.resolve(projectRootDir, cpFile);
|
|
|
const targetDir = path_1.default.dirname(targetFile);
|
|
|
if (!fs_1.default.existsSync(targetDir)) {
|
|
|
- console.log(cli.blue('[INFO]'), 'Creating directory recursively:', targetDir);
|
|
|
yield util_1.default.promisify(fs_1.default.mkdir)(targetDir, { recursive: true, mode: 0o777 });
|
|
|
}
|
|
|
const stat = yield util_1.default.promisify(fs_1.default.stat)(sourceFile);
|
|
|
@@ -140,7 +144,13 @@ function readJsonFile(path, encoding = 'utf8') {
|
|
|
yield exec(`cp -r "${sourceFile}" "${targetFile}"`);
|
|
|
}
|
|
|
}
|
|
|
+ console.log(cli.blue('[INFO]'), 'Creating startup script');
|
|
|
+ pkgJson = yield readJsonFile(path_1.default.resolve(projectRootDir, 'package.json'));
|
|
|
+ pkgJson.scripts = Object.assign(Object.assign({}, pkgJson.scripts), { build: 'tsc -b', start: 'npm run build && node dist/index.js' });
|
|
|
+ console.log(cli.blue('[INFO]'), 'Cleanup: Removing .clone directory...');
|
|
|
yield util_1.default.promisify(fs_1.default.rm)(cloneDir, { force: true, recursive: true });
|
|
|
+ console.log();
|
|
|
+ console.log(cli.green('[SUCCESS] You can now start your express server with `npm start`'));
|
|
|
process.exit(0);
|
|
|
}
|
|
|
catch (e) {
|