UNPKG

zapier-platform-cli

Version:

The CLI for apps in the Zapier Developer Platform.

41 lines (34 loc) 2.61 kB
'use strict'; var utils = require('../utils'); var constants = require('../constants'); var convert = function convert(context, appid, location) { context.line('Welcome to the Zapier Platform! :-D'); context.line(); context.line(constants.ART); context.line(); context.line('Let\'s convert your app!'); context.line(); appid = Number(appid); if (!appid) { var message = 'You must provide an appid - get that from ' + constants.BASE_ENDPOINT + '/developer/builder/ (check the URL).'; return Promise.reject(new Error(message)); } var createApp = function createApp(tempAppDir) { var url = constants.BASE_ENDPOINT + '/api/developer/v1/apps/' + appid + '/dump'; utils.printStarting('Downloading app from Zapier'); return utils.callAPI(null, { url: url }).then(function (legacyApp) { utils.printDone(); return legacyApp; }).then(function (legacyApp) { return utils.convertApp(legacyApp, tempAppDir); }); }; return utils.initApp(context, location, createApp).then(function () { context.line('\nFinished! You might need to `npm install` then try `zapier test`!'); }); }; convert.argsSpec = [{ name: 'appid', required: true, help: 'Get the appid from ' + constants.BASE_ENDPOINT + '/developer/builder/ (check the URL)' }, { name: 'location', required: true, help: 'Relative to your current path - IE: `.` for current directory' }]; convert.help = 'Converts a Zapier Platform app to a CLI app, stubs only.'; convert.example = 'zapier convert appid path'; convert.docs = '\nCreates a new Zapier app from an existing app. **The new app contains code stubs only.** It is supposed to get you started - it isn\'t going to create a complete app!\n\nAfter running this, you\'ll have a new app in your directory, with stubs for your trigger and actions. If you re-run this command on an existing directory it will leave existing files alone and not clobber them.\n\n> Note: this doesn\'t register or push the app with Zapier - try `zapier register "Example"` and `zapier push` for that!\n\n**Arguments**\n\n' + utils.argsFragment(convert.argsSpec) + '\n' + utils.argOptsFragment(convert.argOptsSpec) + '\n\n' + '```' + 'bash\n$ zapier convert 1234 .\n# Let\'s convert your app!\n#\n# Downloading app from Zapier - done!\n# Writing triggers/trigger.js - done!\n# Writing package.json - done!\n# Writing index.js - done!\n# Copy ./index.js - done!\n# Copy ./package.json - done!\n# Copy ./triggers/trigger.js - done!\n#\n# Finished! You might need to `npm install` then try `zapier test`!\n' + '```' + '\n'; module.exports = convert;