UNPKG

foalts2-cli

Version:

CLI tool for FoalTS

35 lines (34 loc) 1.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.initGitRepo = void 0; const child_process_1 = require("child_process"); // This file is inspired by the Angular CLI (MIT License: https://angular.io/license). // See https://github.com/angular/angular-cli/blob/master/packages/angular_devkit/schematics/tasks/repo-init/executor.ts async function initGitRepo(root) { function execute(args) { return new Promise((resolve, reject) => { child_process_1.spawn('git', args, { cwd: root, shell: true }) .on('close', (code) => code === 0 ? resolve() : reject(code)); }); } const hasCommand = await execute(['--version']).then(() => true, () => false); if (!hasCommand) { console.log(' Git not installed. Skipping initialization of git.'); return; } const insideRepo = await execute(['rev-parse', '--is-inside-work-tree']) .then(() => true, () => false); if (insideRepo) { console.log(' Directory is already under version control. Skipping initialization of git.'); return; } try { await execute(['init']); await execute(['add', '.']); await execute(['commit', '-m "Initial commit"']); } catch (_a) { console.log(' Initialization of git failed.'); } } exports.initGitRepo = initGitRepo;