UNPKG

@adpt/cli

Version:
121 lines 4.87 kB
"use strict"; /* * Copyright 2019 Unbounded Systems, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const utils_1 = require("@adpt/utils"); const command_1 = require("@oclif/command"); const listr_1 = tslib_1.__importDefault(require("@unboundedsystems/listr")); const lodash_1 = require("lodash"); const path_1 = tslib_1.__importDefault(require("path")); const semver_1 = require("semver"); const base_1 = require("../../base"); const proj_1 = require("../../proj"); const ssh_1 = require("../../proj/ssh"); const logString = (task) => (msg) => task.output = msg; class NewCommand extends base_1.AdaptBase { async init() { await super.init(); this.parse(); } async run() { const spec = this.args.starter; const dest = this.args.directory; const args = this.cmdArgv.length >= 3 ? this.cmdArgv.slice(2) : []; const f = this.flags(NewCommand); const adaptVerString = f.adaptVersion || this.config.version; if (!spec) { throw new utils_1.UserError(`Missing 1 required arg:\nstarter\nSee more help with --help`); } if (!dest || !lodash_1.isString(dest)) { throw new utils_1.UserError(`Directory argument is not a string`); } const adaptVersion = semver_1.parse(adaptVerString); if (!adaptVersion) { throw new utils_1.UserError(`Adapt version '${adaptVerString}' must be ` + `a valid semver string (Example: 1.0.1)`); } const sshHostKeyCheck = f.sshHostKeyCheck || "unset"; if (sshHostKeyCheck === "ask") this.interactive = true; const starter = proj_1.createStarter({ adaptVersion, args, destDir: path_1.default.resolve(dest), spec, }); try { await starter.init(); const tasks = new listr_1.default(this.outputSettings.listrOptions); tasks.add([ { title: "Downloading starter", enabled: () => !starter.isLocal, task: (_ctx, task) => starter.download(logString(task)), }, { title: "Creating new project", task: (_ctx, task) => starter.run(logString(task)), }, ]); await ssh_1.withGitSshCommand(sshHostKeyCheck, () => tasks.run()); } finally { await starter.cleanup(); } } } NewCommand.description = "Create a new Adapt project"; NewCommand.aliases = ["new"]; NewCommand.examples = [ `Create a new project into the directory './myproj' using the starter ` + `named 'blank' from the Adapt starter gallery:\n` + ` $ adapt <%- command.id %> blank myproj`, ]; NewCommand.flags = Object.assign({}, base_1.AdaptBase.flags, { adaptVersion: command_1.flags.string({ description: "[default: <adapt CLI version>] " + "Attempt to select a starter that is compatible with this " + "version of Adapt. Must be a valid semver." }), sshHostKeyCheck: command_1.flags.string({ description: "Sets the ssh StrictHostKeyChecking option when using the " + "ssh protocol for fetching a starter from a remote git " + "repository. Defaults to 'yes' if OpenSSH is detected, " + "'unset' otherwise.", options: ["yes", "no", "ask", "accept-new", "off", "unset"], default: () => ssh_1.gitUsesOpenSsh() ? "yes" : "unset", }) }); NewCommand.strict = false; NewCommand.args = [ { name: "starter", required: true, description: `Adapt starter to use. May be the name of a starter ` + `from the starter gallery, a URL, a local file path, or most ` + `formats supported by npm.` }, { name: "directory", default: ".", description: `Directory where the new project should be created. ` + `The directory will be created if it does not exist.` } ]; NewCommand.usage = [ "<%- command.id %> STARTER [DIRECTORY]", "<%- command.id %> STARTER DIRECTORY [STARTER_ARGS...]", ]; exports.default = NewCommand; //# sourceMappingURL=new.js.map