UNPKG

tuture

Version:

Write tutorials from the future, with the power of Git and community.

55 lines (54 loc) 2.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const child_process_1 = tslib_1.__importDefault(require("child_process")); const fs_extra_1 = tslib_1.__importDefault(require("fs-extra")); const command_1 = require("@oclif/command"); const inquirer_1 = require("inquirer"); const base_1 = tslib_1.__importDefault(require("../base")); const logger_1 = tslib_1.__importDefault(require("../utils/logger")); const git_1 = require("../utils/git"); const collection_1 = require("../utils/collection"); const constants_1 = require("../constants"); class Commit extends base_1.default { async run() { const { flags } = this.parse(Commit); this.userConfig = Object.assign(this.userConfig, flags); const message = flags.message || (await inquirer_1.prompt([ { name: 'message', type: 'input', default: `Commit on ${new Date()}`, }, ])).message; await collection_1.initializeTutureBranch(); // Checkout tuture branch and add tuture.yml. await git_1.git.checkout(constants_1.TUTURE_BRANCH); // Trying to copy and add collection data to staging. fs_extra_1.default.copySync(collection_1.collectionPath, collection_1.collectionVcsPath); await git_1.git.add(collection_1.collectionVcsPath); // COMPAT: remove collection.json and tuture-assets.json from project root. if (fs_extra_1.default.existsSync(constants_1.COLLECTION_PATH)) { await git_1.git.rm(constants_1.COLLECTION_PATH); } if (fs_extra_1.default.existsSync(constants_1.ASSETS_JSON_PATH)) { await git_1.git.rm(constants_1.ASSETS_JSON_PATH); } fs_extra_1.default.removeSync(collection_1.collectionCheckpoint); // Commit changes to tuture branch. child_process_1.default.execSync(`git commit --allow-empty -m "tuture: ${message}"`); logger_1.default.log('success', `Committed to branch ${constants_1.TUTURE_BRANCH} (${message})`); // Copy the last committed file. await collection_1.saveCheckpoint(); } } exports.default = Commit; Commit.description = 'Commit your tutorial to VCS (Git)'; Commit.flags = { help: command_1.flags.help({ char: 'h' }), message: command_1.flags.string({ char: 'm', description: 'commit message', }), };