UNPKG

@bubblewrap/cli

Version:

CLI tool to Generate TWA projects from a Web Manifest

84 lines (83 loc) 3.22 kB
"use strict"; /* * Copyright 2019 Google Inc. All Rights Reserved. * * 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 }); exports.Cli = void 0; const minimist = require("minimist"); const update_1 = require("./cmds/update"); const help_1 = require("./cmds/help"); const build_1 = require("./cmds/build"); const init_1 = require("./cmds/init"); const validate_1 = require("./cmds/validate"); const install_1 = require("./cmds/install"); const config_1 = require("./config"); const semver_1 = require("semver"); const version_1 = require("./cmds/version"); const constants_1 = require("./constants"); const updateConfig_1 = require("./cmds/updateConfig"); const doctor_1 = require("./cmds/doctor"); class Cli { async run(args) { console.log(constants_1.BUBBLEWRAP_LOGO); if (semver_1.major(process.versions.node) < 10) { throw new Error(`Current Node.js version is ${process.versions.node}.` + ' Node.js version 10 or above is required to run bubblewrap.'); } const config = await config_1.loadOrCreateConfig(); const parsedArgs = minimist(args); let command; if (parsedArgs._.length === 0) { // Accept --version and --help alternatives for the help and version commands. if (parsedArgs.version) { command = 'version'; } else if (parsedArgs.help) { command = 'help'; } } else { command = parsedArgs._[0]; } // If no command is given, default to 'help'. if (!command) { command = 'help'; } switch (command) { case 'help': return await help_1.help(parsedArgs); case 'init': return await init_1.init(parsedArgs, config); case 'update': return await update_1.update(parsedArgs); case 'build': return await build_1.build(config, parsedArgs); case 'validate': return await validate_1.validate(parsedArgs); case 'version': { return await version_1.version(); } case 'install': return await install_1.install(parsedArgs, config); case 'updateConfig': return await updateConfig_1.updateConfig(parsedArgs); case 'doctor': return await doctor_1.doctor(); default: throw new Error(`"${command}" is not a valid command! Use 'bubblewrap help' for a list of commands`); } } } exports.Cli = Cli;