UNPKG

jok

Version:

Bundle of utility functions for code generation related to nodejs and graphql

48 lines (47 loc) 1.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var fs = require("fs-extra"); var path = require("path"); var output = require("../../../integration/output"); var messages = require("../messages"); function copyDir(opts) { var templatePath = opts.templatePath; var templateName = opts.templateName; var projectPath = opts.projectPath; var projectName = opts.projectName; console.log(messages.copying(projectName, templateName)); var files = [ { from: './_gitignore', to: './.gitignore' }, { from: './_package.json', to: './package.json' }, ]; return new Promise(function (resolve, reject) { var stopCopySpinner = output.wait('Copying files'); fs.copy(templatePath, projectPath) .then(function () { return Promise.all(files.map(function (x) { var fromFullPath = path.resolve(projectPath, x.from); var toFullPath = path.resolve(projectPath, x.to); return fs .pathExists(fromFullPath) .then(function (exists) { return exists ? fs.move(fromFullPath, toFullPath) : Promise.resolve(null); }); })); }) .then(function () { stopCopySpinner(); output.success("Created files for \"" + output.cmd(projectName) + "\" jokio app"); resolve(fs); }) .catch(function (err) { console.error(err); stopCopySpinner(); output.error('Copy command failed, try again.'); reject(err); process.exit(1); }); }); } exports.default = copyDir;