sn-typescript-util 1.1.0 → 1.2.1

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 ADDED
@@ -0,0 +1,129 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ import { execFile } from 'node:child_process';
4
+ import path from 'path';
5
+ import { readFileSync } from 'fs';
6
+ import { fileURLToPath } from 'url';
7
+ import { bold, red } from 'colorette';
8
+ import { intro, outro, spinner } from '@clack/prompts';
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
+ });
16
+ }
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
+ });
23
+ }
24
+ async function doSync() {
25
+ const s = startPrompts('Processing', 'Sync started');
26
+ return await execFile(getFilePath('sync.sh'), (stdout) => {
27
+ stopPrompt(s, 'Completed');
28
+ return stdout;
29
+ });
30
+ }
31
+ function getBuildName() {
32
+ const defaultBuild = 'utah';
33
+ try {
34
+ const workspace = getWorkspaceFile();
35
+ const app = workspace.ACTIVE_APPLICATION;
36
+ const build = workspace.ALL_APPLICATIONS[app].BUILD_NAME;
37
+ return Object.entries(build).length !== 0
38
+ ? build.toLowerCase()
39
+ : defaultBuild;
40
+ }
41
+ catch (e) {
42
+ return defaultBuild;
43
+ }
44
+ }
45
+ function getErrorMsg() {
46
+ var url = `https://docs.servicenow.com/bundle/${getBuildName()}-application-development/page/build/applications/task/create-project.html`;
47
+ var msg = `No active application detected. Please create a project with the ServiceNow Extension for VS Code.\n\n${url}`;
48
+ return console.error(bold(red(msg)));
49
+ }
50
+ function getFilePath(file, dir = 'scripts') {
51
+ const __filename = fileURLToPath(import.meta.url);
52
+ const __dirname = path.dirname(__filename);
53
+ return `${path.join(__dirname, `../${dir}`)}/${file}`;
54
+ }
55
+ function getOption(program) {
56
+ program.parse(process.argv).opts();
57
+ const option = Object.keys(program.opts()).toString();
58
+ const options = {
59
+ build: () => {
60
+ doBuild();
61
+ },
62
+ compile: () => {
63
+ doCompile();
64
+ },
65
+ sync: () => {
66
+ doSync();
67
+ },
68
+ default: () => {
69
+ program.help();
70
+ }
71
+ };
72
+ return (options[option] || options['default'])();
73
+ }
74
+ async function getPackageInfo() {
75
+ return JSON.parse(readFileSync(getFilePath('package.json', '.')).toString());
76
+ }
77
+ function getWorkspaceFile() {
78
+ return JSON.parse(readFileSync('./system/sn-workspace.json').toString())
79
+ .ACTIVE_APPLICATION;
80
+ }
81
+ async function hasApplication() {
82
+ try {
83
+ const workspace = await getWorkspaceFile();
84
+ return Object.entries(workspace).length === 0 ? getErrorMsg() : true;
85
+ }
86
+ catch (e) {
87
+ getErrorMsg();
88
+ return process.exit(1);
89
+ }
90
+ }
91
+ (async () => {
92
+ return init();
93
+ })();
94
+ async function init() {
95
+ const program = new Command();
96
+ const info = await getPackageInfo();
97
+ program.description(info.description);
98
+ program.version(info.version);
99
+ program.option('-b, --build', 'build project utility files & package dependencies');
100
+ program.option('-c, --compile', 'compile TypeScript files to JavaScript & move to src');
101
+ program.option('-s, --sync', 'sync new instance-based src files to the ts directory');
102
+ return hasApplication() && getOption(program);
103
+ }
104
+ function introPrompt(msg) {
105
+ return intro(msg);
106
+ }
107
+ async function runInstall() {
108
+ const s = startPrompts('Installing packages', null);
109
+ return await execFile(getFilePath('install.sh'), (stdout) => {
110
+ stopPrompt(s, 'Packages installed');
111
+ outro('Completed');
112
+ return stdout;
113
+ });
114
+ }
115
+ async function runSync() {
116
+ return await execFile(getFilePath('sync.sh'), (stdout) => {
117
+ runInstall();
118
+ return stdout;
119
+ });
120
+ }
121
+ function startPrompts(start, intro) {
122
+ intro && introPrompt(intro);
123
+ const s = spinner();
124
+ s.start(start);
125
+ return s;
126
+ }
127
+ function stopPrompt(spinner, msg) {
128
+ return spinner.stop(msg);
129
+ }
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "sn-typescript-util",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "A TypeScript utility for ServiceNow developers using VS Code",
5
5
  "bin": {
6
- "snts": "bin/snts.ts"
6
+ "snts": "bin/snts.js"
7
7
  },
8
8
  "keywords": [
9
9
  "ServiceNow",
@@ -16,16 +16,16 @@
16
16
  "type": "git",
17
17
  "url": "https://github.com/stevengregory/sn-typescript-util.git"
18
18
  },
19
+ "type": "module",
19
20
  "dependencies": {
20
21
  "@clack/prompts": "^0.6.3",
21
- "@types/node": "^18.15.11",
22
+ "@types/node": "^20.4.2",
22
23
  "@types/servicenow": "^10.0.1",
23
- "colorette": "^2.0.19",
24
- "commander": "^10.0.0",
25
- "nodemon": "^2.0.22",
24
+ "colorette": "^2.0.20",
25
+ "commander": "^11.0.0",
26
+ "nodemon": "^3.0.1",
26
27
  "npm-add-script": "^1.1.0",
27
- "prettier": "^2.8.7",
28
- "ts-node": "^10.9.1",
29
- "typescript": "^5.0.4"
28
+ "prettier": "^3.0.0",
29
+ "typescript": "^5.1.6"
30
30
  }
31
31
  }
package/src/snts.ts ADDED
@@ -0,0 +1,154 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { Command } from 'commander';
4
+ import { execFile } from 'node:child_process';
5
+ import path from 'path';
6
+ import { readFileSync } from 'fs';
7
+ import { fileURLToPath } from 'url';
8
+ import { bold, red } from 'colorette';
9
+ import { intro, outro, spinner } from '@clack/prompts';
10
+
11
+ async function doBuild() {
12
+ const s = startPrompts('Installing configs', 'Build started');
13
+ return await execFile(getFilePath('init.rb'), (stdout) => {
14
+ stopPrompt(s, 'Configs installed');
15
+ runSync();
16
+ return stdout;
17
+ });
18
+ }
19
+
20
+ async function doCompile() {
21
+ const s = startPrompts('Processing', 'Compile started');
22
+ return await execFile(getFilePath('compile.rb'), (stdout) => {
23
+ stopPrompt(s, 'Completed');
24
+ return stdout;
25
+ });
26
+ }
27
+
28
+ async function doSync() {
29
+ const s = startPrompts('Processing', 'Sync started');
30
+ return await execFile(getFilePath('sync.sh'), (stdout: any) => {
31
+ stopPrompt(s, 'Completed');
32
+ return stdout;
33
+ });
34
+ }
35
+
36
+ function getBuildName() {
37
+ const defaultBuild: string = 'utah';
38
+ try {
39
+ const workspace = getWorkspaceFile();
40
+ const app: string = workspace.ACTIVE_APPLICATION;
41
+ const build: string = workspace.ALL_APPLICATIONS[app].BUILD_NAME;
42
+ return Object.entries(build).length !== 0
43
+ ? build.toLowerCase()
44
+ : defaultBuild;
45
+ } catch (e) {
46
+ return defaultBuild;
47
+ }
48
+ }
49
+
50
+ function getErrorMsg() {
51
+ var url: string = `https://docs.servicenow.com/bundle/${getBuildName()}-application-development/page/build/applications/task/create-project.html`;
52
+ var msg: string = `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)));
54
+ }
55
+
56
+ function getFilePath(file: string, dir: string = 'scripts') {
57
+ const __filename = fileURLToPath(import.meta.url);
58
+ const __dirname = path.dirname(__filename);
59
+ return `${path.join(__dirname, `../${dir}`)}/${file}`;
60
+ }
61
+
62
+ function getOption(program: any) {
63
+ program.parse(process.argv).opts();
64
+ const option = Object.keys(program.opts()).toString();
65
+ const options = {
66
+ build: () => {
67
+ doBuild();
68
+ },
69
+ compile: () => {
70
+ doCompile();
71
+ },
72
+ sync: () => {
73
+ doSync();
74
+ },
75
+ default: () => {
76
+ program.help();
77
+ }
78
+ };
79
+ return (options[option] || options['default'])();
80
+ }
81
+
82
+ async function getPackageInfo() {
83
+ return JSON.parse(readFileSync(getFilePath('package.json', '.')).toString());
84
+ }
85
+
86
+ function getWorkspaceFile() {
87
+ return JSON.parse(readFileSync('./system/sn-workspace.json').toString())
88
+ .ACTIVE_APPLICATION;
89
+ }
90
+
91
+ async function hasApplication() {
92
+ try {
93
+ const workspace = await getWorkspaceFile();
94
+ return Object.entries(workspace).length === 0 ? getErrorMsg() : true;
95
+ } catch (e) {
96
+ getErrorMsg();
97
+ return process.exit(1);
98
+ }
99
+ }
100
+
101
+ (async () => {
102
+ return init();
103
+ })();
104
+
105
+ async function init() {
106
+ const program = new Command();
107
+ const info = await getPackageInfo();
108
+ program.description(info.description);
109
+ program.version(info.version);
110
+ program.option(
111
+ '-b, --build',
112
+ 'build project utility files & package dependencies'
113
+ );
114
+ program.option(
115
+ '-c, --compile',
116
+ 'compile TypeScript files to JavaScript & move to src'
117
+ );
118
+ program.option(
119
+ '-s, --sync',
120
+ 'sync new instance-based src files to the ts directory'
121
+ );
122
+ return hasApplication() && getOption(program);
123
+ }
124
+
125
+ function introPrompt(msg: string) {
126
+ return intro(msg);
127
+ }
128
+
129
+ async function runInstall() {
130
+ const s = startPrompts('Installing packages', null);
131
+ return await execFile(getFilePath('install.sh'), (stdout) => {
132
+ stopPrompt(s, 'Packages installed');
133
+ outro('Completed');
134
+ return stdout;
135
+ });
136
+ }
137
+
138
+ async function runSync() {
139
+ return await execFile(getFilePath('sync.sh'), (stdout) => {
140
+ runInstall();
141
+ return stdout;
142
+ });
143
+ }
144
+
145
+ function startPrompts(start: string, intro: string) {
146
+ intro && introPrompt(intro);
147
+ const s = spinner();
148
+ s.start(start);
149
+ return s;
150
+ }
151
+
152
+ function stopPrompt(spinner: any, msg: string) {
153
+ return spinner.stop(msg);
154
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "NodeNext",
5
+ "esModuleInterop": true,
6
+ "outDir": "bin",
7
+ "resolveJsonModule": true,
8
+ "rootDir": "src",
9
+ "skipLibCheck": true
10
+ },
11
+ "include": ["src"]
12
+ }
package/bin/snts.ts DELETED
@@ -1,147 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const childProcess = require('child_process');
4
- const fs = require('fs');
5
- const path = require('path');
6
- const util = require('util');
7
- const exec = util.promisify(childProcess.exec);
8
- const { description, version } = require('./../package.json');
9
- const { program } = require('commander');
10
- const { bold, cyan, red } = require('colorette');
11
- const { cancel, intro, outro, spinner } = require('@clack/prompts');
12
-
13
- async function doBuild() {
14
- const s = startPrompts('Installing configs', 'Build started');
15
- return await exec(getFilePath('init.rb'), (stdout) => {
16
- stopPrompt(s, 'Configs installed');
17
- runSync();
18
- return stdout;
19
- });
20
- }
21
-
22
- async function doCompile() {
23
- const s = startPrompts('Processing', 'Compile started');
24
- return await exec(getFilePath('compile.rb'), (stdout) => {
25
- stopPrompt(s, 'Completed');
26
- return stdout;
27
- });
28
- }
29
-
30
- async function doSync() {
31
- const s = startPrompts('Processing', 'Sync started');
32
- return await exec(getFilePath('sync.sh'), (stdout) => {
33
- stopPrompt(s, 'Completed');
34
- return stdout;
35
- });
36
- }
37
-
38
- function getBuildName() {
39
- const defaultBuild = 'utah';
40
- try {
41
- const workspace = JSON.parse(getWorkspaceConfig());
42
- const app = workspace.ACTIVE_APPLICATION;
43
- const build = workspace.ALL_APPLICATIONS[app].BUILD_NAME;
44
- return Object.entries(build).length !== 0
45
- ? build.toLowerCase()
46
- : defaultBuild;
47
- } catch (e) {
48
- return defaultBuild;
49
- }
50
- }
51
-
52
- function getErrorMsg() {
53
- var url = `https://docs.servicenow.com/bundle/${getBuildName()}-application-development/page/build/applications/task/create-project.html`;
54
- var msg = `No active application detected. Please create a project with the ServiceNow Extension for VS Code.\n\n${url}`;
55
- return console.error(bold(red(msg)));
56
- }
57
-
58
- function getFilePath(file) {
59
- return `${path.join(__dirname, '../scripts')}/${file}`;
60
- }
61
-
62
- function getOption(opts) {
63
- const option = Object.keys(opts).toString();
64
- const options = {
65
- build: () => {
66
- doBuild();
67
- },
68
- compile: () => {
69
- doCompile();
70
- },
71
- sync: () => {
72
- doSync();
73
- },
74
- default: () => {
75
- program.help();
76
- }
77
- };
78
- return (options[option] || options['default'])();
79
- }
80
-
81
- function getWorkspaceConfig() {
82
- return fs.readFileSync('./system/sn-workspace.json');
83
- }
84
-
85
- function hasApplication() {
86
- try {
87
- const app = JSON.parse(getWorkspaceConfig()).ACTIVE_APPLICATION;
88
- return Object.entries(app).length === 0 ? getErrorMsg() : true;
89
- } catch (e) {
90
- getErrorMsg();
91
- return process.exit(1);
92
- }
93
- }
94
-
95
- (() => {
96
- return init();
97
- })();
98
-
99
- function init() {
100
- program.description(description);
101
- program.version(version);
102
- program.option(
103
- '-b, --build',
104
- 'build project utility files & package dependencies'
105
- );
106
- program.option(
107
- '-c, --compile',
108
- 'compile TypeScript files to JavaScript & move to src'
109
- );
110
- program.option(
111
- '-s, --sync',
112
- 'sync new instance-based src files to the ts directory'
113
- );
114
- program.parse(process.argv).opts();
115
- return hasApplication() && getOption(program.opts());
116
- }
117
-
118
- function introPrompt(msg) {
119
- return intro(msg);
120
- }
121
-
122
- async function runInstall() {
123
- const s = startPrompts('Installing packages', null);
124
- return await exec(getFilePath('install.sh'), (stdout) => {
125
- stopPrompt(s, 'Packages installed');
126
- outro('Completed');
127
- return stdout;
128
- });
129
- }
130
-
131
- async function runSync() {
132
- return await exec(getFilePath('sync.sh'), (stdout) => {
133
- runInstall();
134
- return stdout;
135
- });
136
- }
137
-
138
- function startPrompts(start, intro) {
139
- intro && introPrompt(intro);
140
- const s = spinner();
141
- s.start(start);
142
- return s;
143
- }
144
-
145
- function stopPrompt(spinner, msg) {
146
- return spinner.stop(msg);
147
- }