UNPKG

1.56 kBJavaScriptView Raw
1#!/usr/bin/env node
2
3const APP_DIR = 'app';
4const LEGACY_APP_DIR = 'marketplace_builder';
5const MODULES_DIR = 'modules';
6
7const program = require('commander'),
8 Gateway = require('./lib/proxy'),
9 fs = require('fs'),
10 shell = require('shelljs'),
11 logger = require('./lib/logger'),
12 fetchAuthData = require('./lib/settings').fetchSettings,
13 version = require('./package.json').version;
14
15program
16 .version(version)
17 .arguments('[environment]', 'name of the environment. Example: staging')
18 .arguments('<name>', 'base name of the migration. Example: cleanup_data')
19 .option('-c --config-file <config-file>', 'config file path', '.marketplace-kit')
20 .action((environment, name, params) => {
21 process.env.CONFIG_FILE_PATH = params.configFile;
22 const authData = fetchAuthData(environment, program);
23 const gateway = new Gateway(authData);
24 const formData = { name: name };
25 let app_directory;
26
27 if (fs.existsSync(APP_DIR)) {
28 app_directory = APP_DIR;
29 } else {
30 console.log(`Falling back to legacy app-directory name. Please consider renaming ${LEGACY_APP_DIR} to ${APP_DIR}`);
31 app_directory = LEGACY_APP_DIR;
32 }
33 const migrationsDir = `${app_directory}/migrations`;
34
35 gateway.generateMigration(formData).then(body => {
36 const path = `${migrationsDir}/${body['name']}.liquid`;
37 shell.mkdir('-p', migrationsDir);
38
39 fs.writeFileSync(path, body['body'], logger.Error);
40
41 logger.Success(`[Migration Generate] Successfully generated to: ${path}`);
42 });
43 });
44
45program.parse(process.argv);