@vixoniccom/module-packager 2.12.0-dev.11 → 2.12.0-dev.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/dist/electron.js +7 -4
- package/dist/launcher.html +15 -23
- package/dist/main.js +31 -21
- package/dist/webpack.config.js +5 -12
- package/package.json +7 -8
package/dist/electron.js
CHANGED
|
@@ -8,11 +8,11 @@ const __filename = fileURLToPath(import.meta.url);
|
|
|
8
8
|
const __dirname = path.dirname(__filename);
|
|
9
9
|
const optionDefinitions = [
|
|
10
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') },
|
|
11
|
+
{ name: 'src', type: String, defaultValue: path.join(__dirname, './src') },
|
|
12
|
+
{ name: 'build', type: String, defaultValue: path.join(__dirname, './build') },
|
|
13
13
|
{ name: 'config', type: String, defaultValue: './webpack.config.js' },
|
|
14
14
|
{ name: 'port', type: Number, defaultValue: 8080 },
|
|
15
|
-
{ name: 'mode', type: String, defaultValue: '
|
|
15
|
+
{ name: 'mode', type: String, defaultValue: 'run' }
|
|
16
16
|
];
|
|
17
17
|
const options = commandLineArgs(optionDefinitions);
|
|
18
18
|
if (options.mode === 'watch') {
|
|
@@ -55,4 +55,7 @@ app.whenReady().then(() => {
|
|
|
55
55
|
}
|
|
56
56
|
});
|
|
57
57
|
});
|
|
58
|
-
app.on('window-all-closed', () =>
|
|
58
|
+
app.on('window-all-closed', () => {
|
|
59
|
+
if (process.platform !== 'darwin')
|
|
60
|
+
app.quit();
|
|
61
|
+
});
|
package/dist/launcher.html
CHANGED
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
</head>
|
|
8
8
|
|
|
9
9
|
<body style="width: 100%; height: 100%; margin: 0; padding: 0;">
|
|
10
|
-
|
|
11
|
-
<div id="webview-container" style="width: 100%; height: 100%;"></div>
|
|
10
|
+
<webview id="webview" style="width: 100%; height: 100%;" partition="persist:webview"></webview>
|
|
12
11
|
|
|
13
12
|
<script>
|
|
14
13
|
const path = require('path')
|
|
14
|
+
const { pathToFileURL } = require('url')
|
|
15
15
|
let ModuleController;
|
|
16
16
|
try {
|
|
17
17
|
const moduleControllerModule = require('@vixoniccom/module-controller');
|
|
@@ -23,17 +23,11 @@
|
|
|
23
23
|
const remote = require('@electron/remote')
|
|
24
24
|
|
|
25
25
|
ipcRenderer.on('init', (event, options) => {
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
webview.style.width = '100%'
|
|
30
|
-
webview.style.height = '100%'
|
|
31
|
-
webview.setAttribute('partition', 'persist:webview')
|
|
32
|
-
|
|
26
|
+
const webview = document.getElementById('webview')
|
|
27
|
+
const win = remote.getCurrentWindow()
|
|
28
|
+
|
|
33
29
|
webview.setAttribute('nodeintegration', '')
|
|
34
30
|
webview.setAttribute('webpreferences', 'webSecurity=false, allowRunningInsecureContent=true, nodeIntegration=yes, contextIsolation=no')
|
|
35
|
-
|
|
36
|
-
const win = remote.getCurrentWindow()
|
|
37
31
|
|
|
38
32
|
webview.addEventListener('did-finish-load', () => {
|
|
39
33
|
win.show()
|
|
@@ -46,29 +40,27 @@
|
|
|
46
40
|
|
|
47
41
|
webview.src = resolvedSrc
|
|
48
42
|
|
|
49
|
-
// Añadir el webview al DOM después de configurarlo
|
|
50
|
-
document.getElementById('webview-container').appendChild(webview)
|
|
51
|
-
|
|
52
43
|
function getData() {
|
|
53
44
|
const data = {}
|
|
54
45
|
|
|
55
46
|
try {
|
|
56
|
-
data.parameters = require(path.join(options.src, 'test
|
|
47
|
+
data.parameters = require(path.join(options.src, '/test/parameters.json')).parameters
|
|
57
48
|
} catch (err) {
|
|
58
49
|
console.log('No parameters:', err.message)
|
|
59
50
|
}
|
|
60
51
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
data.downloadsPath = escaped
|
|
52
|
+
const downloadsDir = path.join(
|
|
53
|
+
options.mode === 'watch' ? options.src : options.build,
|
|
54
|
+
'test',
|
|
55
|
+
'downloads'
|
|
56
|
+
)
|
|
68
57
|
|
|
58
|
+
data.downloadsPath = options.mode === 'watch'
|
|
59
|
+
? pathToFileURL(downloadsDir).href
|
|
60
|
+
: downloadsDir.replace(/\\/g, '/')
|
|
69
61
|
|
|
70
62
|
try {
|
|
71
|
-
data.services = require(path.join(options.src, 'test
|
|
63
|
+
data.services = require(path.join(options.src, '/test/services.json')).services
|
|
72
64
|
} catch (err) {
|
|
73
65
|
console.log('No services:', err.message)
|
|
74
66
|
}
|
package/dist/main.js
CHANGED
|
@@ -16,14 +16,7 @@ import which from 'which';
|
|
|
16
16
|
const __filename = fileURLToPath(import.meta.url);
|
|
17
17
|
const __dirname = path.dirname(__filename);
|
|
18
18
|
const electronPath = path.join(__dirname, 'electron.js');
|
|
19
|
-
|
|
20
|
-
try {
|
|
21
|
-
npxPath = which.sync('npx');
|
|
22
|
-
}
|
|
23
|
-
catch (error) {
|
|
24
|
-
console.log(error);
|
|
25
|
-
console.error('Error: npx is not installed or not found in PATH.');
|
|
26
|
-
}
|
|
19
|
+
const npxPath = which.sync('npx');
|
|
27
20
|
const optionDefinitions = [
|
|
28
21
|
{ name: 'externals', type: String, defaultValue: [], multiple: true },
|
|
29
22
|
{ name: 'target', type: String, defaultValue: 'web' },
|
|
@@ -54,11 +47,12 @@ function validateOptions(options) {
|
|
|
54
47
|
}
|
|
55
48
|
// Función para sanitizar rutas
|
|
56
49
|
function sanitizePath(inputPath) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
50
|
+
const resolved = path.resolve(inputPath);
|
|
51
|
+
const projectRoot = path.resolve('.');
|
|
52
|
+
if (!resolved.startsWith(projectRoot + path.sep) && !resolved.startsWith(projectRoot)) {
|
|
53
|
+
throw new Error(`Invalid path outside project scope: ${inputPath}`);
|
|
60
54
|
}
|
|
61
|
-
return
|
|
55
|
+
return resolved;
|
|
62
56
|
}
|
|
63
57
|
// Función centralizada para crear argumentos de Electron
|
|
64
58
|
function createElectronArgs(mode) {
|
|
@@ -69,10 +63,9 @@ function createElectronArgs(mode) {
|
|
|
69
63
|
'--port', String(options.port),
|
|
70
64
|
'--mode', mode,
|
|
71
65
|
'--config', options.config,
|
|
72
|
-
|
|
66
|
+
'--externals', Array.isArray(options.externals) ? options.externals.join(',') : ''
|
|
73
67
|
];
|
|
74
68
|
}
|
|
75
|
-
// Función centralizada para manejar procesos Electron
|
|
76
69
|
function spawnElectronProcess(mode) {
|
|
77
70
|
const args = createElectronArgs(mode);
|
|
78
71
|
const nodeEnv = mode === 'run' ? 'production' : 'development';
|
|
@@ -84,10 +77,28 @@ function spawnElectronProcess(mode) {
|
|
|
84
77
|
ELECTRON_DISABLE_SECURITY_WARNINGS: 'true',
|
|
85
78
|
NODE_NO_WARNINGS: '1'
|
|
86
79
|
},
|
|
87
|
-
stdio:
|
|
80
|
+
stdio: 'inherit'
|
|
81
|
+
});
|
|
82
|
+
const signals = ['SIGINT', 'SIGTERM'];
|
|
83
|
+
signals.forEach((sig) => {
|
|
84
|
+
process.once(sig, () => {
|
|
85
|
+
console.log(clc.yellow(`Received ${sig}, terminating Electron process...`));
|
|
86
|
+
child.kill(sig);
|
|
87
|
+
});
|
|
88
88
|
});
|
|
89
|
-
// Manejo centralizado de logs
|
|
90
89
|
setupChildProcessLogging(child);
|
|
90
|
+
child.on('exit', (code) => {
|
|
91
|
+
if (code !== 0) {
|
|
92
|
+
console.error(clc.red(`Electron exited with code ${code}`));
|
|
93
|
+
}
|
|
94
|
+
if (mode === 'watch') {
|
|
95
|
+
process.exit(code ?? 0);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
child.on('error', (err) => {
|
|
99
|
+
console.error(clc.red(`Failed to start Electron: ${err.message}`));
|
|
100
|
+
process.exit(1);
|
|
101
|
+
});
|
|
91
102
|
return child;
|
|
92
103
|
}
|
|
93
104
|
// Función para manejar logging de procesos hijo
|
|
@@ -105,16 +116,16 @@ function setupChildProcessLogging(child) {
|
|
|
105
116
|
}
|
|
106
117
|
});
|
|
107
118
|
}
|
|
108
|
-
// Función centralizada para compilar webpack
|
|
109
119
|
async function compileWebpack() {
|
|
110
|
-
// CORREGIDO: Usar __dirname para el webpack.config.js del module-packager
|
|
111
120
|
const cfgPath = path.resolve(__dirname, 'webpack.config.js');
|
|
112
121
|
const webpackConfigFactory = (await import(cfgPath)).default;
|
|
113
122
|
const compiler = webpack(webpackConfigFactory(options));
|
|
114
123
|
return new Promise((resolve, reject) => {
|
|
115
124
|
compiler.run((err, stats) => {
|
|
116
|
-
if (err)
|
|
125
|
+
if (err) {
|
|
126
|
+
compiler.close(() => { });
|
|
117
127
|
return reject(err);
|
|
128
|
+
}
|
|
118
129
|
if (stats?.hasErrors()) {
|
|
119
130
|
return reject(new Error(stats.toString({ all: false, errors: true, colors: true })));
|
|
120
131
|
}
|
|
@@ -199,7 +210,7 @@ async function pack(callback) {
|
|
|
199
210
|
function installExternals(callback) {
|
|
200
211
|
let externals = options.externals.map((x) => {
|
|
201
212
|
// Validar nombre del paquete
|
|
202
|
-
if (!/^[
|
|
213
|
+
if (!/^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(x)) {
|
|
203
214
|
throw new Error(`Invalid package name: ${x}`);
|
|
204
215
|
}
|
|
205
216
|
const packageJsonPath = sanitizePath(path.resolve(options.src, '..', 'node_modules', x, 'package.json'));
|
|
@@ -229,7 +240,6 @@ function zip() {
|
|
|
229
240
|
console.log(clc.blue('Cleaning build...'));
|
|
230
241
|
const buildPath = sanitizePath(options.build);
|
|
231
242
|
const zipPath = path.resolve(buildPath, '../', 'build.zip');
|
|
232
|
-
console.log("[DEBUG] Cleaning build folder", zipPath);
|
|
233
243
|
let output = fs.createWriteStream(zipPath);
|
|
234
244
|
let archive = archiver('zip');
|
|
235
245
|
archive.pipe(output);
|
package/dist/webpack.config.js
CHANGED
|
@@ -13,9 +13,7 @@ export default (env = {}, argv = {}) => {
|
|
|
13
13
|
port: env.port ?? 8080,
|
|
14
14
|
mode: argv.mode ?? 'production',
|
|
15
15
|
};
|
|
16
|
-
const isDev = options.mode === '
|
|
17
|
-
argv.watch === true ||
|
|
18
|
-
process.env.NODE_ENV === 'development';
|
|
16
|
+
const isDev = options.mode === 'watch';
|
|
19
17
|
const buildPath = path.resolve(options.build);
|
|
20
18
|
const controllerHtmlPath = path.resolve(options.src, 'index.html');
|
|
21
19
|
const controllerStaticPath = path.resolve(path.dirname(controllerHtmlPath), '../static');
|
|
@@ -23,7 +21,7 @@ export default (env = {}, argv = {}) => {
|
|
|
23
21
|
const controllerTestPath = path.resolve(options.src, 'test');
|
|
24
22
|
return {
|
|
25
23
|
mode: isDev ? 'development' : 'production',
|
|
26
|
-
target:
|
|
24
|
+
target: 'electron-renderer',
|
|
27
25
|
entry: isDev ? [
|
|
28
26
|
`webpack-dev-server/client?http://localhost:${options.port}/`,
|
|
29
27
|
'webpack/hot/dev-server',
|
|
@@ -32,12 +30,7 @@ export default (env = {}, argv = {}) => {
|
|
|
32
30
|
output: {
|
|
33
31
|
path: buildPath,
|
|
34
32
|
filename: '[name].js',
|
|
35
|
-
publicPath: isDev ? '/' : '
|
|
36
|
-
},
|
|
37
|
-
performance: {
|
|
38
|
-
maxAssetSize: 2000000, //2MB
|
|
39
|
-
maxEntrypointSize: 2000000,
|
|
40
|
-
hints: isDev ? false : 'warning'
|
|
33
|
+
publicPath: isDev ? '/' : ''
|
|
41
34
|
},
|
|
42
35
|
externals: {
|
|
43
36
|
electron: 'commonjs electron',
|
|
@@ -83,7 +76,7 @@ export default (env = {}, argv = {}) => {
|
|
|
83
76
|
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|mp4)$/,
|
|
84
77
|
type: 'asset/resource',
|
|
85
78
|
generator: {
|
|
86
|
-
filename: '[name][ext]'
|
|
79
|
+
filename: isDev ? '[name][ext]' : '[name].[contenthash:8][ext]'
|
|
87
80
|
}
|
|
88
81
|
},
|
|
89
82
|
{
|
|
@@ -119,7 +112,7 @@ export default (env = {}, argv = {}) => {
|
|
|
119
112
|
]
|
|
120
113
|
})
|
|
121
114
|
],
|
|
122
|
-
optimization: {
|
|
115
|
+
optimization: isDev ? undefined : {
|
|
123
116
|
minimize: !isDev,
|
|
124
117
|
minimizer: [
|
|
125
118
|
new TerserPlugin({
|
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.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"bin": {
|
|
@@ -9,13 +9,13 @@
|
|
|
9
9
|
"files": [
|
|
10
10
|
"dist"
|
|
11
11
|
],
|
|
12
|
-
"main": "dist/main.js",
|
|
12
|
+
"main": "./dist/main.js",
|
|
13
13
|
"scripts": {
|
|
14
14
|
"start": "electron dist/electron.js --mode run --build ./dist/build",
|
|
15
15
|
"clean": "rimraf dist",
|
|
16
16
|
"build:main": "tsc -p tsconfig.json --outDir dist",
|
|
17
17
|
"build:renderer": "webpack --config webpack.config.js --env src=./ --env build=./dist/build --mode production",
|
|
18
|
-
"copy:launcher": "
|
|
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
20
|
"prerelease-dev": "standard-version --prerelease dev",
|
|
21
21
|
"prerelease-rc": "standard-version --prerelease rc",
|
|
@@ -31,19 +31,18 @@
|
|
|
31
31
|
"clean-webpack-plugin": "^4.0.0",
|
|
32
32
|
"cli-color": "^1.2.0",
|
|
33
33
|
"command-line-args": "^3.0.1",
|
|
34
|
-
"copy-webpack-plugin": "^
|
|
35
|
-
"cpy-cli": "^5.0.0",
|
|
34
|
+
"copy-webpack-plugin": "^12.0.2",
|
|
36
35
|
"css-loader": "^7.1.2",
|
|
37
36
|
"electron": "^36.1.0",
|
|
38
37
|
"electron-debug": "^3.2.0",
|
|
39
38
|
"global": "^4.4.0",
|
|
40
39
|
"html-loader": "^5.1.0",
|
|
41
|
-
"html-webpack-plugin": "^
|
|
40
|
+
"html-webpack-plugin": "^5.6.0",
|
|
42
41
|
"lodash": "^4.17.21",
|
|
43
42
|
"process": "^0.11.10",
|
|
44
|
-
"raw-loader": "^
|
|
45
|
-
"rimraf": "^6.0.1",
|
|
43
|
+
"raw-loader": "^0.5.1",
|
|
46
44
|
"style-loader": "^4.0.0",
|
|
45
|
+
"terser-webpack-plugin": "^5.3.10",
|
|
47
46
|
"ts-loader": "^9.5.0",
|
|
48
47
|
"ts-node": "^10.9.1",
|
|
49
48
|
"typescript": "^5.8.3",
|