@steambrew/ttc 1.2.2 → 1.4.2
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/.prettierrc +9 -0
- package/Compiler.ts +226 -291
- package/Linter.ts +43 -43
- package/Logger.ts +48 -48
- package/Parameters.ts +71 -71
- package/PluginSetup.ts +259 -0
- package/VersionMon.ts +27 -27
- package/dist/index.js +230 -104
- package/index.ts +64 -64
- package/package.json +38 -40
- package/rollup.config.js +31 -31
- package/tsconfig.json +23 -23
package/.prettierrc
ADDED
package/Compiler.ts
CHANGED
|
@@ -1,291 +1,226 @@
|
|
|
1
|
-
import { OutputOptions, RollupOptions, rollup } from
|
|
2
|
-
import json from
|
|
3
|
-
import commonjs from
|
|
4
|
-
import replace from
|
|
5
|
-
import typescript from
|
|
6
|
-
import resolve from
|
|
7
|
-
import terser from
|
|
8
|
-
import babel from
|
|
9
|
-
|
|
10
|
-
import chalk from
|
|
11
|
-
import { Logger } from
|
|
12
|
-
import fs from
|
|
13
|
-
|
|
14
|
-
import injectProcessEnv from
|
|
15
|
-
import dotenv from
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
return id === "@steambrew/client" || id === "react" || id === "react-dom";
|
|
228
|
-
},
|
|
229
|
-
output: {
|
|
230
|
-
name: "millennium_main",
|
|
231
|
-
file: ".millennium/Dist/index.js",
|
|
232
|
-
globals: {
|
|
233
|
-
react: "window.SP_REACT",
|
|
234
|
-
"react-dom": "window.SP_REACTDOM",
|
|
235
|
-
"@steambrew/client": "window.MILLENNIUM_API",
|
|
236
|
-
},
|
|
237
|
-
exports: "named",
|
|
238
|
-
format: "iife",
|
|
239
|
-
},
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
Logger.Info("Starting build; this may take a few moments...");
|
|
243
|
-
|
|
244
|
-
try {
|
|
245
|
-
await (
|
|
246
|
-
await rollup(frontendRollupConfig)
|
|
247
|
-
).write(frontendRollupConfig.output as OutputOptions);
|
|
248
|
-
|
|
249
|
-
if (fs.existsSync(`./webkit/index.tsx`)) {
|
|
250
|
-
Logger.Info("Compiling webkit module...");
|
|
251
|
-
|
|
252
|
-
const webkitRollupConfig: RollupOptions = {
|
|
253
|
-
input: `./webkit/index.tsx`,
|
|
254
|
-
plugins: GetWebkitPluginComponents(props),
|
|
255
|
-
context: "window",
|
|
256
|
-
external: (id) => {
|
|
257
|
-
if (id === "@steambrew/client") {
|
|
258
|
-
Logger.Error(
|
|
259
|
-
"The @steambrew/client module should not be included in the webkit module, use @steambrew/webkit instead. Please remove it from the webkit module and try again."
|
|
260
|
-
);
|
|
261
|
-
process.exit(1);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
return id === "@steambrew/webkit";
|
|
265
|
-
},
|
|
266
|
-
output: {
|
|
267
|
-
name: "millennium_main",
|
|
268
|
-
file: ".millennium/Dist/webkit.js",
|
|
269
|
-
exports: "named",
|
|
270
|
-
format: "iife",
|
|
271
|
-
globals: {
|
|
272
|
-
"@steambrew/webkit": "window.MILLENNIUM_API",
|
|
273
|
-
},
|
|
274
|
-
},
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
await (
|
|
278
|
-
await rollup(webkitRollupConfig)
|
|
279
|
-
).write(webkitRollupConfig.output as OutputOptions);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
Logger.Info(
|
|
283
|
-
"Build succeeded!",
|
|
284
|
-
Number((performance.now() - global.PerfStartTime).toFixed(3)),
|
|
285
|
-
"ms elapsed."
|
|
286
|
-
);
|
|
287
|
-
} catch (exception) {
|
|
288
|
-
Logger.Error("Build failed!", exception);
|
|
289
|
-
process.exit(1);
|
|
290
|
-
}
|
|
291
|
-
};
|
|
1
|
+
import { OutputOptions, RollupOptions, rollup } from 'rollup';
|
|
2
|
+
import json from '@rollup/plugin-json';
|
|
3
|
+
import commonjs from '@rollup/plugin-commonjs';
|
|
4
|
+
import replace from '@rollup/plugin-replace';
|
|
5
|
+
import typescript from '@rollup/plugin-typescript';
|
|
6
|
+
import resolve from '@rollup/plugin-node-resolve';
|
|
7
|
+
import terser from '@rollup/plugin-terser';
|
|
8
|
+
import babel from '@rollup/plugin-babel';
|
|
9
|
+
|
|
10
|
+
import chalk from 'chalk';
|
|
11
|
+
import { Logger } from './Logger';
|
|
12
|
+
import fs from 'fs';
|
|
13
|
+
|
|
14
|
+
import injectProcessEnv from 'rollup-plugin-inject-process-env';
|
|
15
|
+
import dotenv from 'dotenv';
|
|
16
|
+
import { ExecutePluginModule, InitializePlugins } from './PluginSetup';
|
|
17
|
+
|
|
18
|
+
const envConfig = dotenv.config().parsed || {};
|
|
19
|
+
|
|
20
|
+
if (envConfig) {
|
|
21
|
+
Logger.Info('Injecting environment variables...');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const envVars = Object.keys(envConfig).reduce((acc: any, key) => {
|
|
25
|
+
acc[key] = envConfig[key];
|
|
26
|
+
return acc;
|
|
27
|
+
}, {});
|
|
28
|
+
|
|
29
|
+
declare global {
|
|
30
|
+
interface Window {
|
|
31
|
+
PLUGIN_LIST: any;
|
|
32
|
+
MILLENNIUM_PLUGIN_SETTINGS_STORE: any;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
declare const pluginName: string, millennium_main: any, MILLENNIUM_BACKEND_IPC: any, MILLENNIUM_IS_CLIENT_MODULE: boolean;
|
|
37
|
+
|
|
38
|
+
enum ComponentType {
|
|
39
|
+
Plugin,
|
|
40
|
+
Webkit,
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface TranspilerProps {
|
|
44
|
+
bTersePlugin?: boolean;
|
|
45
|
+
strPluginInternalName: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const WrappedCallServerMethod = 'const __call_server_method__ = (methodName, kwargs) => Millennium.callServerMethod(pluginName, methodName, kwargs)';
|
|
49
|
+
const WrappedCallable = 'const __wrapped_callable__ = (route) => MILLENNIUM_API.callable(__call_server_method__, route)';
|
|
50
|
+
|
|
51
|
+
const ConstructFunctions = (parts: any) => {
|
|
52
|
+
return parts.join('\n');
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
function generate(code: string) {
|
|
56
|
+
/** Wrap it in a proxy */
|
|
57
|
+
return `let PluginEntryPointMain = function() { ${code} return millennium_main; };`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function InsertMillennium(type: ComponentType, props: TranspilerProps) {
|
|
61
|
+
const generateBundle = (_: unknown, bundle: any) => {
|
|
62
|
+
for (const fileName in bundle) {
|
|
63
|
+
if (bundle[fileName].type != 'chunk') {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
Logger.Info('Injecting Millennium shims into ' + ComponentType[type] + ' module... ' + chalk.green.bold('okay'));
|
|
68
|
+
|
|
69
|
+
bundle[fileName].code = ConstructFunctions([
|
|
70
|
+
`const MILLENNIUM_IS_CLIENT_MODULE = ${type === ComponentType.Plugin ? 'true' : 'false'};`,
|
|
71
|
+
`const pluginName = "${props.strPluginInternalName}";`,
|
|
72
|
+
InitializePlugins.toString(),
|
|
73
|
+
InitializePlugins.name + '()',
|
|
74
|
+
WrappedCallServerMethod,
|
|
75
|
+
WrappedCallable,
|
|
76
|
+
generate(bundle[fileName].code),
|
|
77
|
+
ExecutePluginModule.toString(),
|
|
78
|
+
ExecutePluginModule.name + '()',
|
|
79
|
+
]);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
return { name: String(), generateBundle };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function GetPluginComponents(props: TranspilerProps) {
|
|
87
|
+
let tsConfigPath = `./${GetFrontEndDirectory()}/tsconfig.json`;
|
|
88
|
+
|
|
89
|
+
if (!fs.existsSync(tsConfigPath)) {
|
|
90
|
+
tsConfigPath = './tsconfig.json';
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const pluginList = [
|
|
94
|
+
InsertMillennium(ComponentType.Plugin, props),
|
|
95
|
+
typescript({
|
|
96
|
+
tsconfig: tsConfigPath,
|
|
97
|
+
}),
|
|
98
|
+
resolve(),
|
|
99
|
+
commonjs(),
|
|
100
|
+
json(),
|
|
101
|
+
injectProcessEnv(envVars),
|
|
102
|
+
replace({
|
|
103
|
+
delimiters: ['', ''],
|
|
104
|
+
preventAssignment: true,
|
|
105
|
+
'process.env.NODE_ENV': JSON.stringify('production'),
|
|
106
|
+
'Millennium.callServerMethod': `__call_server_method__`,
|
|
107
|
+
'client.callable': `__wrapped_callable__`,
|
|
108
|
+
'client.pluginSelf': 'window.PLUGIN_LIST[pluginName]',
|
|
109
|
+
'client.Millennium.exposeObj(': 'client.Millennium.exposeObj(exports, ',
|
|
110
|
+
'client.BindPluginSettings()': 'client.BindPluginSettings(pluginName)',
|
|
111
|
+
}),
|
|
112
|
+
];
|
|
113
|
+
|
|
114
|
+
if (props.bTersePlugin) {
|
|
115
|
+
pluginList.push(terser());
|
|
116
|
+
}
|
|
117
|
+
return pluginList;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function GetWebkitPluginComponents(props: TranspilerProps) {
|
|
121
|
+
const pluginList = [
|
|
122
|
+
InsertMillennium(ComponentType.Webkit, props),
|
|
123
|
+
typescript({
|
|
124
|
+
tsconfig: './webkit/tsconfig.json',
|
|
125
|
+
}),
|
|
126
|
+
resolve(),
|
|
127
|
+
commonjs(),
|
|
128
|
+
json(),
|
|
129
|
+
injectProcessEnv(envVars),
|
|
130
|
+
replace({
|
|
131
|
+
delimiters: ['', ''],
|
|
132
|
+
preventAssignment: true,
|
|
133
|
+
'Millennium.callServerMethod': `__call_server_method__`,
|
|
134
|
+
'webkit.callable': `__wrapped_callable__`,
|
|
135
|
+
'client.BindPluginSettings()': 'client.BindPluginSettings(pluginName)',
|
|
136
|
+
}),
|
|
137
|
+
babel({
|
|
138
|
+
presets: ['@babel/preset-env', '@babel/preset-react'],
|
|
139
|
+
babelHelpers: 'bundled',
|
|
140
|
+
}),
|
|
141
|
+
];
|
|
142
|
+
|
|
143
|
+
props.bTersePlugin && pluginList.push(terser());
|
|
144
|
+
return pluginList;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const GetFrontEndDirectory = () => {
|
|
148
|
+
const pluginJsonPath = './plugin.json';
|
|
149
|
+
try {
|
|
150
|
+
return JSON.parse(fs.readFileSync(pluginJsonPath, 'utf8'))?.frontend ?? 'frontend';
|
|
151
|
+
} catch (error) {
|
|
152
|
+
return 'frontend';
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
export const TranspilerPluginComponent = async (props: TranspilerProps) => {
|
|
157
|
+
const frontendRollupConfig: RollupOptions = {
|
|
158
|
+
input: `./${GetFrontEndDirectory()}/index.tsx`,
|
|
159
|
+
plugins: GetPluginComponents(props),
|
|
160
|
+
context: 'window',
|
|
161
|
+
external: (id) => {
|
|
162
|
+
if (id === '@steambrew/webkit') {
|
|
163
|
+
Logger.Error(
|
|
164
|
+
'The @steambrew/webkit module should not be included in the frontend module, use @steambrew/client instead. Please remove it from the frontend module and try again.',
|
|
165
|
+
);
|
|
166
|
+
process.exit(1);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return id === '@steambrew/client' || id === 'react' || id === 'react-dom' || id === 'react-dom/client';
|
|
170
|
+
},
|
|
171
|
+
output: {
|
|
172
|
+
name: 'millennium_main',
|
|
173
|
+
file: '.millennium/Dist/index.js',
|
|
174
|
+
globals: {
|
|
175
|
+
react: 'window.SP_REACT',
|
|
176
|
+
'react-dom': 'window.SP_REACTDOM',
|
|
177
|
+
'react-dom/client': 'window.SP_REACTDOM',
|
|
178
|
+
'@steambrew/client': 'window.MILLENNIUM_API',
|
|
179
|
+
},
|
|
180
|
+
exports: 'named',
|
|
181
|
+
format: 'iife',
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
Logger.Info('Starting build; this may take a few moments...');
|
|
186
|
+
|
|
187
|
+
try {
|
|
188
|
+
await (await rollup(frontendRollupConfig)).write(frontendRollupConfig.output as OutputOptions);
|
|
189
|
+
|
|
190
|
+
if (fs.existsSync(`./webkit/index.tsx`)) {
|
|
191
|
+
Logger.Info('Compiling webkit module...');
|
|
192
|
+
|
|
193
|
+
const webkitRollupConfig: RollupOptions = {
|
|
194
|
+
input: `./webkit/index.tsx`,
|
|
195
|
+
plugins: GetWebkitPluginComponents(props),
|
|
196
|
+
context: 'window',
|
|
197
|
+
external: (id) => {
|
|
198
|
+
if (id === '@steambrew/client') {
|
|
199
|
+
Logger.Error(
|
|
200
|
+
'The @steambrew/client module should not be included in the webkit module, use @steambrew/webkit instead. Please remove it from the webkit module and try again.',
|
|
201
|
+
);
|
|
202
|
+
process.exit(1);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return id === '@steambrew/webkit';
|
|
206
|
+
},
|
|
207
|
+
output: {
|
|
208
|
+
name: 'millennium_main',
|
|
209
|
+
file: '.millennium/Dist/webkit.js',
|
|
210
|
+
exports: 'named',
|
|
211
|
+
format: 'iife',
|
|
212
|
+
globals: {
|
|
213
|
+
'@steambrew/webkit': 'window.MILLENNIUM_API',
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
await (await rollup(webkitRollupConfig)).write(webkitRollupConfig.output as OutputOptions);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
Logger.Info('Build succeeded!', Number((performance.now() - global.PerfStartTime).toFixed(3)), 'ms elapsed.');
|
|
222
|
+
} catch (exception) {
|
|
223
|
+
Logger.Error('Build failed!', exception);
|
|
224
|
+
process.exit(1);
|
|
225
|
+
}
|
|
226
|
+
};
|
package/Linter.ts
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import chalk from 'chalk'
|
|
2
|
-
import path from 'path'
|
|
3
|
-
import { existsSync, readFile } from 'fs'
|
|
4
|
-
|
|
5
|
-
export const ValidatePlugin = (target: string): Promise<any> => {
|
|
6
|
-
|
|
7
|
-
return new Promise<any>((resolve, reject) => {
|
|
8
|
-
if (!existsSync(target)) {
|
|
9
|
-
console.error(chalk.red.bold(`\n[-] --target [${target}] `) + chalk.red("is not a valid system path"))
|
|
10
|
-
reject()
|
|
11
|
-
return
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const pluginModule = path.join(target, "plugin.json")
|
|
15
|
-
|
|
16
|
-
if (!existsSync(pluginModule)) {
|
|
17
|
-
console.error(chalk.red.bold(`\n[-] --target [${target}] `) + chalk.red("is not a valid plugin (missing plugin.json)"))
|
|
18
|
-
reject()
|
|
19
|
-
return
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
readFile(pluginModule, 'utf8', (err, data) => {
|
|
23
|
-
if (err) {
|
|
24
|
-
console.error(chalk.red.bold(`\n[-] couldn't read plugin.json from [${pluginModule}]`))
|
|
25
|
-
reject()
|
|
26
|
-
return
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
try {
|
|
30
|
-
if (!("name" in JSON.parse(data))) {
|
|
31
|
-
console.error(chalk.red.bold(`\n[-] target plugin doesn't contain "name" in plugin.json [${pluginModule}]`))
|
|
32
|
-
reject()
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
resolve(JSON.parse(data))
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
catch (parseError) {
|
|
39
|
-
console.error(chalk.red.bold(`\n[-] couldn't parse JSON in plugin.json from [${pluginModule}]`))
|
|
40
|
-
reject()
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
})
|
|
1
|
+
import chalk from 'chalk'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import { existsSync, readFile } from 'fs'
|
|
4
|
+
|
|
5
|
+
export const ValidatePlugin = (target: string): Promise<any> => {
|
|
6
|
+
|
|
7
|
+
return new Promise<any>((resolve, reject) => {
|
|
8
|
+
if (!existsSync(target)) {
|
|
9
|
+
console.error(chalk.red.bold(`\n[-] --target [${target}] `) + chalk.red("is not a valid system path"))
|
|
10
|
+
reject()
|
|
11
|
+
return
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const pluginModule = path.join(target, "plugin.json")
|
|
15
|
+
|
|
16
|
+
if (!existsSync(pluginModule)) {
|
|
17
|
+
console.error(chalk.red.bold(`\n[-] --target [${target}] `) + chalk.red("is not a valid plugin (missing plugin.json)"))
|
|
18
|
+
reject()
|
|
19
|
+
return
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
readFile(pluginModule, 'utf8', (err, data) => {
|
|
23
|
+
if (err) {
|
|
24
|
+
console.error(chalk.red.bold(`\n[-] couldn't read plugin.json from [${pluginModule}]`))
|
|
25
|
+
reject()
|
|
26
|
+
return
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
if (!("name" in JSON.parse(data))) {
|
|
31
|
+
console.error(chalk.red.bold(`\n[-] target plugin doesn't contain "name" in plugin.json [${pluginModule}]`))
|
|
32
|
+
reject()
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
resolve(JSON.parse(data))
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch (parseError) {
|
|
39
|
+
console.error(chalk.red.bold(`\n[-] couldn't parse JSON in plugin.json from [${pluginModule}]`))
|
|
40
|
+
reject()
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
})
|
|
44
44
|
}
|