sn-typescript-util 1.0.19 → 1.1.1
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.js +123 -0
- package/package.json +9 -10
- package/{bin → src}/snts.ts +53 -64
- package/tsconfig.json +11 -0
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.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const childProcess = require('child_process');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const util = require('util');
|
|
6
|
+
const exec = util.promisify(childProcess.exec);
|
|
7
|
+
const { description, version } = require('./../package.json');
|
|
8
|
+
const { program } = require('commander');
|
|
9
|
+
const { bold, cyan, red } = require('colorette');
|
|
10
|
+
const { cancel, intro, outro, spinner } = require('@clack/prompts');
|
|
11
|
+
async function doBuild() {
|
|
12
|
+
const s = startPrompts('Installing configs', 'Build started');
|
|
13
|
+
return await exec(getFilePath('init.rb'), (stdout) => {
|
|
14
|
+
stopPrompt(s, 'Configs installed');
|
|
15
|
+
runSync();
|
|
16
|
+
return stdout;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
async function doCompile() {
|
|
20
|
+
const s = startPrompts('Processing', 'Compile started');
|
|
21
|
+
return await exec(getFilePath('compile.rb'), (stdout) => {
|
|
22
|
+
stopPrompt(s, 'Completed');
|
|
23
|
+
return stdout;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
async function doSync() {
|
|
27
|
+
const s = startPrompts('Processing', 'Sync started');
|
|
28
|
+
return await exec(getFilePath('sync.sh'), (stdout) => {
|
|
29
|
+
stopPrompt(s, 'Completed');
|
|
30
|
+
return stdout;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function getBuildName() {
|
|
34
|
+
const defaultBuild = 'utah';
|
|
35
|
+
try {
|
|
36
|
+
const workspace = JSON.parse(getWorkspaceConfig());
|
|
37
|
+
const app = workspace.ACTIVE_APPLICATION;
|
|
38
|
+
const build = workspace.ALL_APPLICATIONS[app].BUILD_NAME;
|
|
39
|
+
return Object.entries(build).length !== 0
|
|
40
|
+
? build.toLowerCase()
|
|
41
|
+
: defaultBuild;
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
return defaultBuild;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function getErrorMsg() {
|
|
48
|
+
var url = `https://docs.servicenow.com/bundle/${getBuildName()}-application-development/page/build/applications/task/create-project.html`;
|
|
49
|
+
var msg = `No active application detected. Please create a project with the ServiceNow Extension for VS Code.\n\n${url}`;
|
|
50
|
+
return console.error(bold(red(msg)));
|
|
51
|
+
}
|
|
52
|
+
function getFilePath(file) {
|
|
53
|
+
return `${path.join(__dirname, '../scripts')}/${file}`;
|
|
54
|
+
}
|
|
55
|
+
function getOption(opts) {
|
|
56
|
+
const option = Object.keys(opts).toString();
|
|
57
|
+
const options = {
|
|
58
|
+
build: () => {
|
|
59
|
+
doBuild();
|
|
60
|
+
},
|
|
61
|
+
compile: () => {
|
|
62
|
+
doCompile();
|
|
63
|
+
},
|
|
64
|
+
sync: () => {
|
|
65
|
+
doSync();
|
|
66
|
+
},
|
|
67
|
+
default: () => {
|
|
68
|
+
program.help();
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
return (options[option] || options['default'])();
|
|
72
|
+
}
|
|
73
|
+
function getWorkspaceConfig() {
|
|
74
|
+
return fs.readFileSync('./system/sn-workspace.json');
|
|
75
|
+
}
|
|
76
|
+
function hasApplication() {
|
|
77
|
+
try {
|
|
78
|
+
const app = JSON.parse(getWorkspaceConfig()).ACTIVE_APPLICATION;
|
|
79
|
+
return Object.entries(app).length === 0 ? getErrorMsg() : true;
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
getErrorMsg();
|
|
83
|
+
return process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
(() => {
|
|
87
|
+
return init();
|
|
88
|
+
})();
|
|
89
|
+
function init() {
|
|
90
|
+
program.description(description);
|
|
91
|
+
program.version(version);
|
|
92
|
+
program.option('-b, --build', 'build project utility files & package dependencies');
|
|
93
|
+
program.option('-c, --compile', 'compile TypeScript files to JavaScript & move to src');
|
|
94
|
+
program.option('-s, --sync', 'sync new instance-based src files to the ts directory');
|
|
95
|
+
program.parse(process.argv).opts();
|
|
96
|
+
return hasApplication() && getOption(program.opts());
|
|
97
|
+
}
|
|
98
|
+
function introPrompt(msg) {
|
|
99
|
+
return intro(msg);
|
|
100
|
+
}
|
|
101
|
+
async function runInstall() {
|
|
102
|
+
const s = startPrompts('Installing packages', null);
|
|
103
|
+
return await exec(getFilePath('install.sh'), (stdout) => {
|
|
104
|
+
stopPrompt(s, 'Packages installed');
|
|
105
|
+
outro('Completed');
|
|
106
|
+
return stdout;
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
async function runSync() {
|
|
110
|
+
return await exec(getFilePath('sync.sh'), (stdout) => {
|
|
111
|
+
runInstall();
|
|
112
|
+
return stdout;
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
function startPrompts(start, intro) {
|
|
116
|
+
intro && introPrompt(intro);
|
|
117
|
+
const s = spinner();
|
|
118
|
+
s.start(start);
|
|
119
|
+
return s;
|
|
120
|
+
}
|
|
121
|
+
function stopPrompt(spinner, msg) {
|
|
122
|
+
return spinner.stop(msg);
|
|
123
|
+
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sn-typescript-util",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "A TypeScript utility for ServiceNow developers using VS Code",
|
|
5
5
|
"bin": {
|
|
6
|
-
"snts": "bin/snts.
|
|
6
|
+
"snts": "bin/snts.js"
|
|
7
7
|
},
|
|
8
8
|
"keywords": [
|
|
9
9
|
"ServiceNow",
|
|
@@ -17,15 +17,14 @@
|
|
|
17
17
|
"url": "https://github.com/stevengregory/sn-typescript-util.git"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@
|
|
20
|
+
"@clack/prompts": "^0.6.3",
|
|
21
|
+
"@types/node": "^20.4.2",
|
|
21
22
|
"@types/servicenow": "^10.0.1",
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"nodemon": "^2.0.22",
|
|
23
|
+
"colorette": "^2.0.20",
|
|
24
|
+
"commander": "^11.0.0",
|
|
25
|
+
"nodemon": "^3.0.1",
|
|
26
26
|
"npm-add-script": "^1.1.0",
|
|
27
|
-
"prettier": "^
|
|
28
|
-
"
|
|
29
|
-
"typescript": "^5.0.4"
|
|
27
|
+
"prettier": "^3.0.0",
|
|
28
|
+
"typescript": "^5.1.6"
|
|
30
29
|
}
|
|
31
30
|
}
|
package/{bin → src}/snts.ts
RENAMED
|
@@ -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
|
}
|