UNPKG

snips-sam

Version:

The Snips Assistant Manager

60 lines (49 loc) 2.04 kB
import * as yargs from 'yargs'; import { cli } from '../cli'; import { SSHService } from '../session/ssh'; const rp = require('request-promise'); export const command = 'create'; export const desc = 'Create a new Snips assistant project'; const snipsfileSampleLocation = 'https://github.com/snipsco/samples/raw/master/snipsfiles/Snipsfile.weather'; const fallbackSnipsfile = ` assistant_url: https://github.com/snipsco/samples/raw/master/assistants/weather.zip skills: - url: https://github.com/snipsco/snips-skill-owm package_name: snipsowm params: default_location: "Paris, fr" api_key: aaadcb52c143f85d59cd1e8da5d0eb1f `; export const handler = async (argv: yargs.Argv) => { const ssh = new SSHService(); await ssh.connect().catch(e => cli.stream.error(e)); cli.stream.print('Creating new Snips assistant...'); await ssh.installSnipsPlatformDemo((output) => { cli.stream.printNoLN(output); }) .catch((e) => { cli.stream.error(`Couldn't install assistant: ` + e.message); ssh.disconnect(); process.exit(); }); cli.stream.loading(`Creating & sending a Snipsfile sample...`); let snipsfile; try { // TODO - Add back // snipsfile = await rp(snipsfileSampleLocation); snipsfile = fallbackSnipsfile; } catch (e) { snipsfile = fallbackSnipsfile; } await ssh.copySnipsFile(snipsfile) .catch((e) => { cli.stream.error(`Couldn't copy Snipsfile: ` + e.message); cli.stream.hint(`You can create it manually on your device from this url : https://github.com/snipsco/samples/raw/master/snipsfiles/Snipsfile.weather')`); ssh.disconnect(); process.exit(); }); cli.stream.success('Snips assistant created'); cli.stream.loading('Loading sample assistant...'); await ssh.runSnipsmanagerInstall((output) => { cli.stream.printNoLN(output); }); cli.stream.done(); await ssh.runSnipsManager((output) => { cli.stream.printNoLN(output); }); ssh.disconnect(); };