1 | #!/usr/bin/env node
|
2 |
|
3 | const program = require('commander'),
|
4 | Gateway = require('./lib/proxy'),
|
5 | fs = require('fs'),
|
6 | shell = require('shelljs'),
|
7 | logger = require('./lib/logger'),
|
8 | fetchAuthData = require('./lib/settings').fetchSettings,
|
9 | version = require('./package.json').version;
|
10 |
|
11 | program
|
12 | .version(version)
|
13 | .arguments('[environment]', 'name of the environment. Example: staging')
|
14 | .arguments('<name>', 'base name of the migration. Example: cleanup_data')
|
15 | .option('-c --config-file <config-file>', 'config file path', '.marketplace-kit')
|
16 | .action((environment, name, params) => {
|
17 | process.env.CONFIG_FILE_PATH = params.configFile;
|
18 | const authData = fetchAuthData(environment, program);
|
19 | const gateway = new Gateway(authData);
|
20 | const formData = { name: name };
|
21 | const migrationsDir = 'marketplace_builder/migrations';
|
22 |
|
23 | gateway.generateMigration(formData).then(body => {
|
24 | const path = `${migrationsDir}/${body['name']}.liquid`;
|
25 | shell.mkdir('-p', migrationsDir);
|
26 |
|
27 | fs.writeFileSync(path, body['body'], logger.Error);
|
28 |
|
29 | logger.Success(`[Migration Generate] Successfully generated to: ${path}`);
|
30 | });
|
31 | });
|
32 |
|
33 | program.parse(process.argv);
|