|
|
@@ -12,35 +12,117 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
|
};
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
+const child_process_1 = require("child_process");
|
|
|
const fs_1 = __importDefault(require("fs"));
|
|
|
-const shell_1 = require("node-utils/shell");
|
|
|
-const file_1 = require("node-utils/file");
|
|
|
const path_1 = __importDefault(require("path"));
|
|
|
const util_1 = __importDefault(require("util"));
|
|
|
+const MAX_BUFFER = 10 * Math.pow(2, 20);
|
|
|
+function exec(command, stdout, stderr) {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ try {
|
|
|
+ let stdoutbuf = '';
|
|
|
+ let stderrbuf = '';
|
|
|
+ // EXEC CHILD PROCESS
|
|
|
+ const p = child_process_1.exec(command, { maxBuffer: MAX_BUFFER }, (err, out) => {
|
|
|
+ if (err)
|
|
|
+ return reject(err);
|
|
|
+ if (stdoutbuf.length > 0 && typeof stdout === 'function')
|
|
|
+ stdout(stdoutbuf);
|
|
|
+ if (stderrbuf.length > 0 && typeof stderr === 'function')
|
|
|
+ stderr(stderrbuf);
|
|
|
+ resolve(out);
|
|
|
+ });
|
|
|
+ // PIPE STDOUT
|
|
|
+ if (typeof stdout === 'function') {
|
|
|
+ p.stdout.on('data', chunk => {
|
|
|
+ stdoutbuf += chunk;
|
|
|
+ let i = -1;
|
|
|
+ while ((i = stdoutbuf.indexOf('\n')) >= 0) {
|
|
|
+ const line = stdoutbuf.substring(0, i);
|
|
|
+ stdoutbuf = stdoutbuf.substring(i + 1);
|
|
|
+ if (typeof stdout === 'function') {
|
|
|
+ stdout(line);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else if (typeof stdout !== 'undefined') {
|
|
|
+ p.stdout.pipe(stdout);
|
|
|
+ }
|
|
|
+ // PIPE STDERR
|
|
|
+ if (typeof stderr === 'function') {
|
|
|
+ p.stderr.on('data', chunk => {
|
|
|
+ stderrbuf += chunk;
|
|
|
+ let i = -1;
|
|
|
+ while ((i = stderrbuf.indexOf('\n')) >= 0) {
|
|
|
+ const line = stderrbuf.substring(0, i);
|
|
|
+ stderrbuf = stderrbuf.substring(i + 1);
|
|
|
+ if (typeof stderr === 'function') {
|
|
|
+ stderr(line);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else if (typeof stderr !== 'undefined') {
|
|
|
+ p.stderr.pipe(stderr);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ reject(err);
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+exports.exec = exec;
|
|
|
const cli = {
|
|
|
blue: v => `\x1b[34m${v}\x1b[0m`,
|
|
|
green: v => `\x1b[32m${v}\x1b[0m`,
|
|
|
yellow: v => `\x1b[33m${v}\x1b[0m`,
|
|
|
red: v => `\x1b[31m${v}\x1b[0m`
|
|
|
};
|
|
|
+function readFile(path, encoding = 'utf8') {
|
|
|
+ return __awaiter(this, void 0, void 0, function* () {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ fs_1.default.readFile(path, { encoding }, (err, data) => {
|
|
|
+ if (err)
|
|
|
+ return reject(err);
|
|
|
+ try {
|
|
|
+ resolve(data.toString());
|
|
|
+ }
|
|
|
+ catch (e) {
|
|
|
+ reject(e);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+}
|
|
|
+function readJsonFile(path, encoding = 'utf8') {
|
|
|
+ return __awaiter(this, void 0, void 0, function* () {
|
|
|
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
|
+ try {
|
|
|
+ resolve(JSON.parse(yield readFile(path, encoding)));
|
|
|
+ }
|
|
|
+ catch (e) {
|
|
|
+ reject(e);
|
|
|
+ }
|
|
|
+ }));
|
|
|
+ });
|
|
|
+}
|
|
|
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
try {
|
|
|
const projectRootDir = path_1.default.resolve(process.cwd());
|
|
|
if (!fs_1.default.existsSync(path_1.default.resolve(projectRootDir, 'package.json'))) {
|
|
|
- yield shell_1.exec('npm init -y', process.stdout, process.stderr);
|
|
|
+ yield exec('npm init -y', process.stdout, process.stderr);
|
|
|
}
|
|
|
const cloneDir = path_1.default.resolve(projectRootDir, '.clone');
|
|
|
if (fs_1.default.existsSync(cloneDir)) {
|
|
|
yield util_1.default.promisify(fs_1.default.rm)(cloneDir, { force: true, recursive: true });
|
|
|
}
|
|
|
- yield shell_1.exec(`git clone ssh://git@bitbucket.siriusonline.de:7999/tsc/express-starter.git "${cloneDir}"`, process.stdout, process.stderr);
|
|
|
- const pkgJson = yield file_1.readJsonFile(path_1.default.resolve(cloneDir, 'package.json'));
|
|
|
+ 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 dependencies = Object.keys(pkgJson.dependencies).join('" "');
|
|
|
- yield shell_1.exec(`npm install "${dependencies}"`, process.stdout, process.stderr);
|
|
|
- dependencies = Object.keys(pkgJson.devDependencies)
|
|
|
- .filter(d => d !== 'node-utils')
|
|
|
- .join('" "');
|
|
|
- yield shell_1.exec(`npm install --save-dev "${dependencies}"`, process.stdout, process.stderr);
|
|
|
+ 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);
|
|
|
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);
|
|
|
@@ -55,7 +137,7 @@ const cli = {
|
|
|
yield util_1.default.promisify(fs_1.default.copyFile)(sourceFile, targetFile);
|
|
|
}
|
|
|
else {
|
|
|
- yield shell_1.exec(`cp -r "${sourceFile}" "${targetFile}"`);
|
|
|
+ yield exec(`cp -r "${sourceFile}" "${targetFile}"`);
|
|
|
}
|
|
|
}
|
|
|
yield util_1.default.promisify(fs_1.default.rm)(cloneDir, { force: true, recursive: true });
|