UNPKG

@coat/cli

Version:

TODO: See #3

48 lines (43 loc) 1.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.addInitialCommit = addInitialCommit; var _execa = _interopRequireDefault(require("execa")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * Initializes a git repository and creates an initial * commit with all generated files. * * If git is unavailable, or the project is already a part of * a git repository, no git repository or commit will be created * * @param cwd The working directory of the newly created coat project */ async function addInitialCommit(cwd) { // Check whether the project already is a part of a git // repository and whether git is available const gitResult = await (0, _execa.default)("git", ["rev-parse", "--is-inside-work-tree"], { cwd, reject: false }); // 128 is the exit code if git rev-parse is run outside // a working tree. If any other error code is returned, // git is either unavailable or the project is inside // another git repository if (gitResult.exitCode !== 128) { return; } // Initialize a new git repository await (0, _execa.default)("git", ["init"], { cwd }); // Add all untracked files await (0, _execa.default)("git", ["add", "--all"], { cwd }); // Add an initial commit with all generated files await (0, _execa.default)("git", ["commit", "-m", "Initialize project using coat create"], { cwd }); }