UNPKG

@google/dscc-gen

Version:

Create component & connector projects with sane defaults.

54 lines (53 loc) 2.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * @license * Copyright 2018 Google 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 * * https://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. */ const chalk_1 = require("chalk"); const path = require("path"); const files = require("../files"); const index_1 = require("../index"); const util = require("../util"); const green = chalk_1.default.rgb(15, 157, 88); const blue = chalk_1.default.rgb(66, 133, 244); exports.createFromTemplate = async (answers) => { const { devBucket, prodBucket, projectName, basePath } = answers; const templatePath = path.join(basePath, 'templates', answers.projectChoice); const projectPath = path.join(index_1.PWD, projectName); await files.createAndCopyFiles(projectPath, templatePath, projectName); const templates = [ { match: /{{DEV_BUCKET}}/g, replace: devBucket }, { match: /{{PROD_BUCKET}}/g, replace: prodBucket }, ]; await files.fixTemplates(projectPath, templates); await util.spinnify('Installing project dependencies...', async () => { if (answers.yarn) { await util.exec('yarn install', { cwd: projectPath }, false); } else { await util.exec('npm install', { cwd: projectPath }, false); } }); const runCmd = answers.yarn ? 'yarn' : 'npm run'; const cdDirection = blue.bold(`cd ${projectName}`); const runStart = green.bold(`${runCmd} start`); console.log(` Created new community viz: ${projectName} \n\ ${cdDirection} and ${runStart} to begin working on your viz!\n\ `); return 0; };