sn-typescript-util 1.2.1 → 1.2.3
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 +31 -29
- package/package.json +1 -1
- package/src/snts.ts +33 -30
- package/src/workspace.ts +4 -0
- package/tsconfig.json +0 -1
package/bin/snts.js
CHANGED
|
@@ -21,6 +21,25 @@ async function doCompile() {
|
|
|
21
21
|
return stdout;
|
|
22
22
|
});
|
|
23
23
|
}
|
|
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 ((hasApplication() && options[option]) || options['default'])();
|
|
42
|
+
}
|
|
24
43
|
async function doSync() {
|
|
25
44
|
const s = startPrompts('Processing', 'Sync started');
|
|
26
45
|
return await execFile(getFilePath('sync.sh'), (stdout) => {
|
|
@@ -31,7 +50,7 @@ async function doSync() {
|
|
|
31
50
|
function getBuildName() {
|
|
32
51
|
const defaultBuild = 'utah';
|
|
33
52
|
try {
|
|
34
|
-
const workspace =
|
|
53
|
+
const workspace = getWorkspace();
|
|
35
54
|
const app = workspace.ACTIVE_APPLICATION;
|
|
36
55
|
const build = workspace.ALL_APPLICATIONS[app].BUILD_NAME;
|
|
37
56
|
return Object.entries(build).length !== 0
|
|
@@ -48,40 +67,21 @@ function getErrorMsg() {
|
|
|
48
67
|
return console.error(bold(red(msg)));
|
|
49
68
|
}
|
|
50
69
|
function getFilePath(file, dir = 'scripts') {
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
return `${path.join(
|
|
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'])();
|
|
70
|
+
const fileName = fileURLToPath(import.meta.url);
|
|
71
|
+
const dirName = path.dirname(fileName);
|
|
72
|
+
return `${path.join(dirName, `../${dir}`)}/${file}`;
|
|
73
73
|
}
|
|
74
74
|
async function getPackageInfo() {
|
|
75
75
|
return JSON.parse(readFileSync(getFilePath('package.json', '.')).toString());
|
|
76
76
|
}
|
|
77
|
-
function
|
|
78
|
-
return JSON.parse(readFileSync('./system/sn-workspace.json').toString())
|
|
79
|
-
.ACTIVE_APPLICATION;
|
|
77
|
+
function getWorkspace() {
|
|
78
|
+
return JSON.parse(readFileSync('./system/sn-workspace.json').toString());
|
|
80
79
|
}
|
|
81
80
|
async function hasApplication() {
|
|
82
81
|
try {
|
|
83
|
-
const workspace = await
|
|
84
|
-
|
|
82
|
+
const workspace = await getWorkspace();
|
|
83
|
+
var app = workspace.ACTIVE_APPLICATION;
|
|
84
|
+
return Object.entries(app).length === 0 ? getErrorMsg() : true;
|
|
85
85
|
}
|
|
86
86
|
catch (e) {
|
|
87
87
|
getErrorMsg();
|
|
@@ -99,7 +99,7 @@ async function init() {
|
|
|
99
99
|
program.option('-b, --build', 'build project utility files & package dependencies');
|
|
100
100
|
program.option('-c, --compile', 'compile TypeScript files to JavaScript & move to src');
|
|
101
101
|
program.option('-s, --sync', 'sync new instance-based src files to the ts directory');
|
|
102
|
-
return
|
|
102
|
+
return doOptions(program);
|
|
103
103
|
}
|
|
104
104
|
function introPrompt(msg) {
|
|
105
105
|
return intro(msg);
|
|
@@ -113,7 +113,9 @@ async function runInstall() {
|
|
|
113
113
|
});
|
|
114
114
|
}
|
|
115
115
|
async function runSync() {
|
|
116
|
+
const s = startPrompts('Syncing', null);
|
|
116
117
|
return await execFile(getFilePath('sync.sh'), (stdout) => {
|
|
118
|
+
stopPrompt(s, 'Sync completed');
|
|
117
119
|
runInstall();
|
|
118
120
|
return stdout;
|
|
119
121
|
});
|
package/package.json
CHANGED
package/src/snts.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { readFileSync } from 'fs';
|
|
|
7
7
|
import { fileURLToPath } from 'url';
|
|
8
8
|
import { bold, red } from 'colorette';
|
|
9
9
|
import { intro, outro, spinner } from '@clack/prompts';
|
|
10
|
+
import { Workspace } from './workspace.js';
|
|
10
11
|
|
|
11
12
|
async function doBuild() {
|
|
12
13
|
const s = startPrompts('Installing configs', 'Build started');
|
|
@@ -25,6 +26,26 @@ async function doCompile() {
|
|
|
25
26
|
});
|
|
26
27
|
}
|
|
27
28
|
|
|
29
|
+
function doOptions(program: any) {
|
|
30
|
+
program.parse(process.argv).opts();
|
|
31
|
+
const option = Object.keys(program.opts()).toString();
|
|
32
|
+
const options = {
|
|
33
|
+
build: () => {
|
|
34
|
+
doBuild();
|
|
35
|
+
},
|
|
36
|
+
compile: () => {
|
|
37
|
+
doCompile();
|
|
38
|
+
},
|
|
39
|
+
sync: () => {
|
|
40
|
+
doSync();
|
|
41
|
+
},
|
|
42
|
+
default: () => {
|
|
43
|
+
program.help();
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
return ((hasApplication() && options[option]) || options['default'])();
|
|
47
|
+
}
|
|
48
|
+
|
|
28
49
|
async function doSync() {
|
|
29
50
|
const s = startPrompts('Processing', 'Sync started');
|
|
30
51
|
return await execFile(getFilePath('sync.sh'), (stdout: any) => {
|
|
@@ -36,7 +57,7 @@ async function doSync() {
|
|
|
36
57
|
function getBuildName() {
|
|
37
58
|
const defaultBuild: string = 'utah';
|
|
38
59
|
try {
|
|
39
|
-
const workspace =
|
|
60
|
+
const workspace: Workspace = getWorkspace();
|
|
40
61
|
const app: string = workspace.ACTIVE_APPLICATION;
|
|
41
62
|
const build: string = workspace.ALL_APPLICATIONS[app].BUILD_NAME;
|
|
42
63
|
return Object.entries(build).length !== 0
|
|
@@ -54,44 +75,24 @@ function getErrorMsg() {
|
|
|
54
75
|
}
|
|
55
76
|
|
|
56
77
|
function getFilePath(file: string, dir: string = 'scripts') {
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
return `${path.join(
|
|
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'])();
|
|
78
|
+
const fileName = fileURLToPath(import.meta.url);
|
|
79
|
+
const dirName = path.dirname(fileName);
|
|
80
|
+
return `${path.join(dirName, `../${dir}`)}/${file}`;
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
async function getPackageInfo() {
|
|
83
84
|
return JSON.parse(readFileSync(getFilePath('package.json', '.')).toString());
|
|
84
85
|
}
|
|
85
86
|
|
|
86
|
-
function
|
|
87
|
-
return JSON.parse(readFileSync('./system/sn-workspace.json').toString())
|
|
88
|
-
.ACTIVE_APPLICATION;
|
|
87
|
+
function getWorkspace() {
|
|
88
|
+
return JSON.parse(readFileSync('./system/sn-workspace.json').toString());
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
async function hasApplication() {
|
|
92
92
|
try {
|
|
93
|
-
const workspace = await
|
|
94
|
-
|
|
93
|
+
const workspace: Workspace = await getWorkspace();
|
|
94
|
+
var app: string = workspace.ACTIVE_APPLICATION;
|
|
95
|
+
return Object.entries(app).length === 0 ? getErrorMsg() : true;
|
|
95
96
|
} catch (e) {
|
|
96
97
|
getErrorMsg();
|
|
97
98
|
return process.exit(1);
|
|
@@ -119,7 +120,7 @@ async function init() {
|
|
|
119
120
|
'-s, --sync',
|
|
120
121
|
'sync new instance-based src files to the ts directory'
|
|
121
122
|
);
|
|
122
|
-
return
|
|
123
|
+
return doOptions(program);
|
|
123
124
|
}
|
|
124
125
|
|
|
125
126
|
function introPrompt(msg: string) {
|
|
@@ -136,7 +137,9 @@ async function runInstall() {
|
|
|
136
137
|
}
|
|
137
138
|
|
|
138
139
|
async function runSync() {
|
|
140
|
+
const s = startPrompts('Syncing', null);
|
|
139
141
|
return await execFile(getFilePath('sync.sh'), (stdout) => {
|
|
142
|
+
stopPrompt(s, 'Sync completed');
|
|
140
143
|
runInstall();
|
|
141
144
|
return stdout;
|
|
142
145
|
});
|
package/src/workspace.ts
ADDED