@vixoniccom/module-packager 2.12.0-dev.0 → 2.12.0-dev.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/dist/electron.js +58 -0
- package/dist/launcher.html +86 -0
- package/dist/main.js +188 -104
- package/dist/webpack.config.js +153 -0
- package/package.json +1 -4
package/dist/electron.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { app, BrowserWindow } from 'electron';
|
|
3
|
+
import remoteMain from '@electron/remote/main/index.js';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
6
|
+
import commandLineArgs from 'command-line-args';
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname = path.dirname(__filename);
|
|
9
|
+
const optionDefinitions = [
|
|
10
|
+
{ name: 'externals', type: String, defaultValue: [], multiple: true },
|
|
11
|
+
{ name: 'src', type: String, defaultValue: path.join(__dirname, 'src') },
|
|
12
|
+
{ name: 'build', type: String, defaultValue: path.join(__dirname, 'build') },
|
|
13
|
+
{ name: 'config', type: String, defaultValue: './webpack.config.js' },
|
|
14
|
+
{ name: 'port', type: Number, defaultValue: 8080 },
|
|
15
|
+
{ name: 'mode', type: String, defaultValue: 'run' }
|
|
16
|
+
];
|
|
17
|
+
const options = commandLineArgs(optionDefinitions);
|
|
18
|
+
if (options.mode === 'watch') {
|
|
19
|
+
(await import('electron-debug')).default({ showDevTools: true });
|
|
20
|
+
}
|
|
21
|
+
remoteMain.initialize();
|
|
22
|
+
let mainWindow = null;
|
|
23
|
+
function createWindow() {
|
|
24
|
+
mainWindow = new BrowserWindow({
|
|
25
|
+
show: false,
|
|
26
|
+
x: 100,
|
|
27
|
+
y: 100,
|
|
28
|
+
width: 1024,
|
|
29
|
+
height: 768,
|
|
30
|
+
webPreferences: {
|
|
31
|
+
nodeIntegrationInSubFrames: true,
|
|
32
|
+
allowRunningInsecureContent: true,
|
|
33
|
+
nodeIntegration: true,
|
|
34
|
+
contextIsolation: false,
|
|
35
|
+
webSecurity: false,
|
|
36
|
+
webviewTag: true
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
remoteMain.enable(mainWindow.webContents);
|
|
40
|
+
const launcherPath = path.join(__dirname, 'launcher.html');
|
|
41
|
+
const launcherURL = `file://${launcherPath}`;
|
|
42
|
+
mainWindow.loadURL(launcherURL);
|
|
43
|
+
// mainWindow.webContents.openDevTools({ mode: 'detach' })
|
|
44
|
+
mainWindow.webContents.once('did-finish-load', () => {
|
|
45
|
+
mainWindow?.show();
|
|
46
|
+
mainWindow?.webContents.send('init', options);
|
|
47
|
+
});
|
|
48
|
+
mainWindow.on('closed', () => (mainWindow = null));
|
|
49
|
+
}
|
|
50
|
+
app.whenReady().then(() => {
|
|
51
|
+
createWindow();
|
|
52
|
+
app.on('activate', () => {
|
|
53
|
+
if (BrowserWindow.getAllWindows().length === 0) {
|
|
54
|
+
createWindow();
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
app.on('window-all-closed', () => app.quit());
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en" xml:lang="en" style="width: 100%; height: 100%; margin: 0; padding: 0;">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8" />
|
|
6
|
+
<title></title>
|
|
7
|
+
</head>
|
|
8
|
+
|
|
9
|
+
<body style="width: 100%; height: 100%; margin: 0; padding: 0;">
|
|
10
|
+
<webview id="webview" style="width: 100%; height: 100%;" partition="persist:webview"></webview>
|
|
11
|
+
|
|
12
|
+
<script>
|
|
13
|
+
const path = require('path')
|
|
14
|
+
let ModuleController;
|
|
15
|
+
try {
|
|
16
|
+
const moduleControllerModule = require('@vixoniccom/module-controller');
|
|
17
|
+
ModuleController = moduleControllerModule.default;
|
|
18
|
+
} catch (err) {
|
|
19
|
+
console.error('[WEBVIEW] NO se pudo cargar ModuleController', err);
|
|
20
|
+
}
|
|
21
|
+
const { ipcRenderer } = require('electron')
|
|
22
|
+
const remote = require('@electron/remote')
|
|
23
|
+
|
|
24
|
+
ipcRenderer.on('init', (event, options) => {
|
|
25
|
+
const webview = document.getElementById('webview')
|
|
26
|
+
const win = remote.getCurrentWindow()
|
|
27
|
+
|
|
28
|
+
webview.setAttribute('nodeintegration', '')
|
|
29
|
+
webview.setAttribute('webpreferences', 'webSecurity=false, allowRunningInsecureContent=true, nodeIntegration=yes, contextIsolation=no')
|
|
30
|
+
|
|
31
|
+
webview.addEventListener('did-finish-load', () => {
|
|
32
|
+
win.show()
|
|
33
|
+
win.focus()
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
const resolvedSrc = options.mode === 'watch'
|
|
37
|
+
? `http://localhost:${options.port}/index.html`
|
|
38
|
+
: `file://${path.join(options.build, 'index.html')}`
|
|
39
|
+
|
|
40
|
+
webview.src = resolvedSrc
|
|
41
|
+
|
|
42
|
+
function getData() {
|
|
43
|
+
const data = {}
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
data.parameters = require(path.join(options.src, '/test/parameters.json')).parameters
|
|
47
|
+
} catch (err) {
|
|
48
|
+
console.log('No parameters:', err.message)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
let escaped = path.join(options.mode === 'watch' ? options.src : options.build, 'test', 'downloads')
|
|
52
|
+
|
|
53
|
+
// Add file:// to watch because in this mode the app will be in a localhost hosted environment.
|
|
54
|
+
if (options.mode === 'watch') escaped = `file://${escaped}`
|
|
55
|
+
escaped = escaped.replace(/\\/g, '/')
|
|
56
|
+
|
|
57
|
+
data.downloadsPath = escaped
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
data.services = require(path.join(options.src, '/test/services.json')).services
|
|
62
|
+
} catch (err) {
|
|
63
|
+
console.log('No services:', err.message)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return data
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function getSchema() {
|
|
70
|
+
try {
|
|
71
|
+
return require(path.join(options.src, '../configuration.json')).schema
|
|
72
|
+
} catch (err) {
|
|
73
|
+
console.log('No schema:', err.message)
|
|
74
|
+
return {}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const data = getData()
|
|
79
|
+
const schema = getSchema()
|
|
80
|
+
|
|
81
|
+
ModuleController.init(win, webview, data, schema, options.mode === 'watch')
|
|
82
|
+
})
|
|
83
|
+
</script>
|
|
84
|
+
</body>
|
|
85
|
+
|
|
86
|
+
</html>
|
package/dist/main.js
CHANGED
|
@@ -4,18 +4,19 @@ import commandLineArgs from 'command-line-args';
|
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import webpack from 'webpack';
|
|
6
6
|
import WebpackDevServer from 'webpack-dev-server';
|
|
7
|
-
import { spawn
|
|
7
|
+
import { spawn } from 'child_process';
|
|
8
8
|
import { fileURLToPath } from 'url';
|
|
9
9
|
import fs from 'fs';
|
|
10
10
|
import archiver from 'archiver';
|
|
11
11
|
import clc from 'cli-color';
|
|
12
12
|
import { Configuration } from '@vixoniccom/modules';
|
|
13
13
|
import tsNode from 'ts-node';
|
|
14
|
+
import { createRequire } from 'module';
|
|
15
|
+
import which from 'which';
|
|
14
16
|
const __filename = fileURLToPath(import.meta.url);
|
|
15
17
|
const __dirname = path.dirname(__filename);
|
|
16
18
|
const electronPath = path.join(__dirname, 'electron.js');
|
|
17
|
-
|
|
18
|
-
// console.log(`VIXONIC PACKAGER: Version ${pjson.version}`)
|
|
19
|
+
const npxPath = which.sync('npx');
|
|
19
20
|
const optionDefinitions = [
|
|
20
21
|
{ name: 'externals', type: String, defaultValue: [], multiple: true },
|
|
21
22
|
{ name: 'target', type: String, defaultValue: 'web' },
|
|
@@ -29,9 +30,92 @@ const optionDefinitions = [
|
|
|
29
30
|
{ name: 'tsOverride', type: Boolean }
|
|
30
31
|
];
|
|
31
32
|
const options = commandLineArgs(optionDefinitions);
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
// Validación de entrada mejorada
|
|
34
|
+
function validateOptions(options) {
|
|
35
|
+
if (options.target !== 'electron-renderer' && options.externals.length > 0) {
|
|
36
|
+
throw new Error(`Can't use external dependencies if target is not electron-renderer.`);
|
|
37
|
+
}
|
|
38
|
+
// Validar puerto
|
|
39
|
+
if (options.port < 1 || options.port > 65535) {
|
|
40
|
+
throw new Error('Port must be between 1 and 65535');
|
|
41
|
+
}
|
|
42
|
+
// Validar modo
|
|
43
|
+
const validModes = ['build', 'watch', 'run', 'generate-configuration', 'validate-configuration'];
|
|
44
|
+
if (!validModes.includes(options.mode)) {
|
|
45
|
+
throw new Error(`Invalid mode. Must be one of: ${validModes.join(', ')}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// Función para sanitizar rutas
|
|
49
|
+
function sanitizePath(inputPath) {
|
|
50
|
+
// Prevenir path traversal
|
|
51
|
+
if (inputPath.includes('..') || inputPath.includes('~')) {
|
|
52
|
+
throw new Error('Invalid path: path traversal detected');
|
|
53
|
+
}
|
|
54
|
+
return path.resolve(inputPath);
|
|
55
|
+
}
|
|
56
|
+
// Función centralizada para crear argumentos de Electron
|
|
57
|
+
function createElectronArgs(mode) {
|
|
58
|
+
return [
|
|
59
|
+
electronPath,
|
|
60
|
+
'--src', sanitizePath(options.src),
|
|
61
|
+
'--build', sanitizePath(options.build),
|
|
62
|
+
'--port', String(options.port),
|
|
63
|
+
'--mode', mode,
|
|
64
|
+
'--config', options.config,
|
|
65
|
+
'--externals', Array.isArray(options.externals) ? options.externals.join(',') : ''
|
|
66
|
+
];
|
|
67
|
+
}
|
|
68
|
+
// Función centralizada para manejar procesos Electron
|
|
69
|
+
function spawnElectronProcess(mode) {
|
|
70
|
+
const args = createElectronArgs(mode);
|
|
71
|
+
const nodeEnv = mode === 'run' ? 'production' : 'development';
|
|
72
|
+
const child = spawn(npxPath, ['electron', ...args], {
|
|
73
|
+
cwd: __dirname,
|
|
74
|
+
env: {
|
|
75
|
+
...process.env,
|
|
76
|
+
NODE_ENV: nodeEnv,
|
|
77
|
+
ELECTRON_DISABLE_SECURITY_WARNINGS: 'true',
|
|
78
|
+
NODE_NO_WARNINGS: '1'
|
|
79
|
+
},
|
|
80
|
+
stdio: 'inherit'
|
|
81
|
+
});
|
|
82
|
+
// Manejo centralizado de logs
|
|
83
|
+
setupChildProcessLogging(child);
|
|
84
|
+
return child;
|
|
34
85
|
}
|
|
86
|
+
// Función para manejar logging de procesos hijo
|
|
87
|
+
function setupChildProcessLogging(child) {
|
|
88
|
+
child.stdout?.on('data', (data) => {
|
|
89
|
+
const output = data.toString();
|
|
90
|
+
if (!shouldFilterLog(output)) {
|
|
91
|
+
process.stdout.write(output);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
child.stderr?.on('data', (data) => {
|
|
95
|
+
const output = data.toString();
|
|
96
|
+
if (!shouldFilterLog(output)) {
|
|
97
|
+
process.stderr.write(output);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
// Función centralizada para compilar webpack
|
|
102
|
+
async function compileWebpack() {
|
|
103
|
+
// CORREGIDO: Usar __dirname para el webpack.config.js del module-packager
|
|
104
|
+
const cfgPath = path.resolve(__dirname, 'webpack.config.js');
|
|
105
|
+
const webpackConfigFactory = (await import(cfgPath)).default;
|
|
106
|
+
const compiler = webpack(webpackConfigFactory(options));
|
|
107
|
+
return new Promise((resolve, reject) => {
|
|
108
|
+
compiler.run((err, stats) => {
|
|
109
|
+
if (err)
|
|
110
|
+
return reject(err);
|
|
111
|
+
if (stats?.hasErrors()) {
|
|
112
|
+
return reject(new Error(stats.toString({ all: false, errors: true, colors: true })));
|
|
113
|
+
}
|
|
114
|
+
compiler.close(closeErr => (closeErr ? reject(closeErr) : resolve()));
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
validateOptions(options);
|
|
35
119
|
if (options.mode === 'build') {
|
|
36
120
|
pack(() => {
|
|
37
121
|
if (options.target === 'electron-renderer') {
|
|
@@ -45,75 +129,59 @@ if (options.mode === 'build') {
|
|
|
45
129
|
});
|
|
46
130
|
}
|
|
47
131
|
else if (options.mode === 'watch') {
|
|
48
|
-
console.log('[DEBUG] Entrando a watch()');
|
|
49
132
|
watch();
|
|
50
133
|
}
|
|
51
134
|
else if (options.mode === 'run') {
|
|
52
135
|
run();
|
|
53
136
|
}
|
|
54
137
|
else if (options.mode === 'generate-configuration') {
|
|
55
|
-
generateConfiguration();
|
|
138
|
+
await generateConfiguration();
|
|
56
139
|
}
|
|
57
140
|
else if (options.mode === 'validate-configuration') {
|
|
58
141
|
validateConfiguration();
|
|
59
142
|
}
|
|
60
|
-
function runElectron() {
|
|
61
|
-
const electronProcess = spawn('npx', [
|
|
62
|
-
'electron',
|
|
63
|
-
electronPath,
|
|
64
|
-
'--src', path.resolve(options.src),
|
|
65
|
-
'--build', path.resolve(options.build),
|
|
66
|
-
'--port', `${options.port}`,
|
|
67
|
-
'--mode', options.mode,
|
|
68
|
-
'--config', options.config,
|
|
69
|
-
'--externals', options.externals.join(',')
|
|
70
|
-
], {
|
|
71
|
-
cwd: __dirname,
|
|
72
|
-
env: { ...process.env, NODE_ENV: 'development' },
|
|
73
|
-
stdio: 'inherit'
|
|
74
|
-
});
|
|
75
|
-
electronProcess.on('close', (code) => {
|
|
76
|
-
console.log(`Electron process exited with code ${code}`);
|
|
77
|
-
if (code !== 0) {
|
|
78
|
-
console.error('Electron process exited with an error.');
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
143
|
async function pack(callback) {
|
|
83
144
|
console.log(clc.blue('Building module...'));
|
|
84
145
|
validateConfiguration();
|
|
85
|
-
const configPath = path.resolve(__dirname,
|
|
146
|
+
const configPath = path.resolve(__dirname, options.config);
|
|
147
|
+
console.log("🚀 ~ pack ~ configPath:", configPath);
|
|
86
148
|
try {
|
|
87
149
|
const webpackConfig = (await import(configPath)).default(options);
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
console.error('Details:', err.details);
|
|
93
|
-
}
|
|
94
|
-
if (err.errors) {
|
|
95
|
-
console.error('TS Errors:', JSON.stringify(err.errors, null, 2));
|
|
96
|
-
}
|
|
97
|
-
throw err;
|
|
150
|
+
function handleWebpackError(err) {
|
|
151
|
+
console.error('Build error:', err);
|
|
152
|
+
if (err.details) {
|
|
153
|
+
console.error('Details:', err.details);
|
|
98
154
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
155
|
+
if (err.errors) {
|
|
156
|
+
console.error('TS Errors:', JSON.stringify(err.errors, null, 2));
|
|
157
|
+
}
|
|
158
|
+
throw err;
|
|
159
|
+
}
|
|
160
|
+
function handleWebpackStats(stats, callback) {
|
|
161
|
+
if (stats.hasErrors()) {
|
|
162
|
+
const info = stats.toJson('errors-only');
|
|
163
|
+
console.error(clc.red('Webpack errors:'));
|
|
164
|
+
if (info.errors?.length) {
|
|
165
|
+
info.errors.forEach((e) => {
|
|
166
|
+
console.error(clc.red(typeof e === 'object' ? JSON.stringify(e, null, 2) : e));
|
|
167
|
+
});
|
|
112
168
|
}
|
|
113
169
|
else {
|
|
114
|
-
console.
|
|
115
|
-
callback && callback(null);
|
|
170
|
+
console.error(clc.red(JSON.stringify(info, null, 2)));
|
|
116
171
|
}
|
|
172
|
+
callback?.(stats);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
console.log(clc.green('Build OK.'));
|
|
176
|
+
callback?.(null);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
webpack(webpackConfig, function (err, stats) {
|
|
180
|
+
if (err) {
|
|
181
|
+
handleWebpackError(err);
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
handleWebpackStats(stats, callback);
|
|
117
185
|
}
|
|
118
186
|
});
|
|
119
187
|
}
|
|
@@ -124,30 +192,42 @@ async function pack(callback) {
|
|
|
124
192
|
}
|
|
125
193
|
function installExternals(callback) {
|
|
126
194
|
let externals = options.externals.map((x) => {
|
|
127
|
-
|
|
195
|
+
// Validar nombre del paquete
|
|
196
|
+
if (!/^[@a-z0-9-_./]+$/i.test(x)) {
|
|
197
|
+
throw new Error(`Invalid package name: ${x}`);
|
|
198
|
+
}
|
|
199
|
+
const packageJsonPath = sanitizePath(path.resolve(options.src, '..', 'node_modules', x, 'package.json'));
|
|
200
|
+
return `${x}@${JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')).version}`;
|
|
128
201
|
});
|
|
129
202
|
if (externals.length) {
|
|
130
|
-
externals
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
203
|
+
console.log(clc.blue(`Installing externals ${externals.join(', ')}...`));
|
|
204
|
+
const npmPath = which.sync('npm');
|
|
205
|
+
const child = spawn(npmPath, ['install', '--prefix', './', '--production', ...externals], { cwd: sanitizePath(options.build), stdio: 'inherit' });
|
|
206
|
+
child.on('exit', (code) => {
|
|
207
|
+
if (code !== 0) {
|
|
208
|
+
return callback?.(new Error(`npm install failed with code ${code}`));
|
|
209
|
+
}
|
|
137
210
|
console.log(clc.green('Externals installed.'));
|
|
138
|
-
callback
|
|
211
|
+
callback?.(null);
|
|
212
|
+
});
|
|
213
|
+
child.on('error', (err) => {
|
|
214
|
+
callback?.(err);
|
|
139
215
|
});
|
|
140
216
|
}
|
|
141
217
|
else {
|
|
142
|
-
callback
|
|
218
|
+
callback?.(null);
|
|
143
219
|
}
|
|
144
220
|
}
|
|
145
221
|
function zip() {
|
|
146
222
|
console.log(clc.blue('Archiving...'));
|
|
147
|
-
|
|
223
|
+
console.log(clc.blue('Cleaning build...'));
|
|
224
|
+
const buildPath = sanitizePath(options.build);
|
|
225
|
+
const zipPath = path.resolve(buildPath, '../', 'build.zip');
|
|
226
|
+
console.log("[DEBUG] Cleaning build folder", zipPath);
|
|
227
|
+
let output = fs.createWriteStream(zipPath);
|
|
148
228
|
let archive = archiver('zip');
|
|
149
229
|
archive.pipe(output);
|
|
150
|
-
archive.directory(
|
|
230
|
+
archive.directory(buildPath, './');
|
|
151
231
|
archive.finalize();
|
|
152
232
|
output.on('close', function () {
|
|
153
233
|
console.log(clc.green('Generated build.zip.'));
|
|
@@ -158,10 +238,9 @@ function zip() {
|
|
|
158
238
|
clc.move(-2, 0);
|
|
159
239
|
}
|
|
160
240
|
async function watch() {
|
|
161
|
-
|
|
162
|
-
const cfgPath = path.resolve(__dirname, '
|
|
241
|
+
// CORREGIDO: Usar __dirname para el webpack.config.js del module-packager
|
|
242
|
+
const cfgPath = path.resolve(__dirname, 'webpack.config.js');
|
|
163
243
|
const webpackConfigFactory = (await import(cfgPath)).default;
|
|
164
|
-
console.log('[VMP] ▸ webpack config loaded from', cfgPath);
|
|
165
244
|
const compiler = webpack(webpackConfigFactory(options));
|
|
166
245
|
const server = new WebpackDevServer({
|
|
167
246
|
static: false,
|
|
@@ -170,32 +249,15 @@ async function watch() {
|
|
|
170
249
|
historyApiFallback: true
|
|
171
250
|
}, compiler);
|
|
172
251
|
await server.start();
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
'--mode', 'watch',
|
|
180
|
-
'--config', options.config,
|
|
181
|
-
'--externals', options.externals.join(',')
|
|
182
|
-
].join(' ');
|
|
183
|
-
console.log(`[VMP] ▸ ${cmd}`);
|
|
184
|
-
const child = exec(cmd, { cwd: __dirname, env: { ...process.env, NODE_ENV: 'development' } });
|
|
185
|
-
child.stdout?.pipe(process.stdout);
|
|
186
|
-
child.stderr?.pipe(process.stderr);
|
|
187
|
-
}
|
|
188
|
-
function run() {
|
|
189
|
-
pack((err) => {
|
|
190
|
-
if (err) {
|
|
191
|
-
throw err;
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
runElectron();
|
|
195
|
-
}
|
|
196
|
-
});
|
|
252
|
+
spawnElectronProcess('watch');
|
|
253
|
+
}
|
|
254
|
+
async function run() {
|
|
255
|
+
await new Promise((resolve) => pack((err) => (err ? console.log(err) : resolve())));
|
|
256
|
+
await compileWebpack();
|
|
257
|
+
spawnElectronProcess('run');
|
|
197
258
|
}
|
|
198
|
-
function loadConfiguration() {
|
|
259
|
+
async function loadConfiguration() {
|
|
260
|
+
const require = createRequire(import.meta.url);
|
|
199
261
|
tsNode.register({
|
|
200
262
|
compilerOptions: {
|
|
201
263
|
moduleResolution: 'node',
|
|
@@ -204,13 +266,15 @@ function loadConfiguration() {
|
|
|
204
266
|
checkJs: false
|
|
205
267
|
}
|
|
206
268
|
});
|
|
207
|
-
|
|
269
|
+
const configPath = sanitizePath(path.resolve(options.confDefinition, 'index.ts'));
|
|
270
|
+
return require(configPath).configuration;
|
|
208
271
|
}
|
|
209
|
-
function generateConfiguration() {
|
|
272
|
+
async function generateConfiguration() {
|
|
210
273
|
try {
|
|
211
|
-
let configuration = loadConfiguration();
|
|
212
|
-
|
|
213
|
-
fs.writeFileSync(path.resolve(
|
|
274
|
+
let configuration = await loadConfiguration();
|
|
275
|
+
const srcPath = sanitizePath(options.src);
|
|
276
|
+
fs.writeFileSync(path.resolve(srcPath, 'parameters.d.ts'), configuration.declarationFileString);
|
|
277
|
+
fs.writeFileSync(path.resolve(srcPath, '..', 'configuration.json'), JSON.stringify(configuration, undefined, 2));
|
|
214
278
|
console.log(clc.green(`Configuration generated`));
|
|
215
279
|
}
|
|
216
280
|
catch (e) {
|
|
@@ -220,12 +284,13 @@ function generateConfiguration() {
|
|
|
220
284
|
}
|
|
221
285
|
function validateConfiguration() {
|
|
222
286
|
try {
|
|
223
|
-
const
|
|
224
|
-
const
|
|
287
|
+
const srcPath = sanitizePath(options.src);
|
|
288
|
+
const jsonPath = path.resolve(srcPath, '../', 'configuration.json');
|
|
289
|
+
const json = JSON.parse(fs.readFileSync(jsonPath, 'utf8'));
|
|
225
290
|
const conf = Configuration.fromJSON(json);
|
|
226
291
|
if (conf.durationFormula) {
|
|
227
|
-
const valuesPath = path.resolve(
|
|
228
|
-
const values = JSON.parse(fs.readFileSync(valuesPath, 'utf8'));
|
|
292
|
+
const valuesPath = path.resolve(srcPath, 'test', 'parameters.json');
|
|
293
|
+
const values = JSON.parse(fs.readFileSync(valuesPath, 'utf8'));
|
|
229
294
|
console.log('Validate duration');
|
|
230
295
|
console.log('Duration on undefined:', conf.getDuration({}), 'seconds');
|
|
231
296
|
console.log('Duration:', conf.getDuration(values.parameters), 'seconds');
|
|
@@ -237,3 +302,22 @@ function validateConfiguration() {
|
|
|
237
302
|
throw e;
|
|
238
303
|
}
|
|
239
304
|
}
|
|
305
|
+
function shouldFilterLog(output) {
|
|
306
|
+
const filtersToRemove = [
|
|
307
|
+
"'session.getAllExtensions' is deprecated",
|
|
308
|
+
"DeprecationWarning: Compilation.assets will be frozen",
|
|
309
|
+
"BREAKING CHANGE: No more changes should happen to Compilation.assets",
|
|
310
|
+
"[DEP_WEBPACK_COMPILATION_ASSETS] DeprecationWarning",
|
|
311
|
+
"Compilation.assets will be frozen in future",
|
|
312
|
+
"Request Autofill.enable failed",
|
|
313
|
+
"Request Autofill.setAddresses failed",
|
|
314
|
+
"Uncaught (in promise) SyntaxError",
|
|
315
|
+
"wasn't found",
|
|
316
|
+
"asset main.js",
|
|
317
|
+
"runtime modules",
|
|
318
|
+
"orphan modules",
|
|
319
|
+
"cacheable modules",
|
|
320
|
+
"webpack compiled successfully"
|
|
321
|
+
];
|
|
322
|
+
return filtersToRemove.some(filter => output.includes(filter));
|
|
323
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { fileURLToPath } from 'url';
|
|
3
|
+
import { createRequire } from 'module';
|
|
4
|
+
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
5
|
+
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
|
|
6
|
+
import CopyWebpackPlugin from 'copy-webpack-plugin';
|
|
7
|
+
import TerserPlugin from 'terser-webpack-plugin';
|
|
8
|
+
import webpack from 'webpack';
|
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const __dirname = path.dirname(__filename);
|
|
11
|
+
console.log("🚀 ~ __dirname:", __dirname);
|
|
12
|
+
export default (env = {}, argv = {}) => {
|
|
13
|
+
const require = createRequire(import.meta.url);
|
|
14
|
+
const options = {
|
|
15
|
+
src: env.src ?? './src',
|
|
16
|
+
build: env.build ?? './build',
|
|
17
|
+
port: env.port ?? 8080,
|
|
18
|
+
mode: argv.mode ?? 'production',
|
|
19
|
+
};
|
|
20
|
+
const isDev = options.mode === 'watch';
|
|
21
|
+
const buildPath = path.resolve(options.build);
|
|
22
|
+
const controllerHtmlPath = path.resolve(options.src, 'index.html');
|
|
23
|
+
const controllerStaticPath = path.resolve(path.dirname(controllerHtmlPath), '../static');
|
|
24
|
+
const controllerFontsPath = path.resolve(path.dirname(controllerHtmlPath), '../fonts');
|
|
25
|
+
return {
|
|
26
|
+
mode: isDev ? 'development' : 'production',
|
|
27
|
+
target: 'electron-renderer',
|
|
28
|
+
entry: isDev ? [
|
|
29
|
+
`webpack-dev-server/client?http://localhost:${options.port}/`,
|
|
30
|
+
'webpack/hot/dev-server',
|
|
31
|
+
path.resolve(options.src, 'main.ts')
|
|
32
|
+
] : path.resolve(options.src, 'main.ts'),
|
|
33
|
+
output: {
|
|
34
|
+
path: buildPath,
|
|
35
|
+
filename: '[name].js',
|
|
36
|
+
publicPath: isDev ? '/' : './'
|
|
37
|
+
},
|
|
38
|
+
externals: {
|
|
39
|
+
electron: 'commonjs electron',
|
|
40
|
+
'@vixoniccom/module-controller': 'commonjs @vixoniccom/module-controller',
|
|
41
|
+
webpack: 'commonjs webpack',
|
|
42
|
+
'terser-webpack-plugin': 'commonjs terser-webpack-plugin',
|
|
43
|
+
esbuild: 'commonjs esbuild',
|
|
44
|
+
'@swc/core': 'commonjs @swc/core',
|
|
45
|
+
'@swc/wasm': 'commonjs @swc/wasm'
|
|
46
|
+
},
|
|
47
|
+
resolve: {
|
|
48
|
+
extensions: ['.tsx', '.ts', '.js', '.jsx', '.mjs'],
|
|
49
|
+
mainFields: ['module', 'browser', 'main'],
|
|
50
|
+
fullySpecified: false,
|
|
51
|
+
fallback: {
|
|
52
|
+
process: require.resolve('process/browser.js'),
|
|
53
|
+
global: require.resolve('global')
|
|
54
|
+
},
|
|
55
|
+
modules: ['node_modules', 'src', 'static']
|
|
56
|
+
},
|
|
57
|
+
module: {
|
|
58
|
+
rules: [
|
|
59
|
+
{
|
|
60
|
+
test: /\.(ts|tsx|js|jsx)$/,
|
|
61
|
+
exclude: /node_modules/,
|
|
62
|
+
use: {
|
|
63
|
+
loader: 'ts-loader',
|
|
64
|
+
options: {
|
|
65
|
+
transpileOnly: true
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
test: /\.s[ac]ss$/,
|
|
71
|
+
use: ['style-loader', 'css-loader', 'sass-loader']
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
test: /\.css$/,
|
|
75
|
+
use: ['style-loader', 'css-loader'],
|
|
76
|
+
exclude: /node_modules/
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|mp4)$/,
|
|
80
|
+
type: 'asset/resource',
|
|
81
|
+
generator: {
|
|
82
|
+
filename: '[name][ext]'
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
test: /\.html$/,
|
|
87
|
+
use: {
|
|
88
|
+
loader: 'html-loader',
|
|
89
|
+
options: {
|
|
90
|
+
sources: false,
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
]
|
|
95
|
+
},
|
|
96
|
+
plugins: [
|
|
97
|
+
new webpack.DefinePlugin({
|
|
98
|
+
global: 'globalThis'
|
|
99
|
+
}),
|
|
100
|
+
new webpack.ProvidePlugin({
|
|
101
|
+
process: 'process/browser.js'
|
|
102
|
+
}),
|
|
103
|
+
new CleanWebpackPlugin(),
|
|
104
|
+
new HtmlWebpackPlugin({
|
|
105
|
+
template: controllerHtmlPath,
|
|
106
|
+
filename: 'index.html',
|
|
107
|
+
inject: 'body',
|
|
108
|
+
chunks: ['main']
|
|
109
|
+
}),
|
|
110
|
+
new CopyWebpackPlugin({
|
|
111
|
+
patterns: [
|
|
112
|
+
{ from: controllerStaticPath, to: 'static', noErrorOnMissing: true },
|
|
113
|
+
{ from: controllerFontsPath, to: 'fonts', noErrorOnMissing: true }
|
|
114
|
+
]
|
|
115
|
+
})
|
|
116
|
+
],
|
|
117
|
+
optimization: isDev ? undefined : {
|
|
118
|
+
minimize: false,
|
|
119
|
+
minimizer: [
|
|
120
|
+
new TerserPlugin({
|
|
121
|
+
minify: TerserPlugin.terserMinify,
|
|
122
|
+
terserOptions: {
|
|
123
|
+
ecma: 2020,
|
|
124
|
+
compress: true,
|
|
125
|
+
mangle: true,
|
|
126
|
+
format: { comments: false }
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
]
|
|
130
|
+
},
|
|
131
|
+
devtool: isDev ? 'source-map' : false,
|
|
132
|
+
devServer: isDev ? {
|
|
133
|
+
static: [
|
|
134
|
+
{
|
|
135
|
+
directory: path.resolve(options.src, 'test'),
|
|
136
|
+
publicPath: '/test',
|
|
137
|
+
watch: true,
|
|
138
|
+
}
|
|
139
|
+
],
|
|
140
|
+
open: false,
|
|
141
|
+
client: {
|
|
142
|
+
overlay: true
|
|
143
|
+
},
|
|
144
|
+
port: options.port || 8080,
|
|
145
|
+
hot: true,
|
|
146
|
+
historyApiFallback: true,
|
|
147
|
+
devMiddleware: {
|
|
148
|
+
publicPath: '/',
|
|
149
|
+
writeToDisk: false
|
|
150
|
+
}
|
|
151
|
+
} : undefined
|
|
152
|
+
};
|
|
153
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vixoniccom/module-packager",
|
|
3
|
-
"version": "2.12.0-dev.
|
|
3
|
+
"version": "2.12.0-dev.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"bin": {
|
|
@@ -17,9 +17,6 @@
|
|
|
17
17
|
"build:renderer": "webpack --config webpack.config.js --env src=./ --env build=./dist/build --mode production",
|
|
18
18
|
"copy:launcher": "cp launcher.html dist/launcher.html",
|
|
19
19
|
"build": "npm run clean && npm-run-all -p build:renderer build:main && npm run copy:launcher",
|
|
20
|
-
"watch:renderer": "webpack --config webpack.config.js --env src=./ --env build=./dist/build --mode=development --watch",
|
|
21
|
-
"watch:main": "tsc -p tsconfig.json --outDir dist --watch",
|
|
22
|
-
"dev:watch": "npm run clean && npm-run-all -p watch:renderer watch:main",
|
|
23
20
|
"prerelease-dev": "standard-version --prerelease dev",
|
|
24
21
|
"prerelease-rc": "standard-version --prerelease rc",
|
|
25
22
|
"prerelease-test": "standard-version --prerelease test",
|