sn-typescript-util 1.3.3 → 1.3.5
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 +47 -0
- package/bin/snts.js +82 -79
- package/bun.lockb +0 -0
- package/package.json +9 -8
- package/scripts/options.ts +6 -0
- package/scripts/snts.ts +24 -3
package/README.md
CHANGED
|
@@ -11,6 +11,7 @@ A [TypeScript](https://www.typescriptlang.org/) CLI utility that works on-top of
|
|
|
11
11
|
1. [Installation and Setup](#installation-and-setup)
|
|
12
12
|
1. [Basic Workflow](#basic-workflow)
|
|
13
13
|
1. [Commands](#commands)
|
|
14
|
+
1. [Project Structure](#project-structure)
|
|
14
15
|
1. [License](#license)
|
|
15
16
|
|
|
16
17
|
## Benefits
|
|
@@ -137,6 +138,52 @@ snts -V
|
|
|
137
138
|
|
|
138
139
|
**[Back to top](#table-of-contents)**
|
|
139
140
|
|
|
141
|
+
## Project Structure
|
|
142
|
+
|
|
143
|
+
Inside of the application directory (after the build), the project structure will look something like this.
|
|
144
|
+
|
|
145
|
+
```text
|
|
146
|
+
/
|
|
147
|
+
├── background scripts/
|
|
148
|
+
├── scratch/
|
|
149
|
+
├── src/
|
|
150
|
+
│ ├── Server Development/
|
|
151
|
+
│ │ └── Script Includes/
|
|
152
|
+
│ │ └── DataService.script.js
|
|
153
|
+
│ │ └── Utils.script.js
|
|
154
|
+
│ └── Service Portal/
|
|
155
|
+
│ └── Widgets/
|
|
156
|
+
│ └── Dashboard/
|
|
157
|
+
│ └── Dashboard.client_script.js
|
|
158
|
+
│ └── Dashboard.css.scss
|
|
159
|
+
│ └── Dashboard.demo_data.json
|
|
160
|
+
│ └── Dashboard.link.js
|
|
161
|
+
│ └── Dashboard.option_schema.json
|
|
162
|
+
│ └── Dashboard.script.js
|
|
163
|
+
│ └── Dashboard.template.html
|
|
164
|
+
├── system/
|
|
165
|
+
├── ts/
|
|
166
|
+
│ ├── Server Development/
|
|
167
|
+
│ │ └── Script Includes/
|
|
168
|
+
│ │ └── DataService.script.ts
|
|
169
|
+
│ │ └── Utils.script.ts
|
|
170
|
+
│ ├── Service Portal/
|
|
171
|
+
│ │ └── Widgets/
|
|
172
|
+
│ │ └── Dashboard/
|
|
173
|
+
│ │ └── Dashboard.client_script.ts
|
|
174
|
+
│ │ └── Dashboard.link.ts
|
|
175
|
+
│ │ └── Dashboard.script.ts
|
|
176
|
+
│ └── Types/
|
|
177
|
+
│ └── Table.ts
|
|
178
|
+
│ └── User.ts
|
|
179
|
+
├── .eslintrc
|
|
180
|
+
└── app.config.json
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
This example project has two script includes, a widget, and a `Types` directory for interfaces & types.
|
|
184
|
+
|
|
185
|
+
**[Back to top](#table-of-contents)**
|
|
186
|
+
|
|
140
187
|
## License
|
|
141
188
|
|
|
142
189
|
[MIT License](LICENSE)
|
package/bin/snts.js
CHANGED
|
@@ -7,111 +7,114 @@ import { fileURLToPath } from 'url';
|
|
|
7
7
|
import { bold, red } from 'colorette';
|
|
8
8
|
import { intro, outro, spinner } from '@clack/prompts';
|
|
9
9
|
async function doBuild() {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
const s = startPrompts('Installing configs', 'Build started');
|
|
11
|
+
return await execFile(getFilePath('init.rb'), (stdout) => {
|
|
12
|
+
stopPrompt(s, 'Configs installed');
|
|
13
|
+
runSync();
|
|
14
|
+
return stdout;
|
|
15
|
+
});
|
|
16
16
|
}
|
|
17
17
|
async function doCompile() {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
const s = startPrompts('Processing', 'Compile started');
|
|
19
|
+
return await execFile(getFilePath('compile.rb'), (stdout) => {
|
|
20
|
+
stopPrompt(s, 'Completed');
|
|
21
|
+
return stdout;
|
|
22
|
+
});
|
|
23
23
|
}
|
|
24
24
|
function doOptions(program) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
25
|
+
program.parse(process.argv).opts();
|
|
26
|
+
const option = Object.keys(program.opts()).toString();
|
|
27
|
+
const optionKey = option;
|
|
28
|
+
const options = {
|
|
29
|
+
build: () => {
|
|
30
|
+
doBuild();
|
|
31
|
+
},
|
|
32
|
+
compile: () => {
|
|
33
|
+
doCompile();
|
|
34
|
+
},
|
|
35
|
+
sync: () => {
|
|
36
|
+
doSync();
|
|
37
|
+
},
|
|
38
|
+
default: () => {
|
|
39
|
+
program.help();
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
return handleOptions(program, options, optionKey);
|
|
42
43
|
}
|
|
43
44
|
async function doSync() {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
const s = startPrompts('Processing', 'Sync started');
|
|
46
|
+
return await execFile(getFilePath('sync.sh'), (stdout) => {
|
|
47
|
+
stopPrompt(s, 'Completed');
|
|
48
|
+
return stdout;
|
|
49
|
+
});
|
|
49
50
|
}
|
|
50
51
|
function getErrorMsg() {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
const url = `https://docs.servicenow.com/bundle/vancouver-application-development/page/build/applications/task/create-project.html`;
|
|
53
|
+
const msg = `No active application detected. Please create a project with the ServiceNow Extension for VS Code.\n\n${url}`;
|
|
54
|
+
return console.error(bold(red(msg)));
|
|
54
55
|
}
|
|
55
56
|
function getFilePath(file, dir = 'scripts') {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
const fileName = fileURLToPath(import.meta.url);
|
|
58
|
+
const dirName = path.dirname(fileName);
|
|
59
|
+
return `${path.join(dirName, `../${dir}`)}/${file}`;
|
|
59
60
|
}
|
|
60
61
|
async function getPackageInfo() {
|
|
61
|
-
|
|
62
|
+
return JSON.parse(readFileSync(getFilePath('package.json', '.')).toString());
|
|
62
63
|
}
|
|
63
64
|
function getWorkspace() {
|
|
64
|
-
|
|
65
|
+
return JSON.parse(readFileSync('./system/sn-workspace.json').toString());
|
|
66
|
+
}
|
|
67
|
+
function handleOptions(program, options, option) {
|
|
68
|
+
return (shouldShowHelp(program, option) ||
|
|
69
|
+
((hasApplication() && options[option]) || showHelp(program))());
|
|
65
70
|
}
|
|
66
71
|
async function hasApplication() {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
try {
|
|
73
|
+
const workspace = await getWorkspace();
|
|
74
|
+
const app = workspace.ACTIVE_APPLICATION;
|
|
75
|
+
return Object.entries(app).length === 0 ? getErrorMsg() : true;
|
|
76
|
+
}
|
|
77
|
+
catch (e) {
|
|
78
|
+
getErrorMsg();
|
|
79
|
+
return process.exit(1);
|
|
80
|
+
}
|
|
75
81
|
}
|
|
76
82
|
(async () => {
|
|
77
|
-
|
|
83
|
+
return init();
|
|
78
84
|
})();
|
|
79
85
|
async function init() {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
'-
|
|
86
|
-
'
|
|
87
|
-
|
|
88
|
-
program.option(
|
|
89
|
-
'-c, --compile',
|
|
90
|
-
'compile TypeScript files to JavaScript & move to src'
|
|
91
|
-
);
|
|
92
|
-
program.option(
|
|
93
|
-
'-s, --sync',
|
|
94
|
-
'sync new instance-based src files to the ts directory'
|
|
95
|
-
);
|
|
96
|
-
return doOptions(program);
|
|
86
|
+
const program = new Command();
|
|
87
|
+
const info = await getPackageInfo();
|
|
88
|
+
program.description(info.description);
|
|
89
|
+
program.version(info.version);
|
|
90
|
+
program.option('-b, --build', 'build project utility files & package dependencies');
|
|
91
|
+
program.option('-c, --compile', 'compile TypeScript files to JavaScript & move to src');
|
|
92
|
+
program.option('-s, --sync', 'sync new instance-based src files to the ts directory');
|
|
93
|
+
return doOptions(program);
|
|
97
94
|
}
|
|
98
95
|
function introPrompt(msg) {
|
|
99
|
-
|
|
96
|
+
return intro(msg);
|
|
100
97
|
}
|
|
101
98
|
async function runSync() {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
99
|
+
const s = startPrompts('Syncing', null);
|
|
100
|
+
return await execFile(getFilePath('sync.sh'), (stdout) => {
|
|
101
|
+
stopPrompt(s, 'Sync completed');
|
|
102
|
+
outro('Completed');
|
|
103
|
+
return stdout;
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
function shouldShowHelp(program, option) {
|
|
107
|
+
return !option && showHelp(program);
|
|
108
|
+
}
|
|
109
|
+
function showHelp(program) {
|
|
110
|
+
return program.help();
|
|
108
111
|
}
|
|
109
112
|
function startPrompts(start, intro) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
113
|
+
intro && introPrompt(intro);
|
|
114
|
+
const s = spinner();
|
|
115
|
+
s.start(start);
|
|
116
|
+
return s;
|
|
114
117
|
}
|
|
115
118
|
function stopPrompt(spinner, msg) {
|
|
116
|
-
|
|
119
|
+
return spinner.stop(msg);
|
|
117
120
|
}
|
package/bun.lockb
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sn-typescript-util",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.5",
|
|
4
4
|
"description": "A TypeScript utility for ServiceNow developers using VS Code",
|
|
5
5
|
"bin": {
|
|
6
6
|
"snts": "bin/snts.js"
|
|
@@ -25,17 +25,18 @@
|
|
|
25
25
|
"type": "module",
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@clack/prompts": "^0.7.0",
|
|
28
|
-
"@types/servicenow": "^10.0.
|
|
28
|
+
"@types/servicenow": "^10.0.4",
|
|
29
29
|
"colorette": "^2.0.20",
|
|
30
30
|
"commander": "^11.1.0",
|
|
31
31
|
"npm-add-script": "^1.1.0",
|
|
32
|
-
"typescript": "^5.
|
|
32
|
+
"typescript": "^5.3.3"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@
|
|
36
|
-
"@typescript-eslint/
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
35
|
+
"@types/commander": "^2.12.2",
|
|
36
|
+
"@typescript-eslint/eslint-plugin": "^6.15.0",
|
|
37
|
+
"@typescript-eslint/parser": "^6.15.0",
|
|
38
|
+
"bun-types": "^1.0.19",
|
|
39
|
+
"eslint": "^8.56.0",
|
|
40
|
+
"prettier": "^3.1.1"
|
|
40
41
|
}
|
|
41
42
|
}
|
package/scripts/snts.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { readFileSync } from 'fs';
|
|
|
7
7
|
import { fileURLToPath } from 'url';
|
|
8
8
|
import { bold, red } from 'colorette';
|
|
9
9
|
import { intro, outro, spinner } from '@clack/prompts';
|
|
10
|
+
import { Options } from './options.js';
|
|
10
11
|
import { Workspace } from './workspace.js';
|
|
11
12
|
|
|
12
13
|
async function doBuild() {
|
|
@@ -26,10 +27,11 @@ async function doCompile() {
|
|
|
26
27
|
});
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
function doOptions(program:
|
|
30
|
+
function doOptions(program: Command) {
|
|
30
31
|
program.parse(process.argv).opts();
|
|
31
32
|
const option: string = Object.keys(program.opts()).toString();
|
|
32
|
-
const
|
|
33
|
+
const optionKey = option as keyof Options;
|
|
34
|
+
const options: Options = {
|
|
33
35
|
build: () => {
|
|
34
36
|
doBuild();
|
|
35
37
|
},
|
|
@@ -43,7 +45,7 @@ function doOptions(program: any) {
|
|
|
43
45
|
program.help();
|
|
44
46
|
}
|
|
45
47
|
};
|
|
46
|
-
return (
|
|
48
|
+
return handleOptions(program, options, optionKey);
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
async function doSync() {
|
|
@@ -74,6 +76,17 @@ function getWorkspace() {
|
|
|
74
76
|
return JSON.parse(readFileSync('./system/sn-workspace.json').toString());
|
|
75
77
|
}
|
|
76
78
|
|
|
79
|
+
function handleOptions(
|
|
80
|
+
program: Command,
|
|
81
|
+
options: Options,
|
|
82
|
+
option: keyof Options
|
|
83
|
+
) {
|
|
84
|
+
return (
|
|
85
|
+
shouldShowHelp(program, option) ||
|
|
86
|
+
((hasApplication() && options[option]) || showHelp(program))()
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
77
90
|
async function hasApplication() {
|
|
78
91
|
try {
|
|
79
92
|
const workspace: Workspace = await getWorkspace();
|
|
@@ -122,6 +135,14 @@ async function runSync() {
|
|
|
122
135
|
});
|
|
123
136
|
}
|
|
124
137
|
|
|
138
|
+
function shouldShowHelp(program: Command, option: string) {
|
|
139
|
+
return !option && showHelp(program);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function showHelp(program: Command) {
|
|
143
|
+
return program.help();
|
|
144
|
+
}
|
|
145
|
+
|
|
125
146
|
function startPrompts(start: string, intro: string | null) {
|
|
126
147
|
intro && introPrompt(intro);
|
|
127
148
|
const s = spinner();
|