sn-typescript-util 1.3.11 → 1.3.13

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/bin/snts.js CHANGED
@@ -25,27 +25,9 @@ async function doCompile() {
25
25
  );
26
26
  }
27
27
  function doOptions(program, version) {
28
- program.parse(process.argv).opts();
29
- const option = Object.keys(program.opts()).toString();
30
- const optionKey = option;
31
- const options = {
32
- build: () => {
33
- doBuild();
34
- },
35
- compile: () => {
36
- doCompile();
37
- },
38
- help: () => {
39
- showHelp(program);
40
- },
41
- sync: () => {
42
- doSync();
43
- },
44
- default: () => {
45
- showHelp(program);
46
- }
47
- };
48
- return handleOptions(program, options, optionKey, version);
28
+ const options = parseOptions(program);
29
+ const optionKey = options;
30
+ return handleOptions(program, getOptions(program), optionKey, version);
49
31
  }
50
32
  async function doSync() {
51
33
  const s = startPrompts('Processing', 'Sync started');
@@ -54,15 +36,36 @@ async function doSync() {
54
36
  return stdout;
55
37
  });
56
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
+ }
57
60
  function getDescription(version) {
58
- const title = 'SN TypeScript Util';
59
- const description =
60
- 'is a TS utility for ServiceNow developers using VS Code.';
61
+ const constants = getConstants();
62
+ const title = constants.projectName;
63
+ const description = constants.projectDescription;
61
64
  return `${bold(magenta(title))} ${description} ${gray(`(v${version})`)}\n`;
62
65
  }
63
66
  function getErrorMsg() {
64
- const url = `https://docs.servicenow.com/bundle/vancouver-application-development/page/build/applications/task/create-project.html`;
65
- const msg = `No active application detected. Please create a project with the ServiceNow Extension for VS Code.\n\n${url}`;
67
+ const constants = getConstants();
68
+ const msg = `${constants.errorMsg}\n\n${constants.docsUrl}`;
66
69
  return console.error(bold(red(msg)));
67
70
  }
68
71
  function getFilePath(file, dir = 'scripts/build') {
@@ -70,6 +73,25 @@ function getFilePath(file, dir = 'scripts/build') {
70
73
  const dirName = path.dirname(fileName);
71
74
  return `${path.join(dirName, `../${dir}`)}/${file}`;
72
75
  }
76
+ function getOptions(program) {
77
+ return {
78
+ build: () => {
79
+ doBuild();
80
+ },
81
+ compile: () => {
82
+ doCompile();
83
+ },
84
+ help: () => {
85
+ showHelp(program);
86
+ },
87
+ sync: () => {
88
+ doSync();
89
+ },
90
+ default: () => {
91
+ showHelp(program);
92
+ }
93
+ };
94
+ }
73
95
  async function getPackageInfo() {
74
96
  return JSON.parse(readFileSync(getFilePath('package.json', '.')).toString());
75
97
  }
@@ -105,27 +127,23 @@ async function hasApplication() {
105
127
  async function init() {
106
128
  const program = new Command();
107
129
  const info = await getPackageInfo();
130
+ const constants = getConstants();
108
131
  const version = info.version;
109
- program.option(
110
- '-b, --build',
111
- 'build project utility files & package dependencies'
112
- );
113
- program.option(
114
- '-c, --compile',
115
- 'compile TypeScript files to JavaScript & move to src'
116
- );
117
- program.option('-h, --help', 'display help for command');
118
- program.option(
119
- '-s, --sync',
120
- 'sync new instance-based src files to the ts directory'
121
- );
122
- program.version(version, '-v, --version', 'output the current version');
132
+ program.option('-b, --build', constants.buildOption);
133
+ program.option('-c, --compile', constants.compileOption);
134
+ program.option('-h, --help', constants.helpOption);
135
+ program.option('-s, --sync', constants.syncOption);
136
+ program.version(version, '-v, --version', constants.versionOption);
123
137
  program.usage(cyan('[options]'));
124
138
  return doOptions(program, version);
125
139
  }
126
140
  function introPrompt(msg) {
127
141
  return intro(msg);
128
142
  }
143
+ function parseOptions(program) {
144
+ const options = program.parse(process.argv).opts();
145
+ return options && Object.keys(program.opts()).toString();
146
+ }
129
147
  async function runSync() {
130
148
  const s = startPrompts('Syncing', null);
131
149
  return await execFile(getFilePath('sync.sh', 'scripts/build'), (stdout) => {
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.11",
3
+ "version": "1.3.13",
4
4
  "description": "A TypeScript utility for ServiceNow developers using VS Code",
5
5
  "bin": {
6
6
  "snts": "bin/snts.js"
@@ -33,10 +33,10 @@
33
33
  },
34
34
  "devDependencies": {
35
35
  "@types/commander": "^2.12.2",
36
- "@typescript-eslint/eslint-plugin": "^6.18.1",
37
- "@typescript-eslint/parser": "^6.18.1",
38
- "bun-types": "^1.0.22",
36
+ "@typescript-eslint/eslint-plugin": "^6.19.0",
37
+ "@typescript-eslint/parser": "^6.19.0",
38
+ "bun-types": "^1.0.23",
39
39
  "eslint": "^8.56.0",
40
- "prettier": "^3.1.1"
40
+ "prettier": "^3.2.2"
41
41
  }
42
42
  }
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require_relative File.join(__dir__, './../utils/util')
3
+ require_relative File.join(__dir__, './../utils/utils')
4
4
 
5
5
  module ServiceNow
6
6
  class Build
package/scripts/snts.ts CHANGED
@@ -34,27 +34,9 @@ async function doCompile() {
34
34
  }
35
35
 
36
36
  function doOptions(program: Command, version: string) {
37
- program.parse(process.argv).opts();
38
- const option: string = Object.keys(program.opts()).toString();
39
- const optionKey = option as keyof Options;
40
- const options: Options = {
41
- build: () => {
42
- doBuild();
43
- },
44
- compile: () => {
45
- doCompile();
46
- },
47
- help: () => {
48
- showHelp(program);
49
- },
50
- sync: () => {
51
- doSync();
52
- },
53
- default: () => {
54
- showHelp(program);
55
- }
56
- };
57
- return handleOptions(program, options, optionKey, version);
37
+ const options = parseOptions(program);
38
+ const optionKey = options as keyof Options;
39
+ return handleOptions(program, getOptions(program), optionKey, version);
58
40
  }
59
41
 
60
42
  async function doSync() {
@@ -68,16 +50,31 @@ async function doSync() {
68
50
  );
69
51
  }
70
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
+
71
68
  function getDescription(version: string) {
72
- const title = 'SN TypeScript Util';
73
- const description =
74
- 'is a TS utility for ServiceNow developers using VS Code.';
69
+ const constants = getConstants();
70
+ const title: string = constants.projectName;
71
+ const description: string = constants.projectDescription;
75
72
  return `${bold(magenta(title))} ${description} ${gray(`(v${version})`)}\n`;
76
73
  }
77
74
 
78
75
  function getErrorMsg() {
79
- const url: string = `https://docs.servicenow.com/bundle/vancouver-application-development/page/build/applications/task/create-project.html`;
80
- const msg: string = `No active application detected. Please create a project with the ServiceNow Extension for VS Code.\n\n${url}`;
76
+ const constants = getConstants();
77
+ const msg: string = `${constants.errorMsg}\n\n${constants.docsUrl}`;
81
78
  return console.error(bold(red(msg)));
82
79
  }
83
80
 
@@ -87,6 +84,26 @@ function getFilePath(file: string, dir: string = 'scripts/build') {
87
84
  return `${path.join(dirName, `../${dir}`)}/${file}`;
88
85
  }
89
86
 
87
+ function getOptions(program: Command): Options {
88
+ return {
89
+ build: () => {
90
+ doBuild();
91
+ },
92
+ compile: () => {
93
+ doCompile();
94
+ },
95
+ help: () => {
96
+ showHelp(program);
97
+ },
98
+ sync: () => {
99
+ doSync();
100
+ },
101
+ default: () => {
102
+ showHelp(program);
103
+ }
104
+ };
105
+ }
106
+
90
107
  async function getPackageInfo() {
91
108
  return JSON.parse(readFileSync(getFilePath('package.json', '.')).toString());
92
109
  }
@@ -133,21 +150,13 @@ async function hasApplication() {
133
150
  async function init() {
134
151
  const program = new Command();
135
152
  const info = await getPackageInfo();
153
+ const constants = getConstants();
136
154
  const version = info.version;
137
- program.option(
138
- '-b, --build',
139
- 'build project utility files & package dependencies'
140
- );
141
- program.option(
142
- '-c, --compile',
143
- 'compile TypeScript files to JavaScript & move to src'
144
- );
145
- program.option('-h, --help', 'display help for command');
146
- program.option(
147
- '-s, --sync',
148
- 'sync new instance-based src files to the ts directory'
149
- );
150
- program.version(version, '-v, --version', 'output the current version');
155
+ program.option('-b, --build', constants.buildOption);
156
+ program.option('-c, --compile', constants.compileOption);
157
+ program.option('-h, --help', constants.helpOption);
158
+ program.option('-s, --sync', constants.syncOption);
159
+ program.version(version, '-v, --version', constants.versionOption);
151
160
  program.usage(cyan('[options]'));
152
161
  return doOptions(program, version);
153
162
  }
@@ -156,6 +165,11 @@ function introPrompt(msg: string) {
156
165
  return intro(msg);
157
166
  }
158
167
 
168
+ function parseOptions(program: Command) {
169
+ const options = program.parse(process.argv).opts();
170
+ return options && Object.keys(program.opts()).toString();
171
+ }
172
+
159
173
  async function runSync() {
160
174
  const s = startPrompts('Syncing', null);
161
175
  return await execFile(
File without changes