-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
executable file
·56 lines (42 loc) · 1.83 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env node --no-warnings
require('dotenv').config({ path: __dirname + '/.env' })
// require('dotenv').config();
const { DEFAULT_TEMPLATE_DIR, ENV_VARIABLES, INIT_TYPE } = require('./config/defaults')
let templatesDir = process.env[DEFAULT_TEMPLATE_DIR]; // this is where skaffy templates are at
const { initializeApp, initializeTemplateDirectory } = require('./helper/initializer')
const actions = require('./actions');
const logger = require('./helper/logger')
const fileHandler = require('./helper/fileHandler')
const envFullPath = __dirname + '/.env';
const yargs = require("yargs");
const package = require(__dirname + '/package.json');
const default_template_path = fileHandler.defaultSavePath();
const appName = package.name; // 'skaffy';
const appVersion = package.version;
const workingDir = __dirname;
const [, , ...args] = process.argv
let options = initializeApp(appName, appVersion);
if (!templatesDir) { // [ Initialize template directory ]
initializeTemplateDirectory(default_template_path, envFullPath, ENV_VARIABLES, [], appName, function (newPath) {
options.initialize = INIT_TYPE.NEW
templatesDir = newPath
executeCommand();
});
} else {
executeCommand();
}
function executeCommand() {
let config = {
templatesDir: templatesDir,
workingDir: __dirname
};
if (options.use) actions.useTemplate(options, args, config);
else if (options.create) actions.createTemplate(options, args);
else if (options.edit) actions.editTemplate(options, args);
else if (options.delete) actions.deleteTemplate(options, args);
else if (options.list) actions.listTemplates(options, args, config);
else if (options.show) actions.showTemplate(options, args, config);
else if (options.fork) actions.forkTemplate(options, args);
else if (options.initialize) actions.initializeTemplates(options, args, config);
else yargs.showHelp();
}