sn-typescript-util 1.2.3 → 1.2.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 +1 -1
- package/bin/snts.js +85 -91
- package/package.json +6 -1
- package/scripts/release.sh +19 -0
- package/{src → scripts}/snts.ts +4 -18
- package/tsconfig.json +2 -1
- /package/{src → scripts}/workspace.ts +0 -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/vancouver-application-development/page/build/applications/task/create-project.html) and [application imported](https://docs.servicenow.com/bundle/vancouver-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
CHANGED
|
@@ -7,125 +7,119 @@ 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 options = {
|
|
28
|
+
build: () => {
|
|
29
|
+
doBuild();
|
|
30
|
+
},
|
|
31
|
+
compile: () => {
|
|
32
|
+
doCompile();
|
|
33
|
+
},
|
|
34
|
+
sync: () => {
|
|
35
|
+
doSync();
|
|
36
|
+
},
|
|
37
|
+
default: () => {
|
|
38
|
+
program.help();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
return ((hasApplication() && options[option]) || options['default'])();
|
|
42
42
|
}
|
|
43
43
|
async function doSync() {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
function getBuildName() {
|
|
51
|
-
const defaultBuild = 'utah';
|
|
52
|
-
try {
|
|
53
|
-
const workspace = getWorkspace();
|
|
54
|
-
const app = workspace.ACTIVE_APPLICATION;
|
|
55
|
-
const build = workspace.ALL_APPLICATIONS[app].BUILD_NAME;
|
|
56
|
-
return Object.entries(build).length !== 0
|
|
57
|
-
? build.toLowerCase()
|
|
58
|
-
: defaultBuild;
|
|
59
|
-
}
|
|
60
|
-
catch (e) {
|
|
61
|
-
return defaultBuild;
|
|
62
|
-
}
|
|
44
|
+
const s = startPrompts('Processing', 'Sync started');
|
|
45
|
+
return await execFile(getFilePath('sync.sh'), (stdout) => {
|
|
46
|
+
stopPrompt(s, 'Completed');
|
|
47
|
+
return stdout;
|
|
48
|
+
});
|
|
63
49
|
}
|
|
64
50
|
function getErrorMsg() {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
51
|
+
var url = `https://docs.servicenow.com/bundle/vancouver-application-development/page/build/applications/task/create-project.html`;
|
|
52
|
+
var msg = `No active application detected. Please create a project with the ServiceNow Extension for VS Code.\n\n${url}`;
|
|
53
|
+
return console.error(bold(red(msg)));
|
|
68
54
|
}
|
|
69
55
|
function getFilePath(file, dir = 'scripts') {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
56
|
+
const fileName = fileURLToPath(import.meta.url);
|
|
57
|
+
const dirName = path.dirname(fileName);
|
|
58
|
+
return `${path.join(dirName, `../${dir}`)}/${file}`;
|
|
73
59
|
}
|
|
74
60
|
async function getPackageInfo() {
|
|
75
|
-
|
|
61
|
+
return JSON.parse(readFileSync(getFilePath('package.json', '.')).toString());
|
|
76
62
|
}
|
|
77
63
|
function getWorkspace() {
|
|
78
|
-
|
|
64
|
+
return JSON.parse(readFileSync('./system/sn-workspace.json').toString());
|
|
79
65
|
}
|
|
80
66
|
async function hasApplication() {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
67
|
+
try {
|
|
68
|
+
const workspace = await getWorkspace();
|
|
69
|
+
var app = workspace.ACTIVE_APPLICATION;
|
|
70
|
+
return Object.entries(app).length === 0 ? getErrorMsg() : true;
|
|
71
|
+
} catch (e) {
|
|
72
|
+
getErrorMsg();
|
|
73
|
+
return process.exit(1);
|
|
74
|
+
}
|
|
90
75
|
}
|
|
91
76
|
(async () => {
|
|
92
|
-
|
|
77
|
+
return init();
|
|
93
78
|
})();
|
|
94
79
|
async function init() {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
80
|
+
const program = new Command();
|
|
81
|
+
const info = await getPackageInfo();
|
|
82
|
+
program.description(info.description);
|
|
83
|
+
program.version(info.version);
|
|
84
|
+
program.option(
|
|
85
|
+
'-b, --build',
|
|
86
|
+
'build project utility files & package dependencies'
|
|
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);
|
|
103
97
|
}
|
|
104
98
|
function introPrompt(msg) {
|
|
105
|
-
|
|
99
|
+
return intro(msg);
|
|
106
100
|
}
|
|
107
101
|
async function runInstall() {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
102
|
+
const s = startPrompts('Installing packages', null);
|
|
103
|
+
return await execFile(getFilePath('install.sh'), (stdout) => {
|
|
104
|
+
stopPrompt(s, 'Packages installed');
|
|
105
|
+
outro('Completed');
|
|
106
|
+
return stdout;
|
|
107
|
+
});
|
|
114
108
|
}
|
|
115
109
|
async function runSync() {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
110
|
+
const s = startPrompts('Syncing', null);
|
|
111
|
+
return await execFile(getFilePath('sync.sh'), (stdout) => {
|
|
112
|
+
stopPrompt(s, 'Sync completed');
|
|
113
|
+
runInstall();
|
|
114
|
+
return stdout;
|
|
115
|
+
});
|
|
122
116
|
}
|
|
123
117
|
function startPrompts(start, intro) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
118
|
+
intro && introPrompt(intro);
|
|
119
|
+
const s = spinner();
|
|
120
|
+
s.start(start);
|
|
121
|
+
return s;
|
|
128
122
|
}
|
|
129
123
|
function stopPrompt(spinner, msg) {
|
|
130
|
-
|
|
124
|
+
return spinner.stop(msg);
|
|
131
125
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sn-typescript-util",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5",
|
|
4
4
|
"description": "A TypeScript utility for ServiceNow developers using VS Code",
|
|
5
5
|
"bin": {
|
|
6
6
|
"snts": "bin/snts.js"
|
|
@@ -16,6 +16,11 @@
|
|
|
16
16
|
"type": "git",
|
|
17
17
|
"url": "https://github.com/stevengregory/sn-typescript-util.git"
|
|
18
18
|
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"format": "prettier --write ./bin/*.js ./scripts/*.ts",
|
|
21
|
+
"release": "./scripts/release.sh",
|
|
22
|
+
"watch": "tsc --watch"
|
|
23
|
+
},
|
|
19
24
|
"type": "module",
|
|
20
25
|
"dependencies": {
|
|
21
26
|
"@clack/prompts": "^0.6.3",
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
bump_version() {
|
|
4
|
+
version=$(npm version "$1" --no-git-tag-version)
|
|
5
|
+
echo "version bumped to $version"
|
|
6
|
+
do_git_operation
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
do_git_operation() {
|
|
10
|
+
git commit -a -m "chore: bump the version"
|
|
11
|
+
git tag $(get_package_version)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
get_package_version() {
|
|
15
|
+
version=`node -p "require('./package.json').version"`
|
|
16
|
+
echo "v$version"
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
bump_version "$1"
|
package/{src → scripts}/snts.ts
RENAMED
|
@@ -28,8 +28,8 @@ async function doCompile() {
|
|
|
28
28
|
|
|
29
29
|
function doOptions(program: any) {
|
|
30
30
|
program.parse(process.argv).opts();
|
|
31
|
-
const option = Object.keys(program.opts()).toString();
|
|
32
|
-
const options = {
|
|
31
|
+
const option: string = Object.keys(program.opts()).toString();
|
|
32
|
+
const options: any = {
|
|
33
33
|
build: () => {
|
|
34
34
|
doBuild();
|
|
35
35
|
},
|
|
@@ -54,22 +54,8 @@ async function doSync() {
|
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
function getBuildName() {
|
|
58
|
-
const defaultBuild: string = 'utah';
|
|
59
|
-
try {
|
|
60
|
-
const workspace: Workspace = getWorkspace();
|
|
61
|
-
const app: string = workspace.ACTIVE_APPLICATION;
|
|
62
|
-
const build: string = workspace.ALL_APPLICATIONS[app].BUILD_NAME;
|
|
63
|
-
return Object.entries(build).length !== 0
|
|
64
|
-
? build.toLowerCase()
|
|
65
|
-
: defaultBuild;
|
|
66
|
-
} catch (e) {
|
|
67
|
-
return defaultBuild;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
57
|
function getErrorMsg() {
|
|
72
|
-
var url: string = `https://docs.servicenow.com/bundle
|
|
58
|
+
var url: string = `https://docs.servicenow.com/bundle/vancouver-application-development/page/build/applications/task/create-project.html`;
|
|
73
59
|
var msg: string = `No active application detected. Please create a project with the ServiceNow Extension for VS Code.\n\n${url}`;
|
|
74
60
|
return console.error(bold(red(msg)));
|
|
75
61
|
}
|
|
@@ -145,7 +131,7 @@ async function runSync() {
|
|
|
145
131
|
});
|
|
146
132
|
}
|
|
147
133
|
|
|
148
|
-
function startPrompts(start: string, intro: string) {
|
|
134
|
+
function startPrompts(start: string, intro: string | null) {
|
|
149
135
|
intro && introPrompt(intro);
|
|
150
136
|
const s = spinner();
|
|
151
137
|
s.start(start);
|
package/tsconfig.json
CHANGED
|
File without changes
|