jizy-packer 2.1.42 → 2.1.44

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/README.md CHANGED
@@ -145,7 +145,7 @@ Options:
145
145
  ### Programmatic
146
146
 
147
147
  ```js
148
- import jPackBuild from './lib/Build.js';
148
+ import { jPackBuild } from 'jizy-packer';
149
149
 
150
150
  await jPackBuild({
151
151
  action: 'build',
@@ -154,3 +154,13 @@ await jPackBuild({
154
154
  debug: true
155
155
  });
156
156
  ```
157
+
158
+ ## Development
159
+
160
+ Run the example to test the full pipeline (scaffold + build):
161
+
162
+ ```sh
163
+ npm run example
164
+ ```
165
+
166
+ This creates a dummy "MyWidget" package in `examples/output/`, builds it with jizy-packer, and verifies the output.
package/cli/helper.js ADDED
@@ -0,0 +1,207 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import readline from "readline";
4
+
5
+ export function loadYourConfig(baseDir, defaults) {
6
+ const configPath = path.join(baseDir, "me.json");
7
+
8
+ if (fs.existsSync(configPath)) {
9
+ const jsonConfig = JSON.parse(fs.readFileSync(configPath, "utf8"));
10
+
11
+ if (jsonConfig.keywords) {
12
+ if (!Array.isArray(jsonConfig.keywords)) {
13
+ jsonConfig.keywords = jsonConfig.keywords.split(',');
14
+ }
15
+ defaults.KEYWORDS_PREPEND = jsonConfig.keywords.map(k => k.trim()).filter(k => k.length > 0);
16
+ }
17
+ if (jsonConfig.gitAccount) {
18
+ defaults.GIT_ACCOUNT = jsonConfig.gitAccount;
19
+ }
20
+ if (jsonConfig.gitPrefix) {
21
+ defaults.GIT_PREFIX = jsonConfig.gitPrefix;
22
+ }
23
+ if (jsonConfig.authorName) {
24
+ defaults.AUTHOR_NAME = jsonConfig.authorName;
25
+ }
26
+ if (jsonConfig.authorEmail) {
27
+ defaults.AUTHOR_EMAIL = jsonConfig.authorEmail;
28
+ }
29
+ if (jsonConfig.authorWebsite) {
30
+ defaults.AUTHOR_WEBSITE = jsonConfig.authorWebsite;
31
+ }
32
+ if (jsonConfig.homepagePrefix) {
33
+ defaults.HOMEPAGE_PREFIX = jsonConfig.homepagePrefix;
34
+ }
35
+ if (jsonConfig.license) {
36
+ defaults.LICENSE = jsonConfig.license;
37
+ }
38
+ }
39
+
40
+ return defaults;
41
+ }
42
+
43
+ export function loadActualPackageJsonFile(baseDir, defaults) {
44
+ let pkg = {
45
+ name: null,
46
+ version: '1.0.0',
47
+ browser: '',
48
+ main: 'lib/index.js',
49
+ type: 'module',
50
+ jizy: 'dist/',
51
+ licence: 'MIT',
52
+ homepage: '',
53
+ description: '',
54
+ keywords: [],
55
+ files: [],
56
+ scripts: {},
57
+ dependencies: {}
58
+ };
59
+
60
+ const pkgPath = path.join(baseDir, "package.json");
61
+
62
+ if (fs.existsSync(pkgPath)) {
63
+ const current = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
64
+ pkg = Object.assign({}, pkg, current);
65
+
66
+ if (pkg.name) {
67
+ defaults.MODULE_ALIAS = pkg.name;
68
+ }
69
+
70
+ if (pkg.description) {
71
+ defaults.DESCRIPTION = pkg.description;
72
+ }
73
+
74
+ if (pkg.keywords) {
75
+ defaults.KEYWORDS = pkg.keywords;
76
+ }
77
+
78
+ if (pkg.homepage) {
79
+ defaults.HOMEPAGE = pkg.homepage;
80
+ }
81
+
82
+ if (pkg.author) {
83
+ if (typeof pkg.author === 'string') {
84
+ const authorMatch = pkg.author.match(/(.*?)\s*<([^>]+)>\s*\(([^)]+)\)/);
85
+ if (authorMatch) {
86
+ defaults.AUTHOR_NAME = authorMatch[1];
87
+ defaults.AUTHOR_EMAIL = authorMatch[2];
88
+ defaults.AUTHOR_WEBSITE = authorMatch[3];
89
+ }
90
+ } else {
91
+ defaults.AUTHOR_NAME = pkg.author.name;
92
+ defaults.AUTHOR_EMAIL = pkg.author.email;
93
+ defaults.AUTHOR_WEBSITE = pkg.author.url;
94
+ }
95
+ }
96
+
97
+ if (pkg.license) {
98
+ defaults.LICENSE = pkg.license;
99
+ }
100
+ }
101
+
102
+ return { pkg, defaults };
103
+ }
104
+
105
+ export function loadActualComposerJsonFile(baseDir, defaults) {
106
+ let composer = {
107
+ name: null,
108
+ type: 'library',
109
+ description: '',
110
+ keywords: [],
111
+ homepage: '',
112
+ license: 'MIT',
113
+ authors: []
114
+ }
115
+
116
+ const composerPath = path.join(baseDir, "composer.json");
117
+
118
+ if (fs.existsSync(composerPath)) {
119
+ const current = JSON.parse(fs.readFileSync(composerPath, "utf8"));
120
+ composer = Object.assign({}, composer, current);
121
+
122
+ if (composer.name) {
123
+ defaults.GIT_MODULE = composer.name;
124
+ }
125
+
126
+ if (!defaults.DESCRIPTION && composer.description) {
127
+ defaults.DESCRIPTION = composer.description;
128
+ }
129
+
130
+ if (!defaults.KEYWORDS && composer.keywords) {
131
+ defaults.KEYWORDS = composer.keywords;
132
+ }
133
+
134
+ if (!defaults.HOMEPAGE && composer.homepage) {
135
+ defaults.HOMEPAGE = composer.homepage;
136
+ }
137
+
138
+ if (composer.authors && composer.authors.length > 0) {
139
+ const author = composer.authors[0];
140
+ if (!defaults.AUTHOR_NAME && author.name) {
141
+ defaults.AUTHOR_NAME = author.name;
142
+ }
143
+ if (!defaults.AUTHOR_EMAIL && author.email) {
144
+ defaults.AUTHOR_EMAIL = author.email;
145
+ }
146
+ if (!defaults.AUTHOR_WEBSITE && author.homepage) {
147
+ defaults.AUTHOR_WEBSITE = author.homepage;
148
+ }
149
+ }
150
+ }
151
+
152
+ return { composer, defaults };
153
+ }
154
+
155
+ export function copyDefaultFiles(srcDir, destDir, replacements) {
156
+ const entries = fs.readdirSync(srcDir, { withFileTypes: true });
157
+
158
+ entries.forEach(entry => {
159
+ const srcPath = path.join(srcDir, entry.name);
160
+ const destName = entry.name.replace(/\.skel$/, "");
161
+ const destPath = path.join(destDir, destName);
162
+
163
+ if (entry.isDirectory()) {
164
+ if (!fs.existsSync(destPath)) fs.mkdirSync(destPath);
165
+ copyDefaultFiles(srcPath, destPath, replacements);
166
+ return;
167
+ }
168
+
169
+ if (fs.existsSync(destPath)) {
170
+ console.log(`[SKIP] ${destName}`);
171
+ return;
172
+ }
173
+
174
+ console.log(`[COPY] ${destName}`);
175
+ let content = fs.readFileSync(srcPath, "utf8");
176
+ Object.entries(replacements).forEach(([key, value]) => {
177
+ content = content.replace(new RegExp(`%${key}%`, "g"), value);
178
+ });
179
+ fs.writeFileSync(destPath, content, "utf8");
180
+ });
181
+ }
182
+
183
+ export function askQuestion(query, current = null, def = null) {
184
+ const rl = readline.createInterface({
185
+ input: process.stdin,
186
+ output: process.stdout,
187
+ });
188
+
189
+ const hasCurrent = current !== null && current !== undefined;
190
+ const defaultValue = hasCurrent ? current : def || '';
191
+
192
+ return new Promise(resolve => rl.question(`${query} [${defaultValue}]: `, answer => {
193
+ rl.close();
194
+
195
+ if (answer === '.') {
196
+ resolve('');
197
+ return;
198
+ }
199
+
200
+ if (answer === '' && hasCurrent) {
201
+ resolve(current);
202
+ return;
203
+ }
204
+
205
+ resolve(answer === '' ? def : answer);
206
+ }));
207
+ }
package/cli/init.js CHANGED
@@ -1,511 +1,312 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import readline from "readline";
4
- import { fileURLToPath } from "url";
5
- import { execSync } from "child_process";
6
-
7
- function loadYourConfig(baseDir, defaults) {
8
- const configPath = path.join(baseDir, "me.json");
9
-
10
- if (fs.existsSync(configPath)) {
11
- const jsonConfig = JSON.parse(fs.readFileSync(configPath, "utf8"));
12
-
13
- if (jsonConfig.keywords) {
14
- if (!Array.isArray(jsonConfig.keywords)) {
15
- jsonConfig.keywords = jsonConfig.keywords.split(',');
16
- }
17
- defaults.KEYWORDS_PREPEND = jsonConfig.keywords.map(k => k.trim()).filter(k => k.length > 0);
18
- }
19
- if (jsonConfig.gitAccount) {
20
- defaults.GIT_ACCOUNT = jsonConfig.gitAccount;
21
- }
22
- if (jsonConfig.gitPrefix) {
23
- defaults.GIT_PREFIX = jsonConfig.gitPrefix;
24
- }
25
- if (jsonConfig.authorName) {
26
- defaults.AUTHOR_NAME = jsonConfig.authorName;
27
- }
28
- if (jsonConfig.authorEmail) {
29
- defaults.AUTHOR_EMAIL = jsonConfig.authorEmail;
30
- }
31
- if (jsonConfig.authorWebsite) {
32
- defaults.AUTHOR_WEBSITE = jsonConfig.authorWebsite;
33
- }
34
- if (jsonConfig.homepagePrefix) {
35
- defaults.HOMEPAGE_PREFIX = jsonConfig.homepagePrefix;
36
- }
37
- if (jsonConfig.license) {
38
- defaults.LICENSE = jsonConfig.license;
39
- }
40
- }
41
-
42
- return defaults;
43
- }
44
-
45
- function loadActualPackageJsonFile(baseDir, defaults) {
46
- let pkg = {
47
- name: null,
48
- version: '1.0.0',
49
- browser: '',
50
- main: 'lib/index.js',
51
- type: 'module',
52
- jizy: 'dist/',
53
- licence: 'MIT',
54
- homepage: '',
55
- description: '',
56
- keywords: [],
57
- files: [],
58
- scripts: {},
59
- dependencies: {}
60
- };
61
-
62
- const pkgPath = path.join(baseDir, "package.json");
63
-
64
- if (fs.existsSync(pkgPath)) {
65
- const current = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
66
- pkg = Object.assign({}, pkg, current);
67
-
68
- if (pkg.name) {
69
- defaults.MODULE_ALIAS = pkg.name;
70
- }
71
-
72
- if (pkg.description) {
73
- defaults.DESCRIPTION = pkg.description;
74
- }
75
-
76
- if (pkg.keywords) {
77
- defaults.KEYWORDS = pkg.keywords;
78
- }
79
-
80
- if (pkg.homepage) {
81
- defaults.HOMEPAGE = pkg.homepage;
82
- }
83
-
84
- if (pkg.author) {
85
- if (typeof pkg.author === 'string') {
86
- const authorMatch = pkg.author.match(/(.*?)\s*<([^>]+)>\s*\(([^)]+)\)/);
87
- if (authorMatch) {
88
- defaults.AUTHOR_NAME = authorMatch[1];
89
- defaults.AUTHOR_EMAIL = authorMatch[2];
90
- defaults.AUTHOR_WEBSITE = authorMatch[3];
91
- }
92
- } else {
93
- defaults.AUTHOR_NAME = pkg.author.name;
94
- defaults.AUTHOR_EMAIL = pkg.author.email;
95
- defaults.AUTHOR_WEBSITE = pkg.author.url;
96
- }
97
- }
98
-
99
- if (pkg.license) {
100
- defaults.LICENSE = pkg.license;
101
- }
102
- }
103
-
104
- return { pkg, defaults };
105
- }
106
-
107
- function loadActualComposerJsonFile(baseDir, defaults) {
108
- let composer = {
109
- name: null,
110
- type: 'library',
111
- description: '',
112
- keywords: [],
113
- homepage: '',
114
- license: 'MIT',
115
- authors: []
116
- }
117
-
118
- const composerPath = path.join(baseDir, "composer.json");
119
-
120
- if (fs.existsSync(composerPath)) {
121
- const current = JSON.parse(fs.readFileSync(composerPath, "utf8"));
122
- composer = Object.assign({}, composer, current);
123
-
124
- if (composer.name) {
125
- defaults.GIT_MODULE = composer.name;
126
- }
127
-
128
- if (!defaults.DESCRIPTION && composer.description) {
129
- defaults.DESCRIPTION = composer.description;
130
- }
131
-
132
- if (!defaults.KEYWORDS && composer.keywords) {
133
- defaults.KEYWORDS = composer.keywords;
134
- }
135
-
136
- if (!defaults.HOMEPAGE && composer.homepage) {
137
- defaults.HOMEPAGE = composer.homepage;
138
- }
139
-
140
- if (composer.authors && composer.authors.length > 0) {
141
- const author = composer.authors[0];
142
- if (!defaults.AUTHOR_NAME && author.name) {
143
- defaults.AUTHOR_NAME = author.name;
144
- }
145
- if (!defaults.AUTHOR_EMAIL && author.email) {
146
- defaults.AUTHOR_EMAIL = author.email;
147
- }
148
- if (!defaults.AUTHOR_WEBSITE && author.homepage) {
149
- defaults.AUTHOR_WEBSITE = author.homepage;
150
- }
151
- }
152
- }
153
-
154
- return { composer, defaults };
155
- }
156
-
157
- function copyDefaultFiles(srcDir, destDir, replacements) {
158
- const entries = fs.readdirSync(srcDir, { withFileTypes: true });
159
- // console.dir(entries.map(e => e.name));
160
-
161
- entries.forEach(entry => {
162
- const srcPath = path.join(srcDir, entry.name);
163
- const destName = entry.name.replace(/\.skel$/, "");
164
- const destPath = path.join(destDir, destName);
165
-
166
- if (entry.isDirectory()) {
167
- if (!fs.existsSync(destPath)) fs.mkdirSync(destPath);
168
- copyDefaultFiles(srcPath, destPath, replacements);
169
- return;
170
- }
171
-
172
- if (fs.existsSync(destPath)) {
173
- console.log(`[SKIP] ${destName}`);
174
- return;
175
- }
176
-
177
- console.log(`[COPY] ${destName}`);
178
- let content = fs.readFileSync(srcPath, "utf8");
179
- Object.entries(replacements).forEach(([key, value]) => {
180
- content = content.replace(new RegExp(`%${key}%`, "g"), value);
181
- });
182
- fs.writeFileSync(destPath, content, "utf8");
183
- });
184
- }
185
-
186
- function askQuestion(query, current = null, def = null) {
187
- const rl = readline.createInterface({
188
- input: process.stdin,
189
- output: process.stdout,
190
- });
191
-
192
- const hasCurrent = current !== null && current !== undefined;
193
- const defaultValue = hasCurrent ? current : def || '';
194
-
195
- return new Promise(resolve => rl.question(`${query} [${defaultValue}]: `, answer => {
196
- rl.close();
197
-
198
- if (answer === '.') {
199
- resolve('');
200
- return;
201
- }
202
-
203
- if (answer === '' && hasCurrent) {
204
- resolve(current);
205
- return;
206
- }
207
-
208
- resolve(answer === '' ? def : answer);
209
- }));
210
- }
211
-
212
- const __filename = fileURLToPath(import.meta.url);
213
- const __dirname = path.dirname(__filename);
214
- const baseDir = process.cwd();
215
- const srcDir = path.join(__dirname, "..", "_package");
216
-
217
- console.log('current working directory:', baseDir);
218
-
219
- let defaults = loadYourConfig(baseDir, { KEYWORDS_PREPEND: null });
220
-
221
- const answers = {
222
- MODULE_NAME: null,
223
- MODULE_ALIAS: null,
224
- DESCRIPTION: null,
225
- KEYWORDS: null,
226
- HOMEPAGE: null,
227
- AUTHOR_NAME: null,
228
- AUTHOR_EMAIL: null,
229
- AUTHOR_WEBSITE: null,
230
- GIT_MODULE: null,
231
- GIT_ACCOUNT: null,
232
- GIT_REPO: null,
233
- LESS: null,
234
- YEAR: null,
235
- HOMEPAGE_PREFIX: null,
236
- GIT_PREFIX: null
237
- };
238
-
239
- const packageJson = loadActualPackageJsonFile(baseDir, defaults);
240
- defaults = packageJson.defaults;
241
- const pkg = packageJson.pkg;
242
-
243
- const composerJson = loadActualComposerJsonFile(baseDir, defaults);
244
- defaults = composerJson.defaults;
245
- const composer = composerJson.composer;
246
-
247
- if (pkg.dependencies && pkg.dependencies.less) {
248
- answers.LESS = true;
249
- }
250
-
251
- if (!defaults.YEAR) {
252
- defaults.YEAR = new Date().getFullYear();
253
- }
254
-
255
- const folderName = path.basename(process.cwd());
256
-
257
- if (!defaults.MODULE_NAME) {
258
- // convert to CamelCase
259
- defaults.MODULE_NAME = folderName.split(/[-_ ]+/)
260
- .map(part => part.charAt(0).toUpperCase() + part.slice(1))
261
- .join('');
262
- }
263
-
264
- console.log('');
265
- console.log('****** Module Information');
266
- answers.MODULE_NAME = await askQuestion("Module name* (e.g. ModuleName): ", answers.MODULE_NAME, defaults.MODULE_NAME);
267
-
268
- if (!answers.MODULE_NAME) {
269
- console.error("Module name is required.");
270
- process.exit(1);
271
- }
272
-
273
- if (!defaults.MODULE_ALIAS) {
274
- defaults.MODULE_ALIAS = folderName.replace(/([A-Z])/g, (g, m1, offset) => (offset > 0 ? '-' : '') + m1.toLowerCase());
275
- }
276
-
277
- answers.MODULE_ALIAS = await askQuestion("Module alias* (e.g. module-name): ", answers.MODULE_ALIAS, defaults.MODULE_ALIAS);
278
- if (!answers.MODULE_ALIAS) {
279
- console.error("Module alias is required.");
280
- process.exit(1);
281
- }
282
-
283
- console.log('');
284
- console.log('****** Git Repository Information');
285
-
286
- if (!defaults.GIT_MODULE && defaults.GIT_PREFIX) {
287
- defaults.GIT_MODULE = `${defaults.GIT_PREFIX}/${answers.MODULE_ALIAS}`;
288
- }
289
- answers.GIT_MODULE = await askQuestion("Git module (e.g. prefix/module-name): ", answers.GIT_MODULE, defaults.GIT_MODULE);
290
- if (!answers.GIT_MODULE) {
291
- console.error('Git module is required.');
292
- process.exit(1);
293
- }
294
-
295
- const [defaultGitAccount, defaultGitRepo] = answers.GIT_MODULE.split('/');
296
- if (!defaults.GIT_ACCOUNT) {
297
- defaults.GIT_ACCOUNT = defaultGitAccount;
298
- }
299
- if (!defaults.GIT_REPO) {
300
- defaults.GIT_REPO = defaultGitRepo;
301
- }
302
-
303
- answers.GIT_ACCOUNT = await askQuestion("Git account (e.g. your-account): ", answers.GIT_ACCOUNT, defaults.GIT_ACCOUNT);
304
- answers.GIT_REPO = await askQuestion("Git repo (e.g. module-name): ", answers.GIT_REPO, defaults.GIT_REPO);
305
-
306
- console.log('');
307
- console.log('****** Author Information (optional)');
308
-
309
- answers.AUTHOR_NAME = await askQuestion("Author name (e.g. Your Name): ", answers.AUTHOR_NAME, defaults.AUTHOR_NAME);
310
- answers.AUTHOR_EMAIL = await askQuestion("Author email (e.g. your.email@example.com): ", answers.AUTHOR_EMAIL, defaults.AUTHOR_EMAIL);
311
- answers.AUTHOR_WEBSITE = await askQuestion("Author website (e.g. https://your-website.com): ", answers.AUTHOR_WEBSITE, defaults.AUTHOR_WEBSITE);
312
-
313
- console.log('');
314
- console.log('****** Description, Keywords, Homepage');
315
- console.log('Used in package.json and optionaly in composer.json');
316
-
317
- answers.DESCRIPTION = await askQuestion("Description: ", answers.DESCRIPTION, defaults.DESCRIPTION);
318
-
319
- defaults.KEYWORDS = [];
320
- if (answers.GIT_PREFIX) {
321
- defaults.KEYWORDS.push(answers.GIT_PREFIX);
322
- }
323
- defaults.KEYWORDS.push(answers.GIT_ACCOUNT);
324
- defaults.KEYWORDS.push(answers.MODULE_NAME);
325
-
326
- const keywordsInput = await askQuestion("Keywords (comma separated): ", answers.KEYWORDS ? answers.KEYWORDS.join(', ') : null, defaults.KEYWORDS.join(', '));
327
- if (keywordsInput) {
328
- answers.KEYWORDS = keywordsInput.split(',');
329
- }
330
- if (defaults.KEYWORDS_PREPEND) {
331
- answers.KEYWORDS = [...defaults.KEYWORDS_PREPEND, ...answers.KEYWORDS];
332
- }
333
- answers.KEYWORDS = answers.KEYWORDS
334
- .map(k => k.trim())
335
- .filter(k => k.length > 0)
336
- .map(k => k.toLowerCase());
337
- // unique keywords
338
- answers.KEYWORDS = Array.from(new Set(answers.KEYWORDS));
339
-
340
- if (!defaults.HOMEPAGE && defaults.HOMEPAGE_PREFIX) {
341
- defaults.HOMEPAGE_PREFIX = defaults.HOMEPAGE_PREFIX.replace(/^\/+|\/+$/g, '');
342
- defaults.HOMEPAGE = `${defaults.HOMEPAGE_PREFIX}/${answers.MODULE_ALIAS}`;
343
- }
344
- answers.HOMEPAGE = await askQuestion("Homepage: ", answers.HOMEPAGE, defaults.HOMEPAGE);
345
-
346
- console.log('');
347
- console.log('****** LESS (optional)');
348
- console.log('Used for styles compilation if needed');
349
- if (answers.LESS === null) {
350
- const lessInput = await askQuestion("Use LESS for styles? (y/N): ", null, 'N');
351
- answers.LESS = (lessInput.toLowerCase() === 'y');
352
- } else {
353
- console.log(`LESS usage detected in existing package.json, keeping it as is.`);
354
- }
355
-
356
- answers.LICENSE = await askQuestion("License for package files: ", answers.LICENSE, defaults.LICENSE);
357
- answers.YEAR = await askQuestion("Debut year for license file: ", answers.YEAR, defaults.YEAR);
358
-
359
- pkg.name = answers.MODULE_ALIAS;
360
- pkg.version = pkg.version || '1.0.0';
361
- pkg.browser = pkg.browser || `dist/js/${answers.MODULE_ALIAS}.min.js`;
362
- pkg.main = pkg.main || 'lib/index.js';
363
- pkg.type = pkg.type || 'module';
364
- pkg.jizy = 'dist/';
365
- pkg.description = answers.DESCRIPTION || '';
366
- pkg.keywords = answers.KEYWORDS || [];
367
- pkg.homepage = answers.HOMEPAGE || '';
368
- if (!pkg.files) {
369
- pkg.files = [];
370
- }
371
- pkg.files.push('dist/*');
372
- pkg.files.push('lib/*');
373
-
374
- // unique files
375
- pkg.files = Array.from(new Set(pkg.files));
376
-
377
- pkg.repository = {
378
- type: "git",
379
- url: `git+https://github.com/${answers.GIT_ACCOUNT}/${answers.GIT_REPO}.git`
380
- };
381
-
382
- if (answers.AUTHOR_NAME && answers.AUTHOR_EMAIL && answers.AUTHOR_WEBSITE) {
383
- pkg.author = answers.AUTHOR_NAME + ' <' + answers.AUTHOR_EMAIL + '> (' + answers.AUTHOR_WEBSITE + ')';
384
- } else if (answers.AUTHOR_NAME || answers.AUTHOR_EMAIL || answers.AUTHOR_WEBSITE) {
385
- pkg.author = {};
386
- if (answers.AUTHOR_NAME) pkg.author.name = answers.AUTHOR_NAME;
387
- if (answers.AUTHOR_EMAIL) pkg.author.email = answers.AUTHOR_EMAIL;
388
- if (answers.AUTHOR_WEBSITE) pkg.author.url = answers.AUTHOR_WEBSITE;
389
- }
390
-
391
- pkg.scripts = Object.assign({}, pkg.scripts, {
392
- "jpack:example": "node ./cli/jpack.js --action build --name example",
393
- "jpack:example-debug": "node ./cli/jpack.js --action build --name example --debug",
394
- "jpack:export": "node ./cli/jpack.js --action build --name perso",
395
- "jpack:export-debug": "node ./cli/jpack.js --action build --name perso --debug",
396
- "jpack:dist": "node ./cli/jpack.js",
397
- "jpack:dist-debug": "node ./cli/jpack.js --debug"
398
- });
399
-
400
- // force less dependency for now
401
- // @todo update builder to manage LESS not installed case
402
- answers.LESS = true;
403
- if (answers.LESS) {
404
- pkg.dependencies = Object.assign({}, pkg.dependencies, {
405
- "less": "^4.1.3"
406
- });
407
- }
408
-
409
- // remove empty fields
410
- Object.keys(pkg).forEach(key => {
411
- if (!pkg[key]) {
412
- delete pkg[key];
413
- }
414
- });
415
-
416
- composer.name = answers.GIT_MODULE;
417
- composer.type = composer.type || 'library';
418
- composer.license = answers.LICENSE || 'MIT';
419
- if (!composer.description) {
420
- composer.description = answers.DESCRIPTION || '';
421
- }
422
- if (!composer.keywords.length) {
423
- composer.keywords = answers.KEYWORDS || [];
424
- }
425
- if (!composer.homepage) {
426
- composer.homepage = answers.HOMEPAGE || '';
427
- }
428
-
429
- let author = null;
430
- if (answers.AUTHOR_NAME || answers.AUTHOR_EMAIL || answers.AUTHOR_WEBSITE) {
431
- author = {};
432
- if (answers.AUTHOR_NAME) author.name = answers.AUTHOR_NAME;
433
- if (answers.AUTHOR_EMAIL) author.email = answers.AUTHOR_EMAIL;
434
- if (answers.AUTHOR_WEBSITE) author.homepage = answers.AUTHOR_WEBSITE;
435
- author.role = 'Lead';
436
- }
437
-
438
- if (author) {
439
- if (composer.authors) {
440
- // check if the author is already present
441
- let found = false;
442
- composer.authors.forEach(author => {
443
- if (author.name === answers.AUTHOR_NAME &&
444
- author.email === answers.AUTHOR_EMAIL) {
445
- found = true;
446
- }
447
- });
448
- if (!found) {
449
- composer.authors.push(author);
450
- }
451
- }
452
- else {
453
- composer.authors = [];
454
- composer.authors.push(author);
455
- }
456
- }
457
-
458
- // remove empty fields
459
- Object.keys(composer).forEach(key => {
460
- if (!composer[key]) {
461
- delete composer[key];
462
- }
463
- });
464
-
465
- // display the content to be written for confirmation
466
- console.log('');
467
- console.log("The following content will be written to package.json:");
468
- console.log(JSON.stringify(pkg, null, 2));
469
- console.log('');
470
- console.log("The following content will be written to composer.json:");
471
- console.log(JSON.stringify(composer, null, 2));
472
- console.log('');
473
-
474
- const confirm = await askQuestion("Do you want to proceed? (y/N): ", null, 'N');
475
- if (confirm.toLowerCase().substr(0, 1) !== 'y') {
476
- console.log("Aborted..");
477
- process.exit(0);
478
- }
479
-
480
- fs.writeFileSync(path.join(baseDir, "package.json"), JSON.stringify(pkg, null, 2));
481
- fs.writeFileSync(path.join(baseDir, "composer.json"), JSON.stringify(composer, null, 2));
482
-
483
- //
484
-
485
- if (answers.LESS) {
486
- console.log('Check LESS install...');
487
-
488
- try {
489
- execSync('npm install less', { stdio: 'inherit', cwd: baseDir });
490
- console.log('✓ less package installed successfully');
491
- } catch (error) {
492
- console.error('✗ Failed to install less package:', error.message);
493
- console.log('You can install it manually with: npm install less or npm update');
494
- }
495
- }
496
-
497
- // console.log(srcDir);
498
- // console.log(baseDir);
499
- copyDefaultFiles(srcDir, baseDir, answers);
500
- console.log('✓ copied default files');
501
-
502
- // add an empty js file to start with
503
- const mainJsDir = path.join(baseDir, 'lib', 'js');
504
- if (!fs.existsSync(mainJsDir)) {
505
- fs.mkdirSync(mainJsDir, { recursive: true });
506
- }
507
- const mainJs = path.join(mainJsDir, answers.MODULE_NAME + '.js');
508
- if (!fs.existsSync(mainJs)) {
509
- fs.writeFileSync(mainJs, '', 'utf8');
510
- }
511
- console.log('✓ created main js file');
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { fileURLToPath } from "url";
4
+ import { execSync } from "child_process";
5
+
6
+ import {
7
+ loadYourConfig,
8
+ loadActualPackageJsonFile,
9
+ loadActualComposerJsonFile,
10
+ copyDefaultFiles,
11
+ askQuestion
12
+ } from "./helper.js";
13
+
14
+ const __filename = fileURLToPath(import.meta.url);
15
+ const __dirname = path.dirname(__filename);
16
+ const baseDir = process.cwd();
17
+ const srcDir = path.join(__dirname, "..", "_package");
18
+
19
+ console.log('current working directory:', baseDir);
20
+
21
+ let defaults = loadYourConfig(baseDir, { KEYWORDS_PREPEND: null });
22
+
23
+ const answers = {
24
+ MODULE_NAME: null,
25
+ MODULE_ALIAS: null,
26
+ DESCRIPTION: null,
27
+ KEYWORDS: null,
28
+ HOMEPAGE: null,
29
+ AUTHOR_NAME: null,
30
+ AUTHOR_EMAIL: null,
31
+ AUTHOR_WEBSITE: null,
32
+ GIT_MODULE: null,
33
+ GIT_ACCOUNT: null,
34
+ GIT_REPO: null,
35
+ LESS: null,
36
+ YEAR: null,
37
+ HOMEPAGE_PREFIX: null,
38
+ GIT_PREFIX: null
39
+ };
40
+
41
+ const packageJson = loadActualPackageJsonFile(baseDir, defaults);
42
+ defaults = packageJson.defaults;
43
+ const pkg = packageJson.pkg;
44
+
45
+ const composerJson = loadActualComposerJsonFile(baseDir, defaults);
46
+ defaults = composerJson.defaults;
47
+ const composer = composerJson.composer;
48
+
49
+ if (pkg.dependencies && pkg.dependencies.less) {
50
+ answers.LESS = true;
51
+ }
52
+
53
+ if (!defaults.YEAR) {
54
+ defaults.YEAR = new Date().getFullYear();
55
+ }
56
+
57
+ const folderName = path.basename(process.cwd());
58
+
59
+ if (!defaults.MODULE_NAME) {
60
+ // convert to CamelCase
61
+ defaults.MODULE_NAME = folderName.split(/[-_ ]+/)
62
+ .map(part => part.charAt(0).toUpperCase() + part.slice(1))
63
+ .join('');
64
+ }
65
+
66
+ console.log('');
67
+ console.log('****** Module Information');
68
+ answers.MODULE_NAME = await askQuestion("Module name* (e.g. ModuleName): ", answers.MODULE_NAME, defaults.MODULE_NAME);
69
+
70
+ if (!answers.MODULE_NAME) {
71
+ console.error("Module name is required.");
72
+ process.exit(1);
73
+ }
74
+
75
+ if (!defaults.MODULE_ALIAS) {
76
+ defaults.MODULE_ALIAS = folderName.replace(/([A-Z])/g, (g, m1, offset) => (offset > 0 ? '-' : '') + m1.toLowerCase());
77
+ }
78
+
79
+ answers.MODULE_ALIAS = await askQuestion("Module alias* (e.g. module-name): ", answers.MODULE_ALIAS, defaults.MODULE_ALIAS);
80
+ if (!answers.MODULE_ALIAS) {
81
+ console.error("Module alias is required.");
82
+ process.exit(1);
83
+ }
84
+
85
+ console.log('');
86
+ console.log('****** Git Repository Information');
87
+
88
+ if (!defaults.GIT_MODULE && defaults.GIT_PREFIX) {
89
+ defaults.GIT_MODULE = `${defaults.GIT_PREFIX}/${answers.MODULE_ALIAS}`;
90
+ }
91
+ answers.GIT_MODULE = await askQuestion("Git module (e.g. prefix/module-name): ", answers.GIT_MODULE, defaults.GIT_MODULE);
92
+ if (!answers.GIT_MODULE) {
93
+ console.error('Git module is required.');
94
+ process.exit(1);
95
+ }
96
+
97
+ const [defaultGitAccount, defaultGitRepo] = answers.GIT_MODULE.split('/');
98
+ if (!defaults.GIT_ACCOUNT) {
99
+ defaults.GIT_ACCOUNT = defaultGitAccount;
100
+ }
101
+ if (!defaults.GIT_REPO) {
102
+ defaults.GIT_REPO = defaultGitRepo;
103
+ }
104
+
105
+ answers.GIT_ACCOUNT = await askQuestion("Git account (e.g. your-account): ", answers.GIT_ACCOUNT, defaults.GIT_ACCOUNT);
106
+ answers.GIT_REPO = await askQuestion("Git repo (e.g. module-name): ", answers.GIT_REPO, defaults.GIT_REPO);
107
+
108
+ console.log('');
109
+ console.log('****** Author Information (optional)');
110
+
111
+ answers.AUTHOR_NAME = await askQuestion("Author name (e.g. Your Name): ", answers.AUTHOR_NAME, defaults.AUTHOR_NAME);
112
+ answers.AUTHOR_EMAIL = await askQuestion("Author email (e.g. your.email@example.com): ", answers.AUTHOR_EMAIL, defaults.AUTHOR_EMAIL);
113
+ answers.AUTHOR_WEBSITE = await askQuestion("Author website (e.g. https://your-website.com): ", answers.AUTHOR_WEBSITE, defaults.AUTHOR_WEBSITE);
114
+
115
+ console.log('');
116
+ console.log('****** Description, Keywords, Homepage');
117
+ console.log('Used in package.json and optionaly in composer.json');
118
+
119
+ answers.DESCRIPTION = await askQuestion("Description: ", answers.DESCRIPTION, defaults.DESCRIPTION);
120
+
121
+ defaults.KEYWORDS = [];
122
+ if (answers.GIT_PREFIX) {
123
+ defaults.KEYWORDS.push(answers.GIT_PREFIX);
124
+ }
125
+ defaults.KEYWORDS.push(answers.GIT_ACCOUNT);
126
+ defaults.KEYWORDS.push(answers.MODULE_NAME);
127
+
128
+ const keywordsInput = await askQuestion("Keywords (comma separated): ", answers.KEYWORDS ? answers.KEYWORDS.join(', ') : null, defaults.KEYWORDS.join(', '));
129
+ if (keywordsInput) {
130
+ answers.KEYWORDS = keywordsInput.split(',');
131
+ }
132
+ if (defaults.KEYWORDS_PREPEND) {
133
+ answers.KEYWORDS = [...defaults.KEYWORDS_PREPEND, ...answers.KEYWORDS];
134
+ }
135
+ answers.KEYWORDS = answers.KEYWORDS
136
+ .map(k => k.trim())
137
+ .filter(k => k.length > 0)
138
+ .map(k => k.toLowerCase());
139
+ // unique keywords
140
+ answers.KEYWORDS = Array.from(new Set(answers.KEYWORDS));
141
+
142
+ if (!defaults.HOMEPAGE && defaults.HOMEPAGE_PREFIX) {
143
+ defaults.HOMEPAGE_PREFIX = defaults.HOMEPAGE_PREFIX.replace(/^\/+|\/+$/g, '');
144
+ defaults.HOMEPAGE = `${defaults.HOMEPAGE_PREFIX}/${answers.MODULE_ALIAS}`;
145
+ }
146
+ answers.HOMEPAGE = await askQuestion("Homepage: ", answers.HOMEPAGE, defaults.HOMEPAGE);
147
+
148
+ console.log('');
149
+ console.log('****** LESS (optional)');
150
+ console.log('Used for styles compilation if needed');
151
+ if (answers.LESS === null) {
152
+ const lessInput = await askQuestion("Use LESS for styles? (y/N): ", null, 'N');
153
+ answers.LESS = (lessInput.toLowerCase() === 'y');
154
+ } else {
155
+ console.log(`LESS usage detected in existing package.json, keeping it as is.`);
156
+ }
157
+
158
+ answers.LICENSE = await askQuestion("License for package files: ", answers.LICENSE, defaults.LICENSE);
159
+ answers.YEAR = await askQuestion("Debut year for license file: ", answers.YEAR, defaults.YEAR);
160
+
161
+ pkg.name = answers.MODULE_ALIAS;
162
+ pkg.version = pkg.version || '1.0.0';
163
+ pkg.browser = pkg.browser || `dist/js/${answers.MODULE_ALIAS}.min.js`;
164
+ pkg.main = pkg.main || 'lib/index.js';
165
+ pkg.type = pkg.type || 'module';
166
+ pkg.jizy = 'dist/';
167
+ pkg.description = answers.DESCRIPTION || '';
168
+ pkg.keywords = answers.KEYWORDS || [];
169
+ pkg.homepage = answers.HOMEPAGE || '';
170
+ if (!pkg.files) {
171
+ pkg.files = [];
172
+ }
173
+ pkg.files.push('dist/*');
174
+ pkg.files.push('example/*');
175
+ pkg.files.push('lib/*');
176
+
177
+ // unique files
178
+ pkg.files = Array.from(new Set(pkg.files));
179
+
180
+ pkg.repository = {
181
+ type: "git",
182
+ url: `git+https://github.com/${answers.GIT_ACCOUNT}/${answers.GIT_REPO}.git`
183
+ };
184
+
185
+ if (answers.AUTHOR_NAME && answers.AUTHOR_EMAIL && answers.AUTHOR_WEBSITE) {
186
+ pkg.author = answers.AUTHOR_NAME + ' <' + answers.AUTHOR_EMAIL + '> (' + answers.AUTHOR_WEBSITE + ')';
187
+ } else if (answers.AUTHOR_NAME || answers.AUTHOR_EMAIL || answers.AUTHOR_WEBSITE) {
188
+ pkg.author = {};
189
+ if (answers.AUTHOR_NAME) pkg.author.name = answers.AUTHOR_NAME;
190
+ if (answers.AUTHOR_EMAIL) pkg.author.email = answers.AUTHOR_EMAIL;
191
+ if (answers.AUTHOR_WEBSITE) pkg.author.url = answers.AUTHOR_WEBSITE;
192
+ }
193
+
194
+ pkg.scripts = Object.assign({}, pkg.scripts, {
195
+ "jpack:example": "node ./cli/jpack.js --action build --name example",
196
+ "jpack:example-debug": "node ./cli/jpack.js --action build --name example --debug",
197
+ "jpack:export": "node ./cli/jpack.js --action build --name perso",
198
+ "jpack:export-debug": "node ./cli/jpack.js --action build --name perso --debug",
199
+ "jpack:dist": "node ./cli/jpack.js",
200
+ "jpack:dist-debug": "node ./cli/jpack.js --debug"
201
+ });
202
+
203
+ // force less dependency for now
204
+ // @todo update builder to manage LESS not installed case
205
+ answers.LESS = true;
206
+ if (answers.LESS) {
207
+ pkg.dependencies = Object.assign({}, pkg.dependencies, {
208
+ "less": "^4.5.1"
209
+ });
210
+ }
211
+
212
+ // remove empty fields
213
+ Object.keys(pkg).forEach(key => {
214
+ if (!pkg[key]) {
215
+ delete pkg[key];
216
+ }
217
+ });
218
+
219
+ composer.name = answers.GIT_MODULE;
220
+ composer.type = composer.type || 'library';
221
+ composer.license = answers.LICENSE || 'MIT';
222
+ if (!composer.description) {
223
+ composer.description = answers.DESCRIPTION || '';
224
+ }
225
+ if (!composer.keywords.length) {
226
+ composer.keywords = answers.KEYWORDS || [];
227
+ }
228
+ if (!composer.homepage) {
229
+ composer.homepage = answers.HOMEPAGE || '';
230
+ }
231
+
232
+ let author = null;
233
+ if (answers.AUTHOR_NAME || answers.AUTHOR_EMAIL || answers.AUTHOR_WEBSITE) {
234
+ author = {};
235
+ if (answers.AUTHOR_NAME) author.name = answers.AUTHOR_NAME;
236
+ if (answers.AUTHOR_EMAIL) author.email = answers.AUTHOR_EMAIL;
237
+ if (answers.AUTHOR_WEBSITE) author.homepage = answers.AUTHOR_WEBSITE;
238
+ author.role = 'Lead';
239
+ }
240
+
241
+ if (author) {
242
+ if (composer.authors) {
243
+ // check if the author is already present
244
+ let found = false;
245
+ composer.authors.forEach(author => {
246
+ if (author.name === answers.AUTHOR_NAME &&
247
+ author.email === answers.AUTHOR_EMAIL) {
248
+ found = true;
249
+ }
250
+ });
251
+ if (!found) {
252
+ composer.authors.push(author);
253
+ }
254
+ }
255
+ else {
256
+ composer.authors = [];
257
+ composer.authors.push(author);
258
+ }
259
+ }
260
+
261
+ // remove empty fields
262
+ Object.keys(composer).forEach(key => {
263
+ if (!composer[key]) {
264
+ delete composer[key];
265
+ }
266
+ });
267
+
268
+ // display the content to be written for confirmation
269
+ console.log('');
270
+ console.log("The following content will be written to package.json:");
271
+ console.log(JSON.stringify(pkg, null, 2));
272
+ console.log('');
273
+ console.log("The following content will be written to composer.json:");
274
+ console.log(JSON.stringify(composer, null, 2));
275
+ console.log('');
276
+
277
+ const confirm = await askQuestion("Do you want to proceed? (y/N): ", null, 'N');
278
+ if (confirm.toLowerCase().substr(0, 1) !== 'y') {
279
+ console.log("Aborted..");
280
+ process.exit(0);
281
+ }
282
+
283
+ fs.writeFileSync(path.join(baseDir, "package.json"), JSON.stringify(pkg, null, 2));
284
+ fs.writeFileSync(path.join(baseDir, "composer.json"), JSON.stringify(composer, null, 2));
285
+
286
+ //
287
+
288
+ if (answers.LESS) {
289
+ console.log('Check LESS install...');
290
+
291
+ try {
292
+ execSync('npm install less', { stdio: 'inherit', cwd: baseDir });
293
+ console.log('✓ less package installed successfully');
294
+ } catch (error) {
295
+ console.error('✗ Failed to install less package:', error.message);
296
+ console.log('You can install it manually with: npm install less or npm update');
297
+ }
298
+ }
299
+
300
+ copyDefaultFiles(srcDir, baseDir, answers);
301
+ console.log('✓ copied default files');
302
+
303
+ // add an empty js file to start with
304
+ const mainJsDir = path.join(baseDir, 'lib', 'js');
305
+ if (!fs.existsSync(mainJsDir)) {
306
+ fs.mkdirSync(mainJsDir, { recursive: true });
307
+ }
308
+ const mainJs = path.join(mainJsDir, answers.MODULE_NAME + '.js');
309
+ if (!fs.existsSync(mainJs)) {
310
+ fs.writeFileSync(mainJs, '', 'utf8');
311
+ }
312
+ console.log('✓ created main js file');
package/lib/Build.js CHANGED
@@ -130,7 +130,7 @@ export default async function jPackBuild({
130
130
  LogMe.log('---');
131
131
  LogMe.log('Build completed successfully');
132
132
  LogMe.log('---');
133
- process.exit(1);
133
+ process.exit(0);
134
134
  } catch (error) {
135
135
  LogMe.error(error.message);
136
136
  process.exit(1);
package/lib/Rollup.js CHANGED
@@ -12,7 +12,7 @@ import jPackConfig from "./Config.js";
12
12
  import LogMe from "./LogMe.js";
13
13
  import { emptyTargetPath, moveFolderFiles, mirrorExampleFiles } from './utils.js';
14
14
 
15
- export default async function jPackRollup(config) {
15
+ export default function jPackRollup() {
16
16
  return [
17
17
  {
18
18
  name: 'beforeBuild',
package/package.json CHANGED
@@ -1,14 +1,18 @@
1
1
  {
2
2
  "name": "jizy-packer",
3
- "version": "2.1.42",
3
+ "version": "2.1.44",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "_example",
7
7
  "_package",
8
8
  "cli/init.js",
9
+ "cli/helper.js",
9
10
  "lib/*.js"
10
11
  ],
11
12
  "main": "lib/index.js",
13
+ "scripts": {
14
+ "example": "node examples/my-widget.js"
15
+ },
12
16
  "repository": {
13
17
  "type": "git",
14
18
  "url": "git+https://github.com/joffreydemetz/jizy-packer.git"
@@ -25,11 +29,15 @@
25
29
  "@rollup/plugin-commonjs": "^28.0.3",
26
30
  "@rollup/plugin-json": "^6.1.0",
27
31
  "@rollup/plugin-node-resolve": "^16.0.1",
28
- "@rollup/plugin-terser": "^0.4.4",
32
+ "@rollup/plugin-terser": "^1.0.0",
29
33
  "@rollup/plugin-url": "^8.0.2",
30
34
  "postcss": "^8.5.3",
31
- "rollup": "^4.40.1",
35
+ "rollup": "^4.60.1",
32
36
  "rollup-plugin-postcss": "^4.0.2",
33
37
  "yargs": "^17.7.2"
38
+ },
39
+ "overrides": {
40
+ "svgo": "2.8.2",
41
+ "yaml@1": "1.10.3"
34
42
  }
35
- }
43
+ }