-
Notifications
You must be signed in to change notification settings - Fork 6
/
jussitb.js
executable file
·137 lines (112 loc) · 4.17 KB
/
jussitb.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env node
'use strict';
const pkg = require('./package.json');
const program = require('commander');
const Actions = require('./Actions');
const { readFileSync, readdirSync } = require('fs');
const updateNotifier = require('update-notifier');
const path = require('path');
const message = require('./utils/cli-colors');
const ACTIONS = new Actions();
const PROJECTDIR = process.cwd();
updateNotifier({pkg}).notify();
// init CLI
program
.version(pkg.version)
.description('Jussi CLI for VTEX utils');
program
.command('auth')
.description('Auth user to get VTEX-Auth-Cookies')
.option('--account <account>', 'Set the VTEX account name')
.option('--email <email>', 'Set the email account')
.action(ACTIONS.authAction);
program
.command('html')
.description('Auth user and Deploy HTML Templates files on VTEX CMS')
.option('--account <account>', 'Set the VTEX account name')
.option('--email <email>', 'Set the email account')
.action(ACTIONS.uploadHTMLAction);
program
.command('sub')
.description('Auth user and Deploy HTML Sub Templates files on VTEX CMS')
.option('--account <account>', 'Set the VTEX account name')
.option('--email <email>', 'Set the email account')
.action(ACTIONS.uploadSubHTMLAction);
program
.command('shelf')
.description('Auth user and Deploy HTML Shelves files on VTEX CMS')
.option('--account <account>', 'Set the VTEX account name')
.option('--email <email>', 'Set the email account')
.action(ACTIONS.uploadShelfAction);
program
.command('assets')
.description('Auth user and Deploy CSS and JS files on VTEX Portal')
.option('--account <account>', 'Set the VTEX account name')
.option('--email <email>', 'Set the email account')
.option('--site <site>', 'Set the site for upload on portal ("default" if not provide)')
.action(ACTIONS.uploadAssetsAction);
program
.command('defaultAssets')
.description('Auth user and Deploy CSS and JS files on VTEX CMS')
.option('--account <account>', 'Set the VTEX account name')
.option('--email <email>', 'Set the email account')
.action(ACTIONS.uploadDefaultAssetsAction);
program
.command('deploy')
.description('Auth user and deploy all files (CSS, JS, HTML Templates and HTML SubTemplates) on VTEX')
.option('--account <account>', 'Set the VTEX account name')
.option('--email <email>', 'Set the email account')
.option('--site <site>', 'Set the site for upload on portal ("default" if not provide)')
.option('--pathFiles <path>', 'Set the location to upload assets: "files" or "arquivos"')
.option('--force', 'Force update all files and templates')
.action(cmd => {
if( cmd && cmd.pathFiles && cmd.pathFiles === 'arquivos' ) {
ACTIONS.uploadAssetsAction(cmd)
.then(ACTIONS.uploadDefaultAssetsAction)
.then(ACTIONS.uploadSubHTMLAction)
.then(ACTIONS.uploadHTMLAction)
.then(ACTIONS.uploadShelfAction);
} else {
ACTIONS.uploadAssetsAction(cmd)
.then(ACTIONS.uploadSubHTMLAction)
.then(ACTIONS.uploadHTMLAction)
.then(ACTIONS.uploadShelfAction);
}
});
program
.command('createController')
.description('Create a new Nitro Controller in project structure')
.action(ACTIONS.createController);
program
.command('createModule')
.description('Create a new Nitro Module in project structure')
.action(ACTIONS.createModule);
program
.command('createPage')
.option('--account <account>', 'Set the VTEX project/account name')
.description('Create a new Page in project structure')
.action(ACTIONS.createPage);
program
.command('createProject')
.option('--account <account>', 'Set the VTEX project/account name')
.description('Create a new Project structure')
.action(ACTIONS.createProject);
program
.command('dirname')
.action(() => {
console.log('DIRNAME: ', __dirname);
console.log('FILENAME: ', __filename);
console.log('PROCESS: ', process.cwd());
const isRoot = readFileSync(path.resolve(PROJECTDIR, 'package.json'));
try {
readdirSync(path.resolve(PROJECTDIR, 'build'));
} catch(err) {
message('error', 'Plese run in root of the project after build all files');
throw new Error(err);
}
if(!isRoot) {
message('error', 'Plese run in root of the project after build all files');
throw new Error(err);
}
});
program.parse(process.argv);