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 CHANGED
@@ -133,7 +133,7 @@ snts --version
133
133
 
134
134
  # or
135
135
 
136
- snts -V
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
- │ │ └── Dashboard.client_script.ts
174
- │ │ └── Dashboard.link.ts
175
- │ │ └── Dashboard.script.ts
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
- 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
- });
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
- const s = startPrompts('Processing', 'Compile started');
19
- return await execFile(getFilePath('compile.rb'), (stdout) => {
20
- stopPrompt(s, 'Completed');
21
- return stdout;
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
- 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 handleOptions(program, options, option);
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
- const s = startPrompts('Processing', 'Sync started');
45
- return await execFile(getFilePath('sync.sh'), (stdout) => {
46
- stopPrompt(s, 'Completed');
47
- return stdout;
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
- const url = `https://docs.servicenow.com/bundle/vancouver-application-development/page/build/applications/task/create-project.html`;
52
- const 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)));
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
- const fileName = fileURLToPath(import.meta.url);
57
- const dirName = path.dirname(fileName);
58
- return `${path.join(dirName, `../${dir}`)}/${file}`;
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
- return JSON.parse(readFileSync(getFilePath('package.json', '.')).toString());
62
+ return JSON.parse(readFileSync(getFilePath('package.json', '.')).toString());
62
63
  }
63
64
  function getWorkspace() {
64
- return JSON.parse(readFileSync('./system/sn-workspace.json').toString());
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
- return (shouldShowHelp(program, option) ||
68
- ((hasApplication() && options[option]) || showHelp(program))());
72
+ return (
73
+ shouldShowHelp(program, option) ||
74
+ ((hasApplication() && options[option]) || showHelp(program))()
75
+ );
69
76
  }
70
77
  async function hasApplication() {
71
- try {
72
- const workspace = await getWorkspace();
73
- const app = workspace.ACTIVE_APPLICATION;
74
- return Object.entries(app).length === 0 ? getErrorMsg() : true;
75
- }
76
- catch (e) {
77
- getErrorMsg();
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
- return init();
87
+ return init();
83
88
  })();
84
89
  async function init() {
85
- const program = new Command();
86
- const info = await getPackageInfo();
87
- program.description(info.description);
88
- program.version(info.version);
89
- program.option('-b, --build', 'build project utility files & package dependencies');
90
- program.option('-c, --compile', 'compile TypeScript files to JavaScript & move to src');
91
- program.option('-s, --sync', 'sync new instance-based src files to the ts directory');
92
- return doOptions(program);
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
- return intro(msg);
109
+ return intro(msg);
96
110
  }
97
111
  async function runSync() {
98
- const s = startPrompts('Syncing', null);
99
- return await execFile(getFilePath('sync.sh'), (stdout) => {
100
- stopPrompt(s, 'Sync completed');
101
- outro('Completed');
102
- return stdout;
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
- return !option && showHelp(program);
120
+ return !option && showHelp(program);
107
121
  }
108
122
  function showHelp(program) {
109
- return program.help();
123
+ return program.help();
110
124
  }
111
125
  function startPrompts(start, intro) {
112
- intro && introPrompt(intro);
113
- const s = spinner();
114
- s.start(start);
115
- return s;
126
+ intro && introPrompt(intro);
127
+ const s = spinner();
128
+ s.start(start);
129
+ return s;
116
130
  }
117
131
  function stopPrompt(spinner, msg) {
118
- return spinner.stop(msg);
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.4",
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
- "@typescript-eslint/eslint-plugin": "^6.15.0",
36
- "@typescript-eslint/parser": "^6.15.0",
37
- "bun-types": "^1.0.18-1",
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
  }
@@ -1,6 +1,6 @@
1
- export type Options = {
1
+ export interface Options {
2
2
  build: () => void;
3
3
  compile: () => void;
4
4
  sync: () => void;
5
5
  default: () => void;
6
- };
6
+ }
package/scripts/snts.ts CHANGED
@@ -27,9 +27,10 @@ async function doCompile() {
27
27
  });
28
28
  }
29
29
 
30
- function doOptions(program: any) {
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, option);
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 handleOptions(program: any, options: Options, option: string) {
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 (e) {
91
- getErrorMsg();
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: any, option: string) {
142
+ function shouldShowHelp(program: Command, option: string) {
134
143
  return !option && showHelp(program);
135
144
  }
136
145
 
137
- function showHelp(program: any) {
146
+ function showHelp(program: Command) {
138
147
  return program.help();
139
148
  }
140
149