UNPKG

@dojo/cli

Version:

Dojo CLI utility

54 lines 2.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const fs_1 = require("fs"); const path_1 = require("path"); const detectIndent = require("detect-indent"); const allCommands_1 = require("../allCommands"); const chalk_1 = require("chalk"); const pkgDir = require('pkg-dir'); const noPackageWarning = chalk_1.default.yellow(`Warning: A root `) + chalk_1.default.whiteBright.bold('package.json ') + chalk_1.default.yellow(`was not found; this directory will be used for the root for your Dojo project. It is strongly recommended you create one by running `) + chalk_1.default.whiteBright.bold('npm init'); function run(helper, args = {}) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const cwd = process.cwd(); let rootDir = pkgDir.sync(cwd); if (!rootDir) { console.warn(noPackageWarning); rootDir = cwd; } const dojoRcName = args.dojorc || '.dojorc'; const dojoRcPath = path_1.join(rootDir, dojoRcName); const file = fs_1.existsSync(dojoRcPath) && fs_1.readFileSync(dojoRcPath, 'utf8'); let json = {}; let indent = '\t'; if (file) { indent = detectIndent(file).indent || indent; json = JSON.parse(file); } const groupMap = yield allCommands_1.loadExternalCommands(''); const values = []; for (let [, commandMap] of groupMap.entries()) { for (let [, value] of commandMap.entries()) { const name = `${value.group}-${value.name}`; if (values.indexOf(name) === -1 && json[name] === undefined) { json[name] = {}; values.push(name); } } } fs_1.writeFileSync(dojoRcPath, JSON.stringify(json, null, indent)); console.log(chalk_1.default.white(`Successfully wrote ${dojoRcName} to ${dojoRcPath}`)); }); } exports.default = { name: '', group: 'init', description: 'create a .dojorc file', run, global: false, register: () => { } }; //# sourceMappingURL=init.js.map