UNPKG

zapier-platform-cli

Version:

The CLI for apps in the Zapier Developer Platform.

67 lines (59 loc) 1.76 kB
'use strict'; var path = require('path'); var tmp = require('tmp'); var _require = require('./display'), printStarting = _require.printStarting, printDone = _require.printDone, getInput = _require.getInput; var _require2 = require('./files'), isEmptyDir = _require2.isEmptyDir, copyDir = _require2.copyDir, removeDir = _require2.removeDir, ensureDir = _require2.ensureDir; var confirmNonEmptyDir = function confirmNonEmptyDir(location) { if (location === '.') { return isEmptyDir(location).then(function (isEmpty) { if (!isEmpty) { return getInput('Current directory not empty, continue anyway? (y/n) ').then(function (answer) { if (!answer.match(/^y/i)) { /*eslint no-process-exit: 0 */ process.exit(0); } }); } return Promise.resolve(); }); } return Promise.resolve(); }; var initApp = function initApp(context, location, createApp) { var appDir = path.resolve(location); var tempAppDir = tmp.tmpNameSync(); var copyOpts = { clobber: false, onCopy: function onCopy(file) { printStarting('Copy ' + file); printDone(); }, onSkip: function onSkip(file) { printStarting('File ' + file + ' already exists'); printDone(true, 'skipped'); } }; return confirmNonEmptyDir(location).then(function () { return removeDir(tempAppDir); }).then(function () { return ensureDir(tempAppDir); }).then(function () { return createApp(tempAppDir); }).then(function () { return ensureDir(appDir); }).then(function () { return copyDir(tempAppDir, appDir, copyOpts); }).then(function () { return removeDir(tempAppDir); }); }; module.exports = { initApp: initApp };