UNPKG

@dojo/cli

Version:

Dojo CLI utility

99 lines 4.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const fs_extra_1 = require("fs-extra"); const path_1 = require("path"); const chalk_1 = require("chalk"); const inquirer = require("inquirer"); const allCommands_1 = require("../allCommands"); const npmInstall_1 = require("../npmInstall"); const configurationHelper_1 = require("../configurationHelper"); const { green, underline, yellow } = chalk_1.default; const copiedFilesDir = 'config'; const ejectedKey = 'ejected'; function isEjectableCommandWrapper(object) { return typeof object.eject === 'function'; } function register(options) { } function copyFiles(commandName, { path, files }) { const cwd = process.cwd(); if (path && files && files.length > 0) { files.forEach((fileName) => { const sourcePath = path_1.isAbsolute(fileName) ? fileName : path_1.resolve(path, fileName); const destFileName = path_1.isAbsolute(fileName) ? path_1.basename(fileName) : fileName; const destPath = path_1.resolve(cwd, copiedFilesDir, commandName, destFileName); console.log(` ${yellow('creating')} ${destPath.replace(cwd, '.')}`); fs_extra_1.copySync(sourcePath, destPath); }); } } function run(helper, args) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return inquirer .prompt({ type: 'confirm', name: 'eject', message: 'Are you sure you want to eject (this is a permanent operation)?', default: false }) .then((answer) => { if (!answer.eject) { throw Error('Aborting eject'); } return allCommands_1.loadExternalCommands().then((commands) => tslib_1.__awaiter(this, void 0, void 0, function* () { let toEject = new Set(); commands.forEach((commandMap, group) => { toEject = [...commandMap.values()].reduce((toEject, command) => { if (isEjectableCommandWrapper(command)) { toEject.add(command); } return toEject; }, toEject); }); const npmPackages = { dependencies: {}, devDependencies: {} }; if (toEject.size) { const allHints = []; [...toEject].forEach((command) => { const commandKey = `${command.group}-${command.name}`; console.log(green('\nejecting ') + commandKey); const { npm = {}, copy = false, hints = false } = command.eject(helper); npmPackages.dependencies = Object.assign({}, npmPackages.dependencies, npm.dependencies); npmPackages.devDependencies = Object.assign({}, npmPackages.devDependencies, npm.devDependencies); copy && copyFiles(commandKey, copy); hints && allHints.push(...hints); configurationHelper_1.default.sandbox(command.group, command.name).set({ [ejectedKey]: true }); }); if (Object.keys(npmPackages.dependencies || {}).length) { console.log(underline('\nrunning npm install dependencies...')); yield npmInstall_1.installDependencies(npmPackages); } if (Object.keys(npmPackages.devDependencies || {}).length) { console.log(underline('\nrunning npm install devDependencies...')); yield npmInstall_1.installDevDependencies(npmPackages); } if (allHints.length > 0) { console.log(underline('\nhints')); allHints.forEach((hint) => { console.log(' ' + hint); }); } } else { console.log('There are no commands that can be ejected'); } })); }); }); } exports.default = { name: '', group: 'eject', description: 'disconnect your project from dojo cli commands', register, global: false, run }; //# sourceMappingURL=eject.js.map