@vixoniccom/module-packager 2.10.2-test.7 → 2.10.3-dev.0

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 CHANGED
@@ -4,7 +4,6 @@ import remoteMain from '@electron/remote/main/index.js';
4
4
  import path from 'path';
5
5
  import { fileURLToPath } from 'url';
6
6
  import commandLineArgs from 'command-line-args';
7
- import fs from 'fs';
8
7
  const __filename = fileURLToPath(import.meta.url);
9
8
  const __dirname = path.dirname(__filename);
10
9
  const optionDefinitions = [
@@ -16,14 +15,12 @@ const optionDefinitions = [
16
15
  { name: 'mode', type: String, defaultValue: 'run' }
17
16
  ];
18
17
  const options = commandLineArgs(optionDefinitions);
19
- console.log('🚀 [ELECTRON] options:', options);
20
18
  if (options.mode === 'watch') {
21
19
  (await import('electron-debug')).default({ showDevTools: true });
22
20
  }
23
21
  remoteMain.initialize();
24
22
  let mainWindow = null;
25
23
  function createWindow() {
26
- console.log('[ELECTRON] Creating BrowserWindow…');
27
24
  mainWindow = new BrowserWindow({
28
25
  show: false,
29
26
  x: 100,
@@ -31,7 +28,6 @@ function createWindow() {
31
28
  width: 1024,
32
29
  height: 768,
33
30
  webPreferences: {
34
- preload: path.join(__dirname, 'preload.js'),
35
31
  nodeIntegrationInSubFrames: true,
36
32
  nodeIntegration: true,
37
33
  contextIsolation: false,
@@ -40,21 +36,22 @@ function createWindow() {
40
36
  }
41
37
  });
42
38
  remoteMain.enable(mainWindow.webContents);
43
- const devUrl = `http://localhost:${options.port}/index.html`;
44
- const fileUrl = `file://${path.join(options.build, 'index.html')}`;
45
- console.log('[ELECTRON] build dir:', options.build);
46
- console.log('[ELECTRON] index.html exists?', fs.existsSync(path.join(options.build, 'index.html')));
47
- const url = options.mode === 'watch' ? devUrl : fileUrl;
48
- console.log('[ELECTRON] Loading URL:', url);
49
- console.log('[ELECTRON] Loading URL:', url);
50
- mainWindow.loadURL(url);
39
+ const launcherPath = path.join(__dirname, 'launcher.html');
40
+ const launcherURL = `file://${launcherPath}`;
41
+ // const devUrl = `http://localhost:${options.port}/index.html`;
42
+ // const fileUrl = `file://${path.join(options.build, 'index.html')}`;
43
+ console.log('🚀 cargando launcher:', launcherURL);
44
+ mainWindow.loadURL(launcherURL);
45
+ // const url = options.mode === 'watch' ? devUrl : fileUrl;
46
+ // console.log("🚀 ~ createWindow ~ url:", url)
47
+ mainWindow.webContents.openDevTools({ mode: 'detach' });
48
+ // mainWindow.loadURL(url);
51
49
  mainWindow.webContents.once('did-finish-load', () => {
52
50
  console.log('[ELECTRON] did-finish-load → show()');
53
51
  mainWindow?.show();
54
52
  mainWindow?.webContents.send('init', options);
55
53
  });
56
54
  mainWindow.on('closed', () => (mainWindow = null));
57
- // mainWindow.webContents.openDevTools({ mode: 'detach' });
58
55
  }
59
56
  app.whenReady().then(() => {
60
57
  console.log('[ELECTRON] App is ready');
@@ -0,0 +1,98 @@
1
+ <!DOCTYPE html>
2
+ <html 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
+ ModuleController = require('@vixoniccom/module-controller');
17
+ console.log('[WEBVIEW] ModuleController cargado OK');
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
+ console.log('[WEBVIEW] init', options)
26
+
27
+ const webview = document.getElementById('webview')
28
+ const win = remote.getCurrentWindow()
29
+
30
+ webview.setAttribute('nodeintegration', '')
31
+ webview.setAttribute('webpreferences', 'contextIsolation=no, nodeIntegration=yes')
32
+
33
+ webview.addEventListener('dom-ready', () => {
34
+ webview.openDevTools() // opcional
35
+ })
36
+
37
+ webview.addEventListener('did-finish-load', () => {
38
+ console.log('[WEBVIEW] did-finish-load fired')
39
+ win.show()
40
+ win.focus()
41
+ })
42
+
43
+ webview.addEventListener('did-fail-load', (e) => {
44
+ console.error('[WEBVIEW] did-fail-load', e)
45
+ })
46
+
47
+ const resolvedSrc = options.mode === 'watch'
48
+ ? `http://localhost:${options.port}/index.html`
49
+ : `file://${path.join(options.build, 'index.html')}`
50
+
51
+ console.log('[WEBVIEW] Resolved src:', resolvedSrc)
52
+
53
+ webview.src = resolvedSrc
54
+
55
+ function getData() {
56
+ const data = {}
57
+
58
+ try {
59
+ data.parameters = require(path.join(options.src, '/test/parameters.json')).parameters
60
+ } catch (err) {
61
+ console.log('No parameters:', err.message)
62
+ }
63
+
64
+ let escaped = path.join(options.mode === 'watch' ? options.src : options.build, 'test', 'downloads')
65
+ if (options.mode === 'watch') escaped = `file://${escaped}`
66
+ escaped = escaped.replace(/\\/g, '/')
67
+ data.downloadsPath = escaped
68
+
69
+ try {
70
+ data.services = require(path.join(options.src, '/test/services.json')).services
71
+ } catch (err) {
72
+ console.log('No services:', err.message)
73
+ }
74
+
75
+ return data
76
+ }
77
+
78
+ function getSchema() {
79
+ try {
80
+ return require(path.join(options.src, '../configuration.json')).schema
81
+ } catch (err) {
82
+ console.log('No schema:', err.message)
83
+ return {}
84
+ }
85
+ }
86
+
87
+ const data = getData()
88
+ const schema = getSchema()
89
+
90
+ console.log('[WEBVIEW] Data entregada a ModuleController:', data)
91
+ console.log('[WEBVIEW] Schema entregado a ModuleController:', schema)
92
+
93
+ ModuleController.init(win, webview, data, schema, options.mode === 'watch')
94
+ })
95
+ </script>
96
+ </body>
97
+
98
+ </html>
package/dist/main.js CHANGED
@@ -80,9 +80,11 @@ function runElectron() {
80
80
  });
81
81
  }
82
82
  async function pack(callback) {
83
+ console.log(path.resolve(__dirname, './dist', options.config));
83
84
  console.log(clc.blue('Building module...'));
84
85
  validateConfiguration();
85
- const configPath = path.resolve(__dirname, '../', options.config);
86
+ const configPath = path.resolve(__dirname, options.config);
87
+ console.log("🚀 ~ pack ~ configPath:", configPath);
86
88
  try {
87
89
  const webpackConfig = (await import(configPath)).default(options);
88
90
  webpack(webpackConfig, function (err, stats) {
@@ -144,6 +146,8 @@ function installExternals(callback) {
144
146
  }
145
147
  function zip() {
146
148
  console.log(clc.blue('Archiving...'));
149
+ console.log(clc.blue('Cleaning build...'));
150
+ console.log("[DEBUG] Cleaning build folder", path.resolve(options.build, '../', 'build.zip'));
147
151
  let output = fs.createWriteStream(path.resolve(options.build, '../', 'build.zip'));
148
152
  let archive = archiver('zip');
149
153
  archive.pipe(output);
@@ -159,11 +163,16 @@ function zip() {
159
163
  }
160
164
  async function watch() {
161
165
  console.log('[VMP] ▸ starting dev-server & electron in watch mode…');
162
- const cfgPath = path.resolve(__dirname, '..', 'webpack.config.js');
166
+ const cfgPath = path.resolve(__dirname, '..', 'dist/webpack.config.js');
163
167
  const webpackConfigFactory = (await import(cfgPath)).default;
164
- console.log("🚀 ~ watch ~ webpackConfigFactory:", webpackConfigFactory);
168
+ console.log('[VMP] ▸ webpack config loaded from', cfgPath);
165
169
  const compiler = webpack(webpackConfigFactory(options));
166
- const server = new WebpackDevServer({ static: path.join(__dirname, options.src, '..'), port: options.port }, compiler);
170
+ const server = new WebpackDevServer({
171
+ static: false,
172
+ port: options.port,
173
+ devMiddleware: { publicPath: '/' },
174
+ historyApiFallback: true
175
+ }, compiler);
167
176
  await server.start();
168
177
  console.log(`[VMP] ▸ dev-server listening on http://localhost:${options.port}`);
169
178
  const cmd = [
@@ -216,11 +225,11 @@ function generateConfiguration() {
216
225
  function validateConfiguration() {
217
226
  try {
218
227
  const jsonPath = path.resolve(options.src, '../', 'configuration.json');
219
- const json = JSON.parse(fs.readFileSync(jsonPath, 'utf8')); // Leer y parsear el archivo JSON
228
+ const json = JSON.parse(fs.readFileSync(jsonPath, 'utf8'));
220
229
  const conf = Configuration.fromJSON(json);
221
230
  if (conf.durationFormula) {
222
231
  const valuesPath = path.resolve(options.src, 'test', 'parameters.json');
223
- const values = JSON.parse(fs.readFileSync(valuesPath, 'utf8')); // Leer y parsear otro archivo JSON
232
+ const values = JSON.parse(fs.readFileSync(valuesPath, 'utf8'));
224
233
  console.log('Validate duration');
225
234
  console.log('Duration on undefined:', conf.getDuration({}), 'seconds');
226
235
  console.log('Duration:', conf.getDuration(values.parameters), 'seconds');
@@ -1,12 +1,15 @@
1
1
  import path from 'path';
2
2
  import { fileURLToPath } from 'url';
3
+ import { createRequire } from 'module';
3
4
  import HtmlWebpackPlugin from 'html-webpack-plugin';
4
5
  import { CleanWebpackPlugin } from 'clean-webpack-plugin';
5
6
  import CopyWebpackPlugin from 'copy-webpack-plugin';
6
7
  import TerserPlugin from 'terser-webpack-plugin';
8
+ import webpack from 'webpack';
7
9
  const __filename = fileURLToPath(import.meta.url);
8
- const __dirname = path.dirname(__filename);
10
+ // const __dirname = path.dirname(__filename)
9
11
  export default (env = {}, argv = {}) => {
12
+ const require = createRequire(import.meta.url);
10
13
  const options = {
11
14
  src: env.src ?? './src',
12
15
  build: env.build ?? './build',
@@ -29,6 +32,7 @@ export default (env = {}, argv = {}) => {
29
32
  publicPath: '/'
30
33
  },
31
34
  externals: {
35
+ electron: 'commonjs electron',
32
36
  '@vixoniccom/module-controller': 'commonjs @vixoniccom/module-controller',
33
37
  webpack: 'commonjs webpack',
34
38
  'terser-webpack-plugin': 'commonjs terser-webpack-plugin',
@@ -40,10 +44,11 @@ export default (env = {}, argv = {}) => {
40
44
  extensions: ['.tsx', '.ts', '.js', '.jsx', '.mjs'],
41
45
  mainFields: ['module', 'browser', 'main'],
42
46
  fullySpecified: false,
43
- modules: [
44
- 'node_modules',
45
- path.resolve(__dirname, '../../node_modules')
46
- ]
47
+ fallback: {
48
+ process: require.resolve('process/browser.js'),
49
+ global: require.resolve('global')
50
+ },
51
+ modules: ['node_modules']
47
52
  },
48
53
  module: {
49
54
  rules: [
@@ -91,10 +96,26 @@ export default (env = {}, argv = {}) => {
91
96
  sources: false,
92
97
  }
93
98
  }
99
+ },
100
+ {
101
+ test: /\.(ts|tsx)$/,
102
+ exclude: /node_modules/,
103
+ use: {
104
+ loader: 'ts-loader',
105
+ options: {
106
+ transpileOnly: true
107
+ }
108
+ }
94
109
  }
95
110
  ]
96
111
  },
97
112
  plugins: [
113
+ new webpack.DefinePlugin({
114
+ global: 'globalThis'
115
+ }),
116
+ new webpack.ProvidePlugin({
117
+ process: 'process/browser.js'
118
+ }),
98
119
  new CleanWebpackPlugin(),
99
120
  new HtmlWebpackPlugin({
100
121
  template: controllerHtmlPath,
@@ -123,11 +144,9 @@ export default (env = {}, argv = {}) => {
123
144
  })
124
145
  ]
125
146
  },
126
- devtool: isDev ? 'source-map' : false,
147
+ devtool: isDev ? 'eval' : false,
127
148
  devServer: isDev ? {
128
- static: {
129
- directory: path.resolve(options.src)
130
- },
149
+ static: false,
131
150
  open: false,
132
151
  client: {
133
152
  overlay: true
package/package.json CHANGED
@@ -56,7 +56,7 @@
56
56
  ],
57
57
  "dependencies": {
58
58
  "@electron/remote": "^2.1.2",
59
- "@vixoniccom/module-controller": "1.3.0-dev.5",
59
+ "@vixoniccom/module-controller": "2.0.0-dev.0",
60
60
  "@vixoniccom/modules": "^2.20.0",
61
61
  "archiver": "^5.3.0",
62
62
  "clean-webpack-plugin": "^4.0.0",
@@ -66,9 +66,11 @@
66
66
  "electron": "^36.1.0",
67
67
  "electron-debug": "^3.2.0",
68
68
  "file-loader": "^0.9.0",
69
+ "global": "^4.4.0",
69
70
  "html-loader": "^0.4.5",
70
71
  "html-webpack-plugin": "^4.5.2",
71
72
  "lodash": "^4.17.21",
73
+ "process": "^0.11.10",
72
74
  "raw-loader": "^0.5.1",
73
75
  "ts-loader": "^9.5.0",
74
76
  "ts-node": "^10.9.1",
@@ -93,19 +95,18 @@
93
95
  "readme": "ERROR: No README data found!",
94
96
  "scripts": {
95
97
  "start": "electron dist/electron.js --mode run --build ./dist/build",
96
- "build:renderer": "webpack ./webpack.config.js --mode production --env src=./ --env build=./dist/build",
97
- "build:main": "tsc -p tsconfig.json",
98
- "build": "npm-run-all -p build:renderer build:main",
99
- "dev:renderer": "webpack serve ./webpack.config.js --mode development --env src=./src --env build=./dist/build --env port=8080",
100
- "dev:electron": "wait-on http://localhost:8080/index.html && electron dist/electron.js --mode watch --port 8080 --build ./dist/build",
101
- "dev": "npm-run-all -p dev:renderer dev:electron",
98
+ "clean": "rimraf dist",
99
+ "build:main": "tsc -p tsconfig.json --outDir dist",
100
+ "build:renderer": "webpack --config webpack.config.js --env src=./ --env build=./dist/build --mode production",
101
+ "copy:launcher": "cp launcher.html dist/launcher.html",
102
+ "build": "npm run clean && npm-run-all -p build:renderer build:main && npm run copy:launcher",
102
103
  "prerelease-dev": "standard-version --prerelease dev",
103
104
  "prerelease-rc": "standard-version --prerelease rc",
104
105
  "prerelease-test": "standard-version --prerelease test",
105
106
  "release": "standard-version"
106
107
  },
107
108
  "type": "module",
108
- "version": "2.10.2-test.7",
109
+ "version": "2.10.3-dev.0",
109
110
  "license": "ISC",
110
111
  "devDependencies": {
111
112
  "@types/archiver": "^6.0.3",