sn-typescript-util 1.0.19 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/bin/snts.ts +53 -64
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@ Using TypeScript, the CLI provides an enhanced developer workflow.
|
|
|
29
29
|
- [Node.js](https://nodejs.org/)
|
|
30
30
|
- [Visual Studio Code](https://code.visualstudio.com/)
|
|
31
31
|
- [ServiceNow Extension for VS Code](https://marketplace.visualstudio.com/items?itemName=ServiceNow.now-vscode)
|
|
32
|
-
- A [project created](https://docs.servicenow.com/bundle/
|
|
32
|
+
- A [project created](https://docs.servicenow.com/bundle/utah-application-development/page/build/applications/task/create-project.html) and [application imported](https://docs.servicenow.com/bundle/utah-application-development/page/build/applications/task/vscode-import-application.html) in VS Code
|
|
33
33
|
|
|
34
34
|
**[Back to top](#table-of-contents)**
|
|
35
35
|
|
package/bin/snts.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const childProcess = require('child_process');
|
|
4
|
-
const cliProgress = require('cli-progress');
|
|
5
4
|
const fs = require('fs');
|
|
6
5
|
const path = require('path');
|
|
7
6
|
const util = require('util');
|
|
@@ -9,13 +8,35 @@ const exec = util.promisify(childProcess.exec);
|
|
|
9
8
|
const { description, version } = require('./../package.json');
|
|
10
9
|
const { program } = require('commander');
|
|
11
10
|
const { bold, cyan, red } = require('colorette');
|
|
11
|
+
const { cancel, intro, outro, spinner } = require('@clack/prompts');
|
|
12
12
|
|
|
13
|
-
(
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
async function doBuild() {
|
|
14
|
+
const s = startPrompts('Installing configs', 'Build started');
|
|
15
|
+
return await exec(getFilePath('init.rb'), (stdout) => {
|
|
16
|
+
stopPrompt(s, 'Configs installed');
|
|
17
|
+
runSync();
|
|
18
|
+
return stdout;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function doCompile() {
|
|
23
|
+
const s = startPrompts('Processing', 'Compile started');
|
|
24
|
+
return await exec(getFilePath('compile.rb'), (stdout) => {
|
|
25
|
+
stopPrompt(s, 'Completed');
|
|
26
|
+
return stdout;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function doSync() {
|
|
31
|
+
const s = startPrompts('Processing', 'Sync started');
|
|
32
|
+
return await exec(getFilePath('sync.sh'), (stdout) => {
|
|
33
|
+
stopPrompt(s, 'Completed');
|
|
34
|
+
return stdout;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
16
37
|
|
|
17
38
|
function getBuildName() {
|
|
18
|
-
const defaultBuild = '
|
|
39
|
+
const defaultBuild = 'utah';
|
|
19
40
|
try {
|
|
20
41
|
const workspace = JSON.parse(getWorkspaceConfig());
|
|
21
42
|
const app = workspace.ACTIVE_APPLICATION;
|
|
@@ -34,17 +55,21 @@ function getErrorMsg() {
|
|
|
34
55
|
return console.error(bold(red(msg)));
|
|
35
56
|
}
|
|
36
57
|
|
|
58
|
+
function getFilePath(file) {
|
|
59
|
+
return `${path.join(__dirname, '../scripts')}/${file}`;
|
|
60
|
+
}
|
|
61
|
+
|
|
37
62
|
function getOption(opts) {
|
|
38
63
|
const option = Object.keys(opts).toString();
|
|
39
64
|
const options = {
|
|
40
65
|
build: () => {
|
|
41
|
-
|
|
66
|
+
doBuild();
|
|
42
67
|
},
|
|
43
68
|
compile: () => {
|
|
44
|
-
|
|
69
|
+
doCompile();
|
|
45
70
|
},
|
|
46
71
|
sync: () => {
|
|
47
|
-
|
|
72
|
+
doSync();
|
|
48
73
|
},
|
|
49
74
|
default: () => {
|
|
50
75
|
program.help();
|
|
@@ -53,18 +78,6 @@ function getOption(opts) {
|
|
|
53
78
|
return (options[option] || options['default'])();
|
|
54
79
|
}
|
|
55
80
|
|
|
56
|
-
function getProgressBar() {
|
|
57
|
-
return new cliProgress.SingleBar({
|
|
58
|
-
format:
|
|
59
|
-
'CLI Progress |' +
|
|
60
|
-
cyan('{bar}') +
|
|
61
|
-
'| {percentage}% || {value}/{total} Chunks',
|
|
62
|
-
barCompleteChar: '\u2588',
|
|
63
|
-
barIncompleteChar: '\u2591',
|
|
64
|
-
hideCursor: true
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
81
|
function getWorkspaceConfig() {
|
|
69
82
|
return fs.readFileSync('./system/sn-workspace.json');
|
|
70
83
|
}
|
|
@@ -75,13 +88,13 @@ function hasApplication() {
|
|
|
75
88
|
return Object.entries(app).length === 0 ? getErrorMsg() : true;
|
|
76
89
|
} catch (e) {
|
|
77
90
|
getErrorMsg();
|
|
78
|
-
return process.exit(
|
|
91
|
+
return process.exit(1);
|
|
79
92
|
}
|
|
80
93
|
}
|
|
81
94
|
|
|
82
|
-
|
|
83
|
-
return
|
|
84
|
-
}
|
|
95
|
+
(() => {
|
|
96
|
+
return init();
|
|
97
|
+
})();
|
|
85
98
|
|
|
86
99
|
function init() {
|
|
87
100
|
program.description(description);
|
|
@@ -102,57 +115,33 @@ function init() {
|
|
|
102
115
|
return hasApplication() && getOption(program.opts());
|
|
103
116
|
}
|
|
104
117
|
|
|
105
|
-
function
|
|
106
|
-
|
|
107
|
-
bar.stop();
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function progressStart(bar) {
|
|
111
|
-
bar.start(100, 0);
|
|
112
|
-
bar.update(1);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
async function runConfigs(bar) {
|
|
116
|
-
return await exec(getFilePath('init.rb'), (stdout) => {
|
|
117
|
-
bar.update(10);
|
|
118
|
-
runSync(bar);
|
|
119
|
-
return stdout;
|
|
120
|
-
});
|
|
118
|
+
function introPrompt(msg) {
|
|
119
|
+
return intro(msg);
|
|
121
120
|
}
|
|
122
121
|
|
|
123
|
-
async function runInstall(
|
|
124
|
-
|
|
122
|
+
async function runInstall() {
|
|
123
|
+
const s = startPrompts('Installing packages', null);
|
|
125
124
|
return await exec(getFilePath('install.sh'), (stdout) => {
|
|
126
|
-
|
|
125
|
+
stopPrompt(s, 'Packages installed');
|
|
126
|
+
outro('Completed');
|
|
127
127
|
return stdout;
|
|
128
128
|
});
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
function
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
return childProcess.exec(getFilePath(file), (stdout) => {
|
|
135
|
-
progressComplete(bar);
|
|
136
|
-
return stdout;
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function runScript(file) {
|
|
141
|
-
return childProcess.exec(getFilePath(file), (stdout) => {
|
|
131
|
+
async function runSync() {
|
|
132
|
+
return await exec(getFilePath('sync.sh'), (stdout) => {
|
|
133
|
+
runInstall();
|
|
142
134
|
return stdout;
|
|
143
135
|
});
|
|
144
136
|
}
|
|
145
137
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
});
|
|
138
|
+
function startPrompts(start, intro) {
|
|
139
|
+
intro && introPrompt(intro);
|
|
140
|
+
const s = spinner();
|
|
141
|
+
s.start(start);
|
|
142
|
+
return s;
|
|
152
143
|
}
|
|
153
144
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
progressStart(bar);
|
|
157
|
-
return await Promise.all([runConfigs(bar)]);
|
|
145
|
+
function stopPrompt(spinner, msg) {
|
|
146
|
+
return spinner.stop(msg);
|
|
158
147
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sn-typescript-util",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "A TypeScript utility for ServiceNow developers using VS Code",
|
|
5
5
|
"bin": {
|
|
6
6
|
"snts": "bin/snts.ts"
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"url": "https://github.com/stevengregory/sn-typescript-util.git"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
+
"@clack/prompts": "^0.6.3",
|
|
20
21
|
"@types/node": "^18.15.11",
|
|
21
22
|
"@types/servicenow": "^10.0.1",
|
|
22
|
-
"cli-progress": "^3.12.0",
|
|
23
23
|
"colorette": "^2.0.19",
|
|
24
24
|
"commander": "^10.0.0",
|
|
25
25
|
"nodemon": "^2.0.22",
|