sn-typescript-util 1.3.12 → 1.3.14
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/.eslintignore +1 -0
- package/.eslintrc.yml +0 -1
- package/README.md +2 -6
- package/bin/snts.js +42 -25
- package/bun.lockb +0 -0
- package/package.json +6 -7
- package/scripts/snts.ts +38 -27
- package/scripts/types/version.ts +6 -0
- package/scripts/utils/release.ts +80 -0
- package/scripts/utils/release.sh +0 -21
package/.eslintignore
CHANGED
package/.eslintrc.yml
CHANGED
package/README.md
CHANGED
|
@@ -54,14 +54,10 @@ In the application directory created by the ServiceNow Extension for VS Code, th
|
|
|
54
54
|
|
|
55
55
|
## Basic Workflow
|
|
56
56
|
|
|
57
|
-
After installation & setup, simply run the
|
|
57
|
+
After installation & setup, simply run the TypeScript compiler `--watch` command to start looking for TypeScript code changes in the `ts` directory.
|
|
58
58
|
|
|
59
59
|
```bash
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
# or
|
|
63
|
-
|
|
64
|
-
yarn watch
|
|
60
|
+
tsc --watch
|
|
65
61
|
```
|
|
66
62
|
|
|
67
63
|
Any JavaScript ES2015 (ES6) code added will get converted down to ES5 and moved to the `src` directory. Then changes are ready to sync with the target instance using the ServiceNow Extension for VS Code.
|
package/bin/snts.js
CHANGED
|
@@ -24,10 +24,10 @@ async function doCompile() {
|
|
|
24
24
|
}
|
|
25
25
|
);
|
|
26
26
|
}
|
|
27
|
-
function doOptions(program
|
|
27
|
+
function doOptions(program) {
|
|
28
28
|
const options = parseOptions(program);
|
|
29
29
|
const optionKey = options;
|
|
30
|
-
return handleOptions(program, getOptions(program), optionKey
|
|
30
|
+
return handleOptions(program, getOptions(program), optionKey);
|
|
31
31
|
}
|
|
32
32
|
async function doSync() {
|
|
33
33
|
const s = startPrompts('Processing', 'Sync started');
|
|
@@ -36,15 +36,36 @@ async function doSync() {
|
|
|
36
36
|
return stdout;
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
|
+
function getConstants() {
|
|
40
|
+
let Constants;
|
|
41
|
+
(function (Constants) {
|
|
42
|
+
Constants['projectName'] = 'SN TypeScript Util';
|
|
43
|
+
Constants['projectDescription'] =
|
|
44
|
+
'is a TS utility for ServiceNow developers using VS Code.';
|
|
45
|
+
Constants['errorMsg'] =
|
|
46
|
+
'No active application detected. Please create a project with the ServiceNow Extension for VS Code.';
|
|
47
|
+
Constants['docsUrl'] =
|
|
48
|
+
'https://docs.servicenow.com/bundle/vancouver-application-development/page/build/applications/task/create-project.html';
|
|
49
|
+
Constants['buildOption'] =
|
|
50
|
+
'Build project utility files & package dependencies';
|
|
51
|
+
Constants['compileOption'] =
|
|
52
|
+
'Compile TypeScript files to JavaScript & move to src';
|
|
53
|
+
Constants['helpOption'] = 'Display help for command';
|
|
54
|
+
Constants['syncOption'] =
|
|
55
|
+
'Sync new instance-based src files to the ts directory';
|
|
56
|
+
Constants['versionOption'] = 'Output the current version';
|
|
57
|
+
})(Constants || (Constants = {}));
|
|
58
|
+
return Constants;
|
|
59
|
+
}
|
|
39
60
|
function getDescription(version) {
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
|
|
61
|
+
const constants = getConstants();
|
|
62
|
+
const title = constants.projectName;
|
|
63
|
+
const description = constants.projectDescription;
|
|
43
64
|
return `${bold(magenta(title))} ${description} ${gray(`(v${version})`)}\n`;
|
|
44
65
|
}
|
|
45
66
|
function getErrorMsg() {
|
|
46
|
-
const
|
|
47
|
-
const msg =
|
|
67
|
+
const constants = getConstants();
|
|
68
|
+
const msg = `${constants.errorMsg}\n\n${constants.docsUrl}`;
|
|
48
69
|
return console.error(bold(red(msg)));
|
|
49
70
|
}
|
|
50
71
|
function getFilePath(file, dir = 'scripts/build') {
|
|
@@ -74,6 +95,10 @@ function getOptions(program) {
|
|
|
74
95
|
async function getPackageInfo() {
|
|
75
96
|
return JSON.parse(readFileSync(getFilePath('package.json', '.')).toString());
|
|
76
97
|
}
|
|
98
|
+
async function getVersion() {
|
|
99
|
+
const info = await getPackageInfo();
|
|
100
|
+
return info.version;
|
|
101
|
+
}
|
|
77
102
|
function getWorkspace() {
|
|
78
103
|
return JSON.parse(readFileSync('./system/sn-workspace.json').toString());
|
|
79
104
|
}
|
|
@@ -81,8 +106,9 @@ function handleError() {
|
|
|
81
106
|
getErrorMsg();
|
|
82
107
|
return process.exit(1);
|
|
83
108
|
}
|
|
84
|
-
function handleOptions(program, options, option
|
|
109
|
+
async function handleOptions(program, options, option) {
|
|
85
110
|
if (option === 'help' || !option) {
|
|
111
|
+
const version = await getVersion();
|
|
86
112
|
console.log(getDescription(version));
|
|
87
113
|
showHelp(program);
|
|
88
114
|
}
|
|
@@ -105,24 +131,15 @@ async function hasApplication() {
|
|
|
105
131
|
})();
|
|
106
132
|
async function init() {
|
|
107
133
|
const program = new Command();
|
|
108
|
-
const
|
|
109
|
-
const version =
|
|
110
|
-
program.option(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
);
|
|
114
|
-
program.
|
|
115
|
-
'-c, --compile',
|
|
116
|
-
'compile TypeScript files to JavaScript & move to src'
|
|
117
|
-
);
|
|
118
|
-
program.option('-h, --help', 'display help for command');
|
|
119
|
-
program.option(
|
|
120
|
-
'-s, --sync',
|
|
121
|
-
'sync new instance-based src files to the ts directory'
|
|
122
|
-
);
|
|
123
|
-
program.version(version, '-v, --version', 'output the current version');
|
|
134
|
+
const constants = getConstants();
|
|
135
|
+
const version = await getVersion();
|
|
136
|
+
program.option('-b, --build', constants.buildOption);
|
|
137
|
+
program.option('-c, --compile', constants.compileOption);
|
|
138
|
+
program.option('-h, --help', constants.helpOption);
|
|
139
|
+
program.option('-s, --sync', constants.syncOption);
|
|
140
|
+
program.version(version, '-v, --version', constants.versionOption);
|
|
124
141
|
program.usage(cyan('[options]'));
|
|
125
|
-
return doOptions(program
|
|
142
|
+
return doOptions(program);
|
|
126
143
|
}
|
|
127
144
|
function introPrompt(msg) {
|
|
128
145
|
return intro(msg);
|
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.14",
|
|
4
4
|
"description": "A TypeScript utility for ServiceNow developers using VS Code",
|
|
5
5
|
"bin": {
|
|
6
6
|
"snts": "bin/snts.js"
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"scripts": {
|
|
20
20
|
"format": "prettier --write ./bin/*.js ./scripts/*.ts",
|
|
21
21
|
"lint": "eslint .",
|
|
22
|
-
"release": "./scripts/utils/release.
|
|
22
|
+
"release": "bun ./scripts/utils/release.ts",
|
|
23
23
|
"watch": "tsc --watch"
|
|
24
24
|
},
|
|
25
25
|
"type": "module",
|
|
@@ -28,15 +28,14 @@
|
|
|
28
28
|
"@types/servicenow": "^10.0.4",
|
|
29
29
|
"colorette": "^2.0.20",
|
|
30
30
|
"commander": "^11.1.0",
|
|
31
|
-
"npm-add-script": "^1.1.0",
|
|
32
31
|
"typescript": "^5.3.3"
|
|
33
32
|
},
|
|
34
33
|
"devDependencies": {
|
|
35
34
|
"@types/commander": "^2.12.2",
|
|
36
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
37
|
-
"@typescript-eslint/parser": "^6.
|
|
38
|
-
"bun-types": "^1.0.
|
|
35
|
+
"@typescript-eslint/eslint-plugin": "^6.19.0",
|
|
36
|
+
"@typescript-eslint/parser": "^6.19.0",
|
|
37
|
+
"bun-types": "^1.0.23",
|
|
39
38
|
"eslint": "^8.56.0",
|
|
40
|
-
"prettier": "^3.
|
|
39
|
+
"prettier": "^3.2.2"
|
|
41
40
|
}
|
|
42
41
|
}
|
package/scripts/snts.ts
CHANGED
|
@@ -33,10 +33,10 @@ async function doCompile() {
|
|
|
33
33
|
);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
function doOptions(program: Command
|
|
36
|
+
function doOptions(program: Command) {
|
|
37
37
|
const options = parseOptions(program);
|
|
38
38
|
const optionKey = options as keyof Options;
|
|
39
|
-
return handleOptions(program, getOptions(program), optionKey
|
|
39
|
+
return handleOptions(program, getOptions(program), optionKey);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
async function doSync() {
|
|
@@ -50,16 +50,31 @@ async function doSync() {
|
|
|
50
50
|
);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
function getConstants() {
|
|
54
|
+
enum Constants {
|
|
55
|
+
projectName = 'SN TypeScript Util',
|
|
56
|
+
projectDescription = 'is a TS utility for ServiceNow developers using VS Code.',
|
|
57
|
+
errorMsg = 'No active application detected. Please create a project with the ServiceNow Extension for VS Code.',
|
|
58
|
+
docsUrl = 'https://docs.servicenow.com/bundle/vancouver-application-development/page/build/applications/task/create-project.html',
|
|
59
|
+
buildOption = 'Build project utility files & package dependencies',
|
|
60
|
+
compileOption = 'Compile TypeScript files to JavaScript & move to src',
|
|
61
|
+
helpOption = 'Display help for command',
|
|
62
|
+
syncOption = 'Sync new instance-based src files to the ts directory',
|
|
63
|
+
versionOption = 'Output the current version'
|
|
64
|
+
}
|
|
65
|
+
return Constants;
|
|
66
|
+
}
|
|
67
|
+
|
|
53
68
|
function getDescription(version: string) {
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
|
|
69
|
+
const constants = getConstants();
|
|
70
|
+
const title: string = constants.projectName;
|
|
71
|
+
const description: string = constants.projectDescription;
|
|
57
72
|
return `${bold(magenta(title))} ${description} ${gray(`(v${version})`)}\n`;
|
|
58
73
|
}
|
|
59
74
|
|
|
60
75
|
function getErrorMsg() {
|
|
61
|
-
const
|
|
62
|
-
const msg: string =
|
|
76
|
+
const constants = getConstants();
|
|
77
|
+
const msg: string = `${constants.errorMsg}\n\n${constants.docsUrl}`;
|
|
63
78
|
return console.error(bold(red(msg)));
|
|
64
79
|
}
|
|
65
80
|
|
|
@@ -93,6 +108,11 @@ async function getPackageInfo() {
|
|
|
93
108
|
return JSON.parse(readFileSync(getFilePath('package.json', '.')).toString());
|
|
94
109
|
}
|
|
95
110
|
|
|
111
|
+
async function getVersion() {
|
|
112
|
+
const info = await getPackageInfo();
|
|
113
|
+
return info.version;
|
|
114
|
+
}
|
|
115
|
+
|
|
96
116
|
function getWorkspace() {
|
|
97
117
|
return JSON.parse(readFileSync('./system/sn-workspace.json').toString());
|
|
98
118
|
}
|
|
@@ -102,13 +122,13 @@ function handleError() {
|
|
|
102
122
|
return process.exit(1);
|
|
103
123
|
}
|
|
104
124
|
|
|
105
|
-
function handleOptions(
|
|
125
|
+
async function handleOptions(
|
|
106
126
|
program: Command,
|
|
107
127
|
options: Options,
|
|
108
|
-
option: keyof Options
|
|
109
|
-
version: string
|
|
128
|
+
option: keyof Options
|
|
110
129
|
) {
|
|
111
130
|
if (option === 'help' || !option) {
|
|
131
|
+
const version = await getVersion();
|
|
112
132
|
console.log(getDescription(version));
|
|
113
133
|
showHelp(program);
|
|
114
134
|
}
|
|
@@ -134,24 +154,15 @@ async function hasApplication() {
|
|
|
134
154
|
|
|
135
155
|
async function init() {
|
|
136
156
|
const program = new Command();
|
|
137
|
-
const
|
|
138
|
-
const version =
|
|
139
|
-
program.option(
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
);
|
|
143
|
-
program.
|
|
144
|
-
'-c, --compile',
|
|
145
|
-
'compile TypeScript files to JavaScript & move to src'
|
|
146
|
-
);
|
|
147
|
-
program.option('-h, --help', 'display help for command');
|
|
148
|
-
program.option(
|
|
149
|
-
'-s, --sync',
|
|
150
|
-
'sync new instance-based src files to the ts directory'
|
|
151
|
-
);
|
|
152
|
-
program.version(version, '-v, --version', 'output the current version');
|
|
157
|
+
const constants = getConstants();
|
|
158
|
+
const version = await getVersion();
|
|
159
|
+
program.option('-b, --build', constants.buildOption);
|
|
160
|
+
program.option('-c, --compile', constants.compileOption);
|
|
161
|
+
program.option('-h, --help', constants.helpOption);
|
|
162
|
+
program.option('-s, --sync', constants.syncOption);
|
|
163
|
+
program.version(version, '-v, --version', constants.versionOption);
|
|
153
164
|
program.usage(cyan('[options]'));
|
|
154
|
-
return doOptions(program
|
|
165
|
+
return doOptions(program);
|
|
155
166
|
}
|
|
156
167
|
|
|
157
168
|
function introPrompt(msg: string) {
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { $ } from 'execa';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { readFileSync } from 'fs';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
import { cancel, confirm, intro, outro, select, spinner } from '@clack/prompts';
|
|
6
|
+
import { Version } from './../types/version.js';
|
|
7
|
+
|
|
8
|
+
async function bumpVersion(releaseType) {
|
|
9
|
+
return await $`npm version ${releaseType} --no-git-tag-version`;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async function confirmVersion(version: string) {
|
|
13
|
+
return await confirm({
|
|
14
|
+
message: `Bump to ${version}?`
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function doGitOperation(version: string) {
|
|
19
|
+
const msg = 'chore: bump the version';
|
|
20
|
+
await $`git commit -a -m ${msg}`;
|
|
21
|
+
await $`git tag ${version}`;
|
|
22
|
+
await $`git push`;
|
|
23
|
+
await $`git push origin ${version}`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function doOperation(shouldContinue, version: string) {
|
|
27
|
+
if (shouldContinue) {
|
|
28
|
+
const s = spinner();
|
|
29
|
+
s.start('Start release');
|
|
30
|
+
await doGitOperation(version);
|
|
31
|
+
await doPublish();
|
|
32
|
+
s.stop('Done.');
|
|
33
|
+
outro("You're all set!");
|
|
34
|
+
} else {
|
|
35
|
+
cancel('Operation cancelled.');
|
|
36
|
+
await $`git checkout package.json`;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function doPublish() {
|
|
41
|
+
return await $`npm publish`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function getFilePath(file: string, dir: string) {
|
|
45
|
+
const fileName = fileURLToPath(import.meta.url);
|
|
46
|
+
const dirName = path.dirname(fileName);
|
|
47
|
+
return `${path.join(dirName, `./../../${dir}`)}/${file}`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function getPackageInfo() {
|
|
51
|
+
return JSON.parse(readFileSync(getFilePath('package.json', '.')).toString());
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function getReleaseTypes() {
|
|
55
|
+
return select({
|
|
56
|
+
message: 'Please pick a release type.',
|
|
57
|
+
options: getOptions()
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function getOptions(): Version[] {
|
|
62
|
+
return [
|
|
63
|
+
{ value: 'patch', label: 'Patch' },
|
|
64
|
+
{ value: 'minor', label: 'Minor' },
|
|
65
|
+
{ value: 'major', label: 'Major' }
|
|
66
|
+
];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function getVersion() {
|
|
70
|
+
const file = await getPackageInfo();
|
|
71
|
+
return file.version;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
(async function init() {
|
|
75
|
+
intro('Release Utils');
|
|
76
|
+
const releaseType = await getReleaseTypes();
|
|
77
|
+
const version = (await bumpVersion(releaseType)) && (await getVersion());
|
|
78
|
+
const shouldContinue = await confirmVersion(version);
|
|
79
|
+
return await doOperation(shouldContinue, version);
|
|
80
|
+
})();
|
package/scripts/utils/release.sh
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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
|
-
git push
|
|
13
|
-
git push origin $(get_package_version)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
get_package_version() {
|
|
17
|
-
version=`node -p "require('./package.json').version"`
|
|
18
|
-
echo "v$version"
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
bump_version "$1"
|