UNPKG

novu

Version:

Novu CLI. Run Novu Studio and sync workflows with Novu Cloud

84 lines (78 loc) 3.77 kB
#!/usr/bin/env node "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.config = void 0; const commander_1 = require("commander"); const uuid_1 = require("uuid"); const commands_1 = require("./commands"); const sync_1 = require("./commands/sync"); const services_1 = require("./services"); const init_1 = require("./commands/init"); const constants_1 = require("./constants"); const analytics = new services_1.AnalyticService(); exports.config = new services_1.ConfigService(); if (process.env.NODE_ENV === 'development') { exports.config.clearStore(); } const anonymousIdLocalState = exports.config.getValue('anonymousId'); const anonymousId = anonymousIdLocalState || (0, uuid_1.v4)(); const program = new commander_1.Command(); program.name('novu').description(`A CLI tool to interact with Novu Cloud`); program .command('sync') .description(`Sync your state with Novu Cloud Specifying the Bridge URL and Secret Key: (e.g., npx novu@latest sync -b https://acme.org/api/novu -s NOVU_SECRET_KEY) Sync with Novu Cloud in Europe: (e.g., npx novu@latest sync -b https://acme.org/api/novu -s NOVU_SECRET_KEY -a https://eu.api.novu.co)`) .usage('-b <url> -s <secret-key> [-a <url>]') .option('-a, --api-url <url>', 'The Novu Cloud API URL', constants_1.NOVU_API_URL || 'https://api.novu.co') .requiredOption('-b, --bridge-url <url>', 'The Novu endpoint URL hosted in the Bridge application, by convention ends in /api/novu') .requiredOption('-s, --secret-key <secret-key>', 'The Novu Secret Key. Obtainable at https://dashboard.novu.co/api-keys', constants_1.NOVU_SECRET_KEY || '') .action(async (options) => { analytics.track({ identity: { anonymousId, }, data: {}, event: 'Sync Novu Endpoint State', }); await (0, sync_1.sync)(options.bridgeUrl, options.secretKey, options.apiUrl); }); program .command('dev') .description(`Start Novu Studio and a local tunnel Running the Bridge application on port 4000: (e.g., npx novu@latest dev -p 4000) Running the Bridge application on a different route: (e.g., npx novu@latest dev -r /v1/api/novu) Running with a custom tunnel: (e.g., npx novu@latest dev --tunnel https://my-tunnel.ngrok.app)`) .usage('[-p <port>] [-r <route>] [-o <origin>] [-d <dashboard-url>] [-sp <studio-port>] [-t <url>] [-H]') .option('-p, --port <port>', 'The local Bridge endpoint port', '4000') .option('-r, --route <route>', 'The Bridge endpoint route', '/api/novu') .option('-o, --origin <origin>', 'The Bridge endpoint origin') .option('-d, --dashboard-url <url>', 'The Novu Cloud Dashboard URL', 'https://dashboard.novu.co') .option('-sp, --studio-port <port>', 'The Local Studio server port', '2022') .option('-sh, --studio-host <host>', 'The Local Studio server host', 'localhost') .option('-t, --tunnel <url>', 'Self hosted tunnel. e.g. https://my-tunnel.ngrok.app') .option('-H, --headless', 'Run the Bridge in headless mode without opening the browser', false) .action(async (options) => { analytics.track({ identity: { anonymousId, }, data: {}, event: 'Open Dev Server', }); return await (0, commands_1.devCommand)(options, anonymousId); }); program .command('init') .description(`Create a new Novu application`) .option('-s, --secret-key <secret-key>', `The Novu development environment Secret Key. Note that your Novu app won't work outside of local mode without it.`) .option('-a, --api-url <url>', 'The Novu Cloud API URL', 'https://api.novu.co') .action(async (options) => { return await (0, init_1.init)(options, anonymousId); }); program.parse(process.argv);