@vixoniccom/module-packager 2.11.0-just4dev.2 → 2.12.0-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/main.js ADDED
@@ -0,0 +1,239 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ import commandLineArgs from 'command-line-args';
4
+ import path from 'path';
5
+ import webpack from 'webpack';
6
+ import WebpackDevServer from 'webpack-dev-server';
7
+ import { spawn, exec } from 'child_process';
8
+ import { fileURLToPath } from 'url';
9
+ import fs from 'fs';
10
+ import archiver from 'archiver';
11
+ import clc from 'cli-color';
12
+ import { Configuration } from '@vixoniccom/modules';
13
+ import tsNode from 'ts-node';
14
+ const __filename = fileURLToPath(import.meta.url);
15
+ const __dirname = path.dirname(__filename);
16
+ const electronPath = path.join(__dirname, 'electron.js');
17
+ // import pjson from '../package.json' assert { type: 'json' }
18
+ // console.log(`VIXONIC PACKAGER: Version ${pjson.version}`)
19
+ const optionDefinitions = [
20
+ { name: 'externals', type: String, defaultValue: [], multiple: true },
21
+ { name: 'target', type: String, defaultValue: 'web' },
22
+ { name: 'src', type: String, defaultValue: './src' },
23
+ { name: 'build', type: String, defaultValue: './build' },
24
+ { name: 'confDefinition', type: String, defaultValue: './configuration' },
25
+ { name: 'config', type: String, defaultValue: './webpack.config.js' },
26
+ { name: 'port', type: Number, defaultValue: 8080 },
27
+ { name: 'mode', type: String, defaultValue: 'build' },
28
+ { name: 'transpileOnly', type: Boolean },
29
+ { name: 'tsOverride', type: Boolean }
30
+ ];
31
+ const options = commandLineArgs(optionDefinitions);
32
+ if (options.target !== 'electron-renderer' && options.externals.length > 0) {
33
+ throw new Error(`Can't use external dependencies if target is not electron-renderer.`);
34
+ }
35
+ if (options.mode === 'build') {
36
+ pack(() => {
37
+ if (options.target === 'electron-renderer') {
38
+ installExternals(() => {
39
+ zip();
40
+ });
41
+ }
42
+ else {
43
+ zip();
44
+ }
45
+ });
46
+ }
47
+ else if (options.mode === 'watch') {
48
+ console.log('[DEBUG] Entrando a watch()');
49
+ watch();
50
+ }
51
+ else if (options.mode === 'run') {
52
+ run();
53
+ }
54
+ else if (options.mode === 'generate-configuration') {
55
+ generateConfiguration();
56
+ }
57
+ else if (options.mode === 'validate-configuration') {
58
+ validateConfiguration();
59
+ }
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
+ async function pack(callback) {
83
+ console.log(clc.blue('Building module...'));
84
+ validateConfiguration();
85
+ const configPath = path.resolve(__dirname, '../', options.config);
86
+ try {
87
+ const webpackConfig = (await import(configPath)).default(options);
88
+ webpack(webpackConfig, function (err, stats) {
89
+ if (err) {
90
+ console.error('Build error:', err);
91
+ if (err.details) {
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;
98
+ }
99
+ else {
100
+ if (stats.hasErrors()) {
101
+ const info = stats.toJson('errors-only');
102
+ console.error(clc.red('Webpack errors:'));
103
+ if (info.errors && info.errors.length) {
104
+ info.errors.forEach((e) => {
105
+ console.error(clc.red(typeof e === 'object' ? JSON.stringify(e, null, 2) : e));
106
+ });
107
+ }
108
+ else {
109
+ console.error(clc.red(JSON.stringify(info, null, 2)));
110
+ }
111
+ callback && callback(stats);
112
+ }
113
+ else {
114
+ console.log(clc.green('Build OK.'));
115
+ callback && callback(null);
116
+ }
117
+ }
118
+ });
119
+ }
120
+ catch (e) {
121
+ console.error(clc.red('Failed to load webpack config'));
122
+ throw e;
123
+ }
124
+ }
125
+ function installExternals(callback) {
126
+ let externals = options.externals.map((x) => {
127
+ return `${x}@${JSON.parse(fs.readFileSync(path.resolve(options.src, '..', 'node_modules', x, 'package.json'), 'utf8')).version}`;
128
+ });
129
+ if (externals.length) {
130
+ externals = externals.join(' ');
131
+ console.log(clc.blue(`Installing externals ${externals}...`));
132
+ exec(`npm install --prefix ./ --production ${externals}`, {
133
+ cwd: options.build
134
+ }, (err, _stdout) => {
135
+ if (err)
136
+ throw err;
137
+ console.log(clc.green('Externals installed.'));
138
+ callback && callback(null);
139
+ });
140
+ }
141
+ else {
142
+ callback && callback(null);
143
+ }
144
+ }
145
+ function zip() {
146
+ console.log(clc.blue('Archiving...'));
147
+ let output = fs.createWriteStream(path.resolve(options.build, '../', 'build.zip'));
148
+ let archive = archiver('zip');
149
+ archive.pipe(output);
150
+ archive.directory(path.resolve(options.build), './');
151
+ archive.finalize();
152
+ output.on('close', function () {
153
+ console.log(clc.green('Generated build.zip.'));
154
+ });
155
+ archive.on('error', function (err) {
156
+ throw err;
157
+ });
158
+ clc.move(-2, 0);
159
+ }
160
+ async function watch() {
161
+ console.log('[VMP] ▸ starting dev-server & electron in watch mode…');
162
+ const cfgPath = path.resolve(__dirname, '..', 'dist/webpack.config.js');
163
+ const webpackConfigFactory = (await import(cfgPath)).default;
164
+ console.log('[VMP] ▸ webpack config loaded from', cfgPath);
165
+ const compiler = webpack(webpackConfigFactory(options));
166
+ const server = new WebpackDevServer({
167
+ static: false,
168
+ port: options.port,
169
+ devMiddleware: { publicPath: '/' },
170
+ historyApiFallback: true
171
+ }, compiler);
172
+ await server.start();
173
+ console.log(`[VMP] ▸ dev-server listening on http://localhost:${options.port}`);
174
+ const cmd = [
175
+ 'npx', 'electron', electronPath,
176
+ '--src', path.resolve(options.src),
177
+ '--build', path.resolve(options.build),
178
+ '--port', String(options.port),
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
+ });
197
+ }
198
+ function loadConfiguration() {
199
+ tsNode.register({
200
+ compilerOptions: {
201
+ moduleResolution: 'node',
202
+ module: 'commonjs',
203
+ target: 'es2015',
204
+ checkJs: false
205
+ }
206
+ });
207
+ return require(path.resolve(options.confDefinition, 'index.ts')).configuration;
208
+ }
209
+ function generateConfiguration() {
210
+ try {
211
+ let configuration = loadConfiguration();
212
+ fs.writeFileSync(path.resolve(options.src, 'parameters.d.ts'), configuration.declarationFileString);
213
+ fs.writeFileSync(path.resolve(options.src, '..', 'configuration.json'), JSON.stringify(configuration, undefined, 2));
214
+ console.log(clc.green(`Configuration generated`));
215
+ }
216
+ catch (e) {
217
+ console.log(clc.red('Configuration generation failed'));
218
+ throw e;
219
+ }
220
+ }
221
+ function validateConfiguration() {
222
+ try {
223
+ const jsonPath = path.resolve(options.src, '../', 'configuration.json');
224
+ const json = JSON.parse(fs.readFileSync(jsonPath, 'utf8')); // Leer y parsear el archivo JSON
225
+ const conf = Configuration.fromJSON(json);
226
+ if (conf.durationFormula) {
227
+ const valuesPath = path.resolve(options.src, 'test', 'parameters.json');
228
+ const values = JSON.parse(fs.readFileSync(valuesPath, 'utf8')); // Leer y parsear otro archivo JSON
229
+ console.log('Validate duration');
230
+ console.log('Duration on undefined:', conf.getDuration({}), 'seconds');
231
+ console.log('Duration:', conf.getDuration(values.parameters), 'seconds');
232
+ }
233
+ console.log(clc.green('Valid configuration'));
234
+ }
235
+ catch (e) {
236
+ console.log(clc.red('Invalid configuration'));
237
+ throw e;
238
+ }
239
+ }
package/package.json CHANGED
@@ -1,111 +1,69 @@
1
1
  {
2
- "_args": [
3
- [
4
- {
5
- "raw": "@vixoniccom/module-packager@^1.2.0",
6
- "scope": "@vixoniccom",
7
- "escapedName": "@vixoniccom%2fmodule-packager",
8
- "name": "@vixoniccom/module-packager",
9
- "rawSpec": "^1.2.0",
10
- "spec": ">=1.2.0 <2.0.0",
11
- "type": "range"
12
- }
13
- ]
14
- ],
15
- "_from": "@vixoniccom/module-packager@>=1.2.0 <2.0.0",
16
- "_id": "@vixoniccom/module-packager@1.2.0",
17
- "_inCache": true,
18
- "_location": "/@vixoniccom/module-packager",
19
- "_nodeVersion": "7.6.0",
20
- "_npmOperationalInternal": {
21
- "host": "packages-12-west.internal.npmjs.com",
22
- "tmp": "tmp/module-packager-1.2.0.tgz_1487918846893_0.5388180573936552"
23
- },
24
- "_npmUser": {
25
- "name": "vixonic",
26
- "email": "tdadone@vixonic.net"
27
- },
28
- "_npmVersion": "2.15.9",
29
- "_phantomChildren": {},
30
- "_requested": {
31
- "raw": "@vixoniccom/module-packager@^1.2.0",
32
- "scope": "@vixonic",
33
- "escapedName": "@vixonic%2fmodule-packager",
34
- "name": "@vixoniccom/module-packager",
35
- "rawSpec": "^1.2.0",
36
- "spec": ">=1.2.0 <2.0.0",
37
- "type": "range"
2
+ "name": "@vixoniccom/module-packager",
3
+ "version": "2.12.0-dev.0",
4
+ "type": "module",
5
+ "license": "ISC",
6
+ "bin": {
7
+ "vixonic-module-packager": "./dist/main.js"
38
8
  },
39
- "_requiredBy": [
40
- "#DEV:/"
9
+ "files": [
10
+ "dist"
41
11
  ],
42
- "_resolved": "https://registry.npmjs.org/@vixoniccom/module-packager/-/module-packager-1.2.0.tgz",
43
- "_shasum": "9735f3bcbf2101d404d7bb058cb8337b0a87c503",
44
- "_shrinkwrap": null,
45
- "_spec": "@vixoniccom/module-packager@^1.2.0",
46
- "_where": "c:\\Development\\menuboard",
47
- "author": {
48
- "name": "tdadone"
49
- },
50
- "bin": {
51
- "vixonic-module-packager": "main.js"
12
+ "main": "dist/main.js",
13
+ "scripts": {
14
+ "start": "electron dist/electron.js --mode run --build ./dist/build",
15
+ "clean": "rimraf dist",
16
+ "build:main": "tsc -p tsconfig.json --outDir dist",
17
+ "build:renderer": "webpack --config webpack.config.js --env src=./ --env build=./dist/build --mode production",
18
+ "copy:launcher": "cp launcher.html dist/launcher.html",
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
+ "prerelease-dev": "standard-version --prerelease dev",
24
+ "prerelease-rc": "standard-version --prerelease rc",
25
+ "prerelease-test": "standard-version --prerelease test",
26
+ "release": "standard-version"
52
27
  },
53
28
  "dependencies": {
54
- "@vixoniccom/module-controller": "^1.2.2",
55
- "@vixoniccom/modules": "^2.20.0",
29
+ "@electron/remote": "^2.1.2",
30
+ "@types/which": "^3.0.4",
31
+ "@vixoniccom/module-controller": "2.0.0-dev.6",
32
+ "@vixoniccom/modules": "2.20.3-dev.0",
56
33
  "archiver": "^5.3.0",
57
- "babel-core": "^6.14.0",
58
- "babel-loader": "^6.2.5",
59
- "babel-polyfill": "^6.26.0",
60
- "babel-preset-env": "^1.7.0",
61
- "babel-preset-react": "^6.24.1",
62
- "clean-webpack-plugin": "^0.1.10",
34
+ "clean-webpack-plugin": "^4.0.0",
63
35
  "cli-color": "^1.2.0",
64
36
  "command-line-args": "^3.0.1",
65
- "copy-webpack-plugin": "^4.6.0",
66
- "css-loader": "^0.24.0",
67
- "electron": "^11.4.12",
37
+ "copy-webpack-plugin": "^13.0.0",
38
+ "css-loader": "^7.1.2",
39
+ "electron": "^36.1.0",
68
40
  "electron-debug": "^3.2.0",
69
- "file-loader": "^0.9.0",
70
- "html-loader": "^0.4.3",
41
+ "global": "^4.4.0",
42
+ "html-loader": "^5.1.0",
71
43
  "html-webpack-plugin": "^4.5.2",
72
44
  "lodash": "^4.17.21",
73
- "node-sass": "^6.0.1",
45
+ "process": "^0.11.10",
74
46
  "raw-loader": "^0.5.1",
75
- "sass-loader": "^4.0.2",
76
- "style-loader": "^0.13.1",
77
- "ts-loader": "^8.2.0",
47
+ "style-loader": "^4.0.0",
48
+ "ts-loader": "^9.5.0",
78
49
  "ts-node": "^10.9.1",
79
- "typescript": "^4.7.3",
80
- "uglifyjs-webpack-plugin": "^1.3.0",
81
- "webpack": "^4.46.0",
82
- "webpack-dev-server": "^4.9.3"
83
- },
84
- "directories": {},
85
- "dist": {
86
- "shasum": "9735f3bcbf2101d404d7bb058cb8337b0a87c503",
87
- "tarball": "https://registry.npmjs.org/@vixoniccom/module-packager/-/module-packager-1.2.0.tgz"
50
+ "typescript": "^5.8.3",
51
+ "webpack": "^5.99.8",
52
+ "webpack-cli": "^6.0.1",
53
+ "webpack-dev-server": "^5.2.1",
54
+ "which": "^5.0.0"
88
55
  },
89
- "main": "main.js",
90
- "maintainers": [
91
- {
92
- "name": "vixonic",
93
- "email": "tdadone@vixonic.net"
94
- }
95
- ],
96
- "name": "@vixoniccom/module-packager",
97
- "readme": "ERROR: No README data found!",
98
- "scripts": {
99
- "start": "electron --disable-site-isolation-trials",
100
- "prerelease-dev": "standard-version --prerelease dev",
101
- "prerelease-rc": "standard-version --prerelease rc",
102
- "prerelease-test": "standard-version --prerelease test",
103
- "prerelease-just4dev": "standard-version --prerelease just4dev",
104
- "release": "standard-version"
105
- },
106
- "version": "2.11.0-just4dev.2",
107
- "license": "ISC",
108
56
  "devDependencies": {
109
- "standard-version": "^9.3.1"
57
+ "@types/archiver": "^6.0.3",
58
+ "@types/cli-color": "^2.0.6",
59
+ "@types/command-line-args": "^5.2.3",
60
+ "@types/node": "^20.11.25",
61
+ "@types/webpack-env": "^1.18.8",
62
+ "concurrently": "^9.1.2",
63
+ "npm-run-all": "^4.1.5",
64
+ "sass": "^1.88.0",
65
+ "sass-loader": "^16.0.5",
66
+ "standard-version": "^9.3.1",
67
+ "wait-on": "^8.0.3"
110
68
  }
111
69
  }
package/.babelrc DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "presets": ["env", "react"]
3
- }
package/.eslintrc DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "extends": ["standard", "standard-react"]
3
- }