sn-typescript-util 1.3.4 → 1.3.6
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 +4 -4
- package/bin/snts.js +89 -75
- package/bun.lockb +0 -0
- package/package.json +5 -4
- package/scripts/options.ts +2 -2
- package/scripts/snts.ts +18 -9
package/README.md
CHANGED
|
@@ -133,7 +133,7 @@ snts --version
|
|
|
133
133
|
|
|
134
134
|
# or
|
|
135
135
|
|
|
136
|
-
snts -
|
|
136
|
+
snts -v
|
|
137
137
|
```
|
|
138
138
|
|
|
139
139
|
**[Back to top](#table-of-contents)**
|
|
@@ -170,9 +170,9 @@ Inside of the application directory (after the build), the project structure wil
|
|
|
170
170
|
│ ├── Service Portal/
|
|
171
171
|
│ │ └── Widgets/
|
|
172
172
|
│ │ └── Dashboard/
|
|
173
|
-
│ │
|
|
174
|
-
│ │
|
|
175
|
-
│ │
|
|
173
|
+
│ │ └── Dashboard.client_script.ts
|
|
174
|
+
│ │ └── Dashboard.link.ts
|
|
175
|
+
│ │ └── Dashboard.script.ts
|
|
176
176
|
│ └── Types/
|
|
177
177
|
│ └── Table.ts
|
|
178
178
|
│ └── User.ts
|
package/bin/snts.js
CHANGED
|
@@ -7,113 +7,127 @@ 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 handleError() {
|
|
68
|
+
getErrorMsg();
|
|
69
|
+
process.exit(1);
|
|
65
70
|
}
|
|
66
71
|
function handleOptions(program, options, option) {
|
|
67
|
-
|
|
68
|
-
|
|
72
|
+
return (
|
|
73
|
+
shouldShowHelp(program, option) ||
|
|
74
|
+
((hasApplication() && options[option]) || showHelp(program))()
|
|
75
|
+
);
|
|
69
76
|
}
|
|
70
77
|
async function hasApplication() {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return process.exit(1);
|
|
79
|
-
}
|
|
78
|
+
try {
|
|
79
|
+
const workspace = await getWorkspace();
|
|
80
|
+
const app = workspace.ACTIVE_APPLICATION;
|
|
81
|
+
return Object.entries(app).length === 0 ? getErrorMsg() : true;
|
|
82
|
+
} catch {
|
|
83
|
+
return handleError();
|
|
84
|
+
}
|
|
80
85
|
}
|
|
81
86
|
(async () => {
|
|
82
|
-
|
|
87
|
+
return init();
|
|
83
88
|
})();
|
|
84
89
|
async function init() {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
const program = new Command();
|
|
91
|
+
const info = await getPackageInfo();
|
|
92
|
+
program.description(info.description);
|
|
93
|
+
program.version(info.version, '-v, --version', 'output the current version');
|
|
94
|
+
program.option(
|
|
95
|
+
'-b, --build',
|
|
96
|
+
'build project utility files & package dependencies'
|
|
97
|
+
);
|
|
98
|
+
program.option(
|
|
99
|
+
'-c, --compile',
|
|
100
|
+
'compile TypeScript files to JavaScript & move to src'
|
|
101
|
+
);
|
|
102
|
+
program.option(
|
|
103
|
+
'-s, --sync',
|
|
104
|
+
'sync new instance-based src files to the ts directory'
|
|
105
|
+
);
|
|
106
|
+
return doOptions(program);
|
|
93
107
|
}
|
|
94
108
|
function introPrompt(msg) {
|
|
95
|
-
|
|
109
|
+
return intro(msg);
|
|
96
110
|
}
|
|
97
111
|
async function runSync() {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
112
|
+
const s = startPrompts('Syncing', null);
|
|
113
|
+
return await execFile(getFilePath('sync.sh'), (stdout) => {
|
|
114
|
+
stopPrompt(s, 'Sync completed');
|
|
115
|
+
outro('Completed');
|
|
116
|
+
return stdout;
|
|
117
|
+
});
|
|
104
118
|
}
|
|
105
119
|
function shouldShowHelp(program, option) {
|
|
106
|
-
|
|
120
|
+
return !option && showHelp(program);
|
|
107
121
|
}
|
|
108
122
|
function showHelp(program) {
|
|
109
|
-
|
|
123
|
+
return program.help();
|
|
110
124
|
}
|
|
111
125
|
function startPrompts(start, intro) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
126
|
+
intro && introPrompt(intro);
|
|
127
|
+
const s = spinner();
|
|
128
|
+
s.start(start);
|
|
129
|
+
return s;
|
|
116
130
|
}
|
|
117
131
|
function stopPrompt(spinner, msg) {
|
|
118
|
-
|
|
132
|
+
return spinner.stop(msg);
|
|
119
133
|
}
|
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.6",
|
|
4
4
|
"description": "A TypeScript utility for ServiceNow developers using VS Code",
|
|
5
5
|
"bin": {
|
|
6
6
|
"snts": "bin/snts.js"
|
|
@@ -32,9 +32,10 @@
|
|
|
32
32
|
"typescript": "^5.3.3"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@
|
|
36
|
-
"@typescript-eslint/
|
|
37
|
-
"
|
|
35
|
+
"@types/commander": "^2.12.2",
|
|
36
|
+
"@typescript-eslint/eslint-plugin": "^6.16.0",
|
|
37
|
+
"@typescript-eslint/parser": "^6.16.0",
|
|
38
|
+
"bun-types": "^1.0.20",
|
|
38
39
|
"eslint": "^8.56.0",
|
|
39
40
|
"prettier": "^3.1.1"
|
|
40
41
|
}
|
package/scripts/options.ts
CHANGED
package/scripts/snts.ts
CHANGED
|
@@ -27,9 +27,10 @@ async function doCompile() {
|
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
function doOptions(program:
|
|
30
|
+
function doOptions(program: Command) {
|
|
31
31
|
program.parse(process.argv).opts();
|
|
32
32
|
const option: string = Object.keys(program.opts()).toString();
|
|
33
|
+
const optionKey = option as keyof Options;
|
|
33
34
|
const options: Options = {
|
|
34
35
|
build: () => {
|
|
35
36
|
doBuild();
|
|
@@ -44,7 +45,7 @@ function doOptions(program: any) {
|
|
|
44
45
|
program.help();
|
|
45
46
|
}
|
|
46
47
|
};
|
|
47
|
-
return handleOptions(program, options,
|
|
48
|
+
return handleOptions(program, options, optionKey);
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
async function doSync() {
|
|
@@ -75,7 +76,16 @@ function getWorkspace() {
|
|
|
75
76
|
return JSON.parse(readFileSync('./system/sn-workspace.json').toString());
|
|
76
77
|
}
|
|
77
78
|
|
|
78
|
-
function
|
|
79
|
+
function handleError() {
|
|
80
|
+
getErrorMsg();
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function handleOptions(
|
|
85
|
+
program: Command,
|
|
86
|
+
options: Options,
|
|
87
|
+
option: keyof Options
|
|
88
|
+
) {
|
|
79
89
|
return (
|
|
80
90
|
shouldShowHelp(program, option) ||
|
|
81
91
|
((hasApplication() && options[option]) || showHelp(program))()
|
|
@@ -87,9 +97,8 @@ async function hasApplication() {
|
|
|
87
97
|
const workspace: Workspace = await getWorkspace();
|
|
88
98
|
const app: string = workspace.ACTIVE_APPLICATION;
|
|
89
99
|
return Object.entries(app).length === 0 ? getErrorMsg() : true;
|
|
90
|
-
} catch
|
|
91
|
-
|
|
92
|
-
return process.exit(1);
|
|
100
|
+
} catch {
|
|
101
|
+
return handleError();
|
|
93
102
|
}
|
|
94
103
|
}
|
|
95
104
|
|
|
@@ -101,7 +110,7 @@ async function init() {
|
|
|
101
110
|
const program = new Command();
|
|
102
111
|
const info = await getPackageInfo();
|
|
103
112
|
program.description(info.description);
|
|
104
|
-
program.version(info.version);
|
|
113
|
+
program.version(info.version, '-v, --version', 'output the current version');
|
|
105
114
|
program.option(
|
|
106
115
|
'-b, --build',
|
|
107
116
|
'build project utility files & package dependencies'
|
|
@@ -130,11 +139,11 @@ async function runSync() {
|
|
|
130
139
|
});
|
|
131
140
|
}
|
|
132
141
|
|
|
133
|
-
function shouldShowHelp(program:
|
|
142
|
+
function shouldShowHelp(program: Command, option: string) {
|
|
134
143
|
return !option && showHelp(program);
|
|
135
144
|
}
|
|
136
145
|
|
|
137
|
-
function showHelp(program:
|
|
146
|
+
function showHelp(program: Command) {
|
|
138
147
|
return program.help();
|
|
139
148
|
}
|
|
140
149
|
|