sn-typescript-util 1.3.13 → 1.3.15

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 CHANGED
@@ -1 +1,2 @@
1
1
  node_modules
2
+ tmp
package/.eslintrc.yml CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended']
3
2
  parser: '@typescript-eslint/parser'
4
3
  plugins: ['@typescript-eslint']
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 `watch` script to start looking for TypeScript code changes in the `ts` directory.
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
- npm run watch
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, version) {
27
+ function doOptions(program) {
28
28
  const options = parseOptions(program);
29
29
  const optionKey = options;
30
- return handleOptions(program, getOptions(program), optionKey, version);
30
+ return handleOptions(program, getOptions(program), optionKey);
31
31
  }
32
32
  async function doSync() {
33
33
  const s = startPrompts('Processing', 'Sync started');
@@ -95,6 +95,10 @@ function getOptions(program) {
95
95
  async function getPackageInfo() {
96
96
  return JSON.parse(readFileSync(getFilePath('package.json', '.')).toString());
97
97
  }
98
+ async function getVersion() {
99
+ const info = await getPackageInfo();
100
+ return info.version;
101
+ }
98
102
  function getWorkspace() {
99
103
  return JSON.parse(readFileSync('./system/sn-workspace.json').toString());
100
104
  }
@@ -102,8 +106,9 @@ function handleError() {
102
106
  getErrorMsg();
103
107
  return process.exit(1);
104
108
  }
105
- function handleOptions(program, options, option, version) {
109
+ async function handleOptions(program, options, option) {
106
110
  if (option === 'help' || !option) {
111
+ const version = await getVersion();
107
112
  console.log(getDescription(version));
108
113
  showHelp(program);
109
114
  }
@@ -126,16 +131,15 @@ async function hasApplication() {
126
131
  })();
127
132
  async function init() {
128
133
  const program = new Command();
129
- const info = await getPackageInfo();
130
134
  const constants = getConstants();
131
- const version = info.version;
135
+ const version = await getVersion();
132
136
  program.option('-b, --build', constants.buildOption);
133
137
  program.option('-c, --compile', constants.compileOption);
134
138
  program.option('-h, --help', constants.helpOption);
135
139
  program.option('-s, --sync', constants.syncOption);
136
140
  program.version(version, '-v, --version', constants.versionOption);
137
141
  program.usage(cyan('[options]'));
138
- return doOptions(program, version);
142
+ return doOptions(program);
139
143
  }
140
144
  function introPrompt(msg) {
141
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.13",
3
+ "version": "1.3.15",
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.sh",
22
+ "release": "bun ./scripts/utils/release.ts",
23
23
  "watch": "tsc --watch"
24
24
  },
25
25
  "type": "module",
@@ -28,7 +28,6 @@
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": {
package/scripts/snts.ts CHANGED
@@ -33,10 +33,10 @@ async function doCompile() {
33
33
  );
34
34
  }
35
35
 
36
- function doOptions(program: Command, version: string) {
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, version);
39
+ return handleOptions(program, getOptions(program), optionKey);
40
40
  }
41
41
 
42
42
  async function doSync() {
@@ -108,6 +108,11 @@ async function getPackageInfo() {
108
108
  return JSON.parse(readFileSync(getFilePath('package.json', '.')).toString());
109
109
  }
110
110
 
111
+ async function getVersion() {
112
+ const info = await getPackageInfo();
113
+ return info.version;
114
+ }
115
+
111
116
  function getWorkspace() {
112
117
  return JSON.parse(readFileSync('./system/sn-workspace.json').toString());
113
118
  }
@@ -117,13 +122,13 @@ function handleError() {
117
122
  return process.exit(1);
118
123
  }
119
124
 
120
- function handleOptions(
125
+ async function handleOptions(
121
126
  program: Command,
122
127
  options: Options,
123
- option: keyof Options,
124
- version: string
128
+ option: keyof Options
125
129
  ) {
126
130
  if (option === 'help' || !option) {
131
+ const version = await getVersion();
127
132
  console.log(getDescription(version));
128
133
  showHelp(program);
129
134
  }
@@ -149,16 +154,15 @@ async function hasApplication() {
149
154
 
150
155
  async function init() {
151
156
  const program = new Command();
152
- const info = await getPackageInfo();
153
157
  const constants = getConstants();
154
- const version = info.version;
158
+ const version = await getVersion();
155
159
  program.option('-b, --build', constants.buildOption);
156
160
  program.option('-c, --compile', constants.compileOption);
157
161
  program.option('-h, --help', constants.helpOption);
158
162
  program.option('-s, --sync', constants.syncOption);
159
163
  program.version(version, '-v, --version', constants.versionOption);
160
164
  program.usage(cyan('[options]'));
161
- return doOptions(program, version);
165
+ return doOptions(program);
162
166
  }
163
167
 
164
168
  function introPrompt(msg: string) {
@@ -0,0 +1,6 @@
1
+ type VersionType = 'patch' | 'minor' | 'major';
2
+
3
+ export interface Version {
4
+ value: VersionType;
5
+ label: Capitalize<VersionType>;
6
+ }
@@ -0,0 +1,84 @@
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 cancelOperation() {
13
+ cancel('Operation cancelled.');
14
+ await $`git checkout package.json`;
15
+ }
16
+
17
+ async function confirmVersion(version: string) {
18
+ return await confirm({
19
+ message: `Bump to ${version}?`
20
+ });
21
+ }
22
+
23
+ async function doGitOperation(version: string) {
24
+ const msg = 'chore: bump the version';
25
+ await $`git commit -a -m ${msg}`;
26
+ await $`git tag ${version}`;
27
+ await $`git push`;
28
+ await $`git push origin ${version}`;
29
+ }
30
+
31
+ async function doOperation(shouldContinue, version: string) {
32
+ if (shouldContinue) {
33
+ const s = spinner();
34
+ s.start('Start release');
35
+ await doGitOperation(version);
36
+ await doPublish();
37
+ s.stop('Done.');
38
+ outro("You're all set!");
39
+ } else {
40
+ cancelOperation();
41
+ }
42
+ }
43
+
44
+ async function doPublish() {
45
+ return await $`npm publish`;
46
+ }
47
+
48
+ function getFilePath(file: string, dir: string) {
49
+ const fileName = fileURLToPath(import.meta.url);
50
+ const dirName = path.dirname(fileName);
51
+ return `${path.join(dirName, `./../../${dir}`)}/${file}`;
52
+ }
53
+
54
+ async function getPackageInfo() {
55
+ return JSON.parse(readFileSync(getFilePath('package.json', '.')).toString());
56
+ }
57
+
58
+ async function getReleaseTypes() {
59
+ return select({
60
+ message: 'Please pick a release type.',
61
+ options: getOptions()
62
+ });
63
+ }
64
+
65
+ function getOptions(): Version[] {
66
+ return [
67
+ { value: 'patch', label: 'Patch' },
68
+ { value: 'minor', label: 'Minor' },
69
+ { value: 'major', label: 'Major' }
70
+ ];
71
+ }
72
+
73
+ async function getVersion() {
74
+ const file = await getPackageInfo();
75
+ return `v${file.version}`;
76
+ }
77
+
78
+ (async function init() {
79
+ intro('Release Utils');
80
+ const releaseType = await getReleaseTypes();
81
+ const version = (await bumpVersion(releaseType)) && (await getVersion());
82
+ const shouldContinue = await confirmVersion(version);
83
+ return await doOperation(shouldContinue, version);
84
+ })();
@@ -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"