innetjs 2.2.0 → 2.2.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/bin/innet +47 -64
- package/constants.js +36 -0
- package/constants.mjs +30 -0
- package/extract.js +49 -0
- package/extract.mjs +45 -0
- package/helpers.js +54 -0
- package/helpers.mjs +41 -0
- package/index.d.ts +2 -1
- package/index.js +60 -181
- package/{index.es6.js → index.mjs} +43 -164
- package/package.json +14 -2
package/bin/innet
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
var commander = require('commander');
|
|
5
|
+
var tslib = require('tslib');
|
|
5
6
|
var logger = require('@cantinc/logger');
|
|
6
7
|
var commonjs = require('@rollup/plugin-commonjs');
|
|
7
8
|
var eslint = require('@rollup/plugin-eslint');
|
|
@@ -17,10 +18,10 @@ var express = require('express');
|
|
|
17
18
|
var proxy = require('express-http-proxy');
|
|
18
19
|
var fs = require('fs-extra');
|
|
19
20
|
var glob = require('glob');
|
|
20
|
-
var http = require('http');
|
|
21
|
-
var https = require('https');
|
|
21
|
+
var http = require('node:http');
|
|
22
|
+
var https = require('node:https');
|
|
22
23
|
var linesAndColumns = require('lines-and-columns');
|
|
23
|
-
var path$1 = require('path');
|
|
24
|
+
var path$1 = require('node:path');
|
|
24
25
|
var prompt = require('prompts');
|
|
25
26
|
var rollup = require('rollup');
|
|
26
27
|
var filesize = require('rollup-plugin-filesize');
|
|
@@ -33,7 +34,7 @@ var styles = require('rollup-plugin-styles');
|
|
|
33
34
|
var rollupPluginTerser = require('rollup-plugin-terser');
|
|
34
35
|
var typescript = require('rollup-plugin-typescript2');
|
|
35
36
|
var tmp = require('tmp');
|
|
36
|
-
var
|
|
37
|
+
var node_util = require('node:util');
|
|
37
38
|
var unzipper = require('unzipper');
|
|
38
39
|
|
|
39
40
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -66,31 +67,6 @@ var styles__default = /*#__PURE__*/_interopDefaultLegacy(styles);
|
|
|
66
67
|
var typescript__default = /*#__PURE__*/_interopDefaultLegacy(typescript);
|
|
67
68
|
var tmp__default = /*#__PURE__*/_interopDefaultLegacy(tmp);
|
|
68
69
|
|
|
69
|
-
/******************************************************************************
|
|
70
|
-
Copyright (c) Microsoft Corporation.
|
|
71
|
-
|
|
72
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
73
|
-
purpose with or without fee is hereby granted.
|
|
74
|
-
|
|
75
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
76
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
77
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
78
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
79
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
80
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
81
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
82
|
-
***************************************************************************** */
|
|
83
|
-
|
|
84
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
85
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
86
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
87
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
88
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
89
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
90
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
|
|
94
70
|
const lintInclude = [
|
|
95
71
|
'**/*.ts',
|
|
96
72
|
'**/*.tsx',
|
|
@@ -185,7 +161,7 @@ function getFile(file) {
|
|
|
185
161
|
return file;
|
|
186
162
|
}
|
|
187
163
|
function convertIndexFile(data, version, baseUrl) {
|
|
188
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
164
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
189
165
|
return data
|
|
190
166
|
.toString()
|
|
191
167
|
.replace('</head>', `<script type="module" defer src="${baseUrl}index.js${version ? `?v=${version}` : ''}"></script></head>`);
|
|
@@ -200,8 +176,8 @@ const livereload = require('rollup-plugin-livereload');
|
|
|
200
176
|
const { string } = require('rollup-plugin-string');
|
|
201
177
|
const { exec, spawn } = require('child_process');
|
|
202
178
|
const readline = require('readline');
|
|
203
|
-
const execAsync =
|
|
204
|
-
const copyFiles =
|
|
179
|
+
const execAsync = node_util.promisify(exec);
|
|
180
|
+
const copyFiles = node_util.promisify(fs__default["default"].copy);
|
|
205
181
|
const dotenvConfigOutput$1 = require('dotenv').config();
|
|
206
182
|
require('dotenv-expand').expand(dotenvConfigOutput$1);
|
|
207
183
|
const REG_CLEAR_TEXT = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g;
|
|
@@ -247,9 +223,9 @@ class InnetJS {
|
|
|
247
223
|
}
|
|
248
224
|
// Methods
|
|
249
225
|
init(appName, { template, force = false } = {}) {
|
|
250
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
226
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
251
227
|
const appPath = path__default["default"].resolve(appName);
|
|
252
|
-
const { data } = yield logger__default["default"].start('Get templates list', () => __awaiter(this, void 0, void 0, function* () { return yield axios__default["default"].get('https://api.github.com/repos/d8corp/innetjs-templates/branches'); }));
|
|
228
|
+
const { data } = yield logger__default["default"].start('Get templates list', () => tslib.__awaiter(this, void 0, void 0, function* () { return yield axios__default["default"].get('https://api.github.com/repos/d8corp/innetjs-templates/branches'); }));
|
|
253
229
|
const templates = data.map(({ name }) => name).filter(name => name !== 'main');
|
|
254
230
|
if (!template || !templates.includes(template)) {
|
|
255
231
|
logger__default["default"].log(chalk__default["default"].green('Select one of those templates'));
|
|
@@ -263,7 +239,7 @@ class InnetJS {
|
|
|
263
239
|
logger__default["default"].end(text);
|
|
264
240
|
}
|
|
265
241
|
if (!force) {
|
|
266
|
-
yield logger__default["default"].start('Check if app folder is available', () => __awaiter(this, void 0, void 0, function* () {
|
|
242
|
+
yield logger__default["default"].start('Check if app folder is available', () => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
267
243
|
if (fs__default["default"].existsSync(appPath)) {
|
|
268
244
|
logger__default["default"].log(chalk__default["default"].red(`'${appPath}' already exist, what do you want?`));
|
|
269
245
|
const { id: result, value } = yield selector__default["default"]({
|
|
@@ -280,7 +256,7 @@ class InnetJS {
|
|
|
280
256
|
}
|
|
281
257
|
}));
|
|
282
258
|
}
|
|
283
|
-
yield logger__default["default"].start('Download template', () => __awaiter(this, void 0, void 0, function* () {
|
|
259
|
+
yield logger__default["default"].start('Download template', () => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
284
260
|
const { data } = yield axios__default["default"].get(`https://github.com/d8corp/innetjs-templates/archive/refs/heads/${template}.zip`, {
|
|
285
261
|
responseType: 'stream',
|
|
286
262
|
});
|
|
@@ -294,7 +270,7 @@ class InnetJS {
|
|
|
294
270
|
});
|
|
295
271
|
}
|
|
296
272
|
build({ node = false, index = 'index' } = {}) {
|
|
297
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
273
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
298
274
|
const input = glob__default["default"].sync(`src/${index}.{${indexExt}}`);
|
|
299
275
|
if (!input.length) {
|
|
300
276
|
throw Error('index file is not detected');
|
|
@@ -350,7 +326,7 @@ class InnetJS {
|
|
|
350
326
|
}),
|
|
351
327
|
];
|
|
352
328
|
}
|
|
353
|
-
yield logger__default["default"].start('Build production bundle', () => __awaiter(this, void 0, void 0, function* () {
|
|
329
|
+
yield logger__default["default"].start('Build production bundle', () => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
354
330
|
const bundle = yield rollup__default["default"].rollup(inputOptions);
|
|
355
331
|
yield bundle.write(outputOptions);
|
|
356
332
|
yield bundle.close();
|
|
@@ -362,7 +338,7 @@ class InnetJS {
|
|
|
362
338
|
}
|
|
363
339
|
}));
|
|
364
340
|
if (pkg) {
|
|
365
|
-
yield logger__default["default"].start('Copy package.json', () => __awaiter(this, void 0, void 0, function* () {
|
|
341
|
+
yield logger__default["default"].start('Copy package.json', () => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
366
342
|
const data = Object.assign({}, pkg);
|
|
367
343
|
delete data.private;
|
|
368
344
|
delete data.devDependencies;
|
|
@@ -378,7 +354,7 @@ class InnetJS {
|
|
|
378
354
|
});
|
|
379
355
|
}
|
|
380
356
|
start({ node = false, error = false, index = 'index' } = {}) {
|
|
381
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
357
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
382
358
|
const pkg = yield this.getPackage();
|
|
383
359
|
const input = glob__default["default"].sync(`src/${index}.{${indexExt}}`);
|
|
384
360
|
if (!input.length) {
|
|
@@ -446,7 +422,7 @@ class InnetJS {
|
|
|
446
422
|
}), this.createClient(key, cert, pkg), livereload(Object.assign({ exts: ['html', 'css', 'js', 'png', 'svg', 'webp', 'gif', 'jpg', 'json'], watch: [this.devBuildFolder, this.publicFolder], verbose: false }, (key && cert ? { https: { key, cert } } : {}))), injectEnv__default["default"](innetEnv));
|
|
447
423
|
}
|
|
448
424
|
const watcher = rollup__default["default"].watch(options);
|
|
449
|
-
watcher.on('event', (e) => __awaiter(this, void 0, void 0, function* () {
|
|
425
|
+
watcher.on('event', (e) => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
450
426
|
if (e.code === 'ERROR') {
|
|
451
427
|
if (e.error.code === 'UNRESOLVED_IMPORT') {
|
|
452
428
|
const [, importer, file] = e.error.message.match(/^Could not resolve '(.+)' from (.+)$/) || [];
|
|
@@ -479,7 +455,7 @@ class InnetJS {
|
|
|
479
455
|
});
|
|
480
456
|
}
|
|
481
457
|
run(file) {
|
|
482
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
458
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
483
459
|
const input = yield logger__default["default"].start('Check file', () => getFile(file));
|
|
484
460
|
const folder = yield new Promise((resolve, reject) => {
|
|
485
461
|
tmp__default["default"].dir((err, folder) => {
|
|
@@ -492,7 +468,7 @@ class InnetJS {
|
|
|
492
468
|
});
|
|
493
469
|
});
|
|
494
470
|
const jsFilePath = `${folder}/index.js`;
|
|
495
|
-
yield logger__default["default"].start('Build bundle', () => __awaiter(this, void 0, void 0, function* () {
|
|
471
|
+
yield logger__default["default"].start('Build bundle', () => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
496
472
|
const inputOptions = {
|
|
497
473
|
input,
|
|
498
474
|
plugins: [
|
|
@@ -517,17 +493,17 @@ class InnetJS {
|
|
|
517
493
|
yield bundle.write(outputOptions);
|
|
518
494
|
yield bundle.close();
|
|
519
495
|
}));
|
|
520
|
-
yield logger__default["default"].start('Running of the script', () => __awaiter(this, void 0, void 0, function* () {
|
|
496
|
+
yield logger__default["default"].start('Running of the script', () => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
521
497
|
spawn('node', ['-r', 'source-map-support/register', jsFilePath], { stdio: 'inherit' });
|
|
522
498
|
}));
|
|
523
499
|
});
|
|
524
500
|
}
|
|
525
|
-
release({ node = false, index = 'index', release, } = {}) {
|
|
526
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
501
|
+
release({ node = false, index = 'index', release, pub } = {}) {
|
|
502
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
527
503
|
const { releaseFolder, cssModules } = this;
|
|
528
504
|
yield logger__default["default"].start('Remove previous release', () => fs__default["default"].remove(releaseFolder));
|
|
529
505
|
const pkg = yield this.getPackage();
|
|
530
|
-
yield logger__default["default"].start('Prepare package.json', () => __awaiter(this, void 0, void 0, function* () {
|
|
506
|
+
yield logger__default["default"].start('Prepare package.json', () => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
531
507
|
const version = pkg.version.split('.');
|
|
532
508
|
switch (release) {
|
|
533
509
|
case 'patch': {
|
|
@@ -552,7 +528,7 @@ class InnetJS {
|
|
|
552
528
|
}));
|
|
553
529
|
function build(format) {
|
|
554
530
|
var _a, _b;
|
|
555
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
531
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
556
532
|
const ext = format === 'es'
|
|
557
533
|
? ((_a = (pkg.module || pkg.esnext || pkg['jsnext:main'])) === null || _a === void 0 ? void 0 : _a.replace('index', '')) || '.mjs'
|
|
558
534
|
: ((_b = pkg.main) === null || _b === void 0 ? void 0 : _b.replace('index', '')) || '.js';
|
|
@@ -618,20 +594,20 @@ class InnetJS {
|
|
|
618
594
|
yield bundle.close();
|
|
619
595
|
});
|
|
620
596
|
}
|
|
621
|
-
yield logger__default["default"].start('Build cjs bundle', () => __awaiter(this, void 0, void 0, function* () {
|
|
597
|
+
yield logger__default["default"].start('Build cjs bundle', () => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
622
598
|
yield build('cjs');
|
|
623
599
|
}));
|
|
624
|
-
yield logger__default["default"].start('Build es6 bundle', () => __awaiter(this, void 0, void 0, function* () {
|
|
600
|
+
yield logger__default["default"].start('Build es6 bundle', () => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
625
601
|
yield build('es');
|
|
626
602
|
}));
|
|
627
|
-
yield logger__default["default"].start('Copy package.json', () => __awaiter(this, void 0, void 0, function* () {
|
|
603
|
+
yield logger__default["default"].start('Copy package.json', () => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
628
604
|
const data = Object.assign({}, pkg);
|
|
629
605
|
delete data.private;
|
|
630
606
|
delete data.devDependencies;
|
|
631
607
|
yield fs__default["default"].writeFile(path__default["default"].resolve(this.releaseFolder, 'package.json'), JSON.stringify(data, undefined, 2), 'UTF-8');
|
|
632
608
|
}));
|
|
633
609
|
if (pkg.bin) {
|
|
634
|
-
yield logger__default["default"].start('Build bin', () => __awaiter(this, void 0, void 0, function* () {
|
|
610
|
+
yield logger__default["default"].start('Build bin', () => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
635
611
|
const { bin } = pkg;
|
|
636
612
|
for (const name in bin) {
|
|
637
613
|
const value = bin[name];
|
|
@@ -666,29 +642,35 @@ class InnetJS {
|
|
|
666
642
|
}));
|
|
667
643
|
}
|
|
668
644
|
if (fs__default["default"].existsSync(this.licenseFile)) {
|
|
669
|
-
yield logger__default["default"].start('Copy license', () => __awaiter(this, void 0, void 0, function* () {
|
|
645
|
+
yield logger__default["default"].start('Copy license', () => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
670
646
|
yield fs.promises.copyFile(this.licenseFile, this.licenseReleaseFile);
|
|
671
647
|
}));
|
|
672
648
|
}
|
|
673
649
|
if (fs__default["default"].existsSync(this.readmeFile)) {
|
|
674
|
-
yield logger__default["default"].start('Copy readme', () => __awaiter(this, void 0, void 0, function* () {
|
|
650
|
+
yield logger__default["default"].start('Copy readme', () => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
675
651
|
yield fs.promises.copyFile(this.readmeFile, this.readmeReleaseFile);
|
|
676
652
|
}));
|
|
677
653
|
}
|
|
678
654
|
if (fs__default["default"].existsSync(this.declarationFile)) {
|
|
679
|
-
yield logger__default["default"].start('Copy declaration', () => __awaiter(this, void 0, void 0, function* () {
|
|
655
|
+
yield logger__default["default"].start('Copy declaration', () => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
680
656
|
yield fs.promises.copyFile(this.declarationFile, this.declarationReleaseFile);
|
|
681
657
|
}));
|
|
682
658
|
}
|
|
659
|
+
if (pub) {
|
|
660
|
+
const date = (Date.now() / 1000) | 0;
|
|
661
|
+
yield logger__default["default"].start(`publishing v${pkg.version} ${date}`, () => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
662
|
+
yield execAsync(`npm publish ${this.releaseFolder}`);
|
|
663
|
+
}));
|
|
664
|
+
}
|
|
683
665
|
});
|
|
684
666
|
}
|
|
685
667
|
getPackage() {
|
|
686
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
668
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
687
669
|
if (this.package) {
|
|
688
670
|
return this.package;
|
|
689
671
|
}
|
|
690
672
|
const packageFolder = path__default["default"].resolve(this.projectFolder, 'package.json');
|
|
691
|
-
yield logger__default["default"].start('Check package.json', () => __awaiter(this, void 0, void 0, function* () {
|
|
673
|
+
yield logger__default["default"].start('Check package.json', () => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
692
674
|
if (fs__default["default"].existsSync(packageFolder)) {
|
|
693
675
|
this.package = yield fs__default["default"].readJson(packageFolder);
|
|
694
676
|
}
|
|
@@ -700,11 +682,11 @@ class InnetJS {
|
|
|
700
682
|
let app;
|
|
701
683
|
return {
|
|
702
684
|
name: 'client',
|
|
703
|
-
writeBundle: () => __awaiter(this, void 0, void 0, function* () {
|
|
685
|
+
writeBundle: () => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
704
686
|
var _a;
|
|
705
687
|
if (!app) {
|
|
706
688
|
app = express__default["default"]();
|
|
707
|
-
const update = () => __awaiter(this, void 0, void 0, function* () {
|
|
689
|
+
const update = () => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
708
690
|
const data = yield fs.promises.readFile(this.publicIndexFile);
|
|
709
691
|
yield fs.promises.writeFile(this.devBuildIndexFile, yield convertIndexFile(data, pkg.version, this.baseUrl));
|
|
710
692
|
});
|
|
@@ -728,7 +710,7 @@ class InnetJS {
|
|
|
728
710
|
console.log(`${chalk__default["default"].green('➤')} Started on http${httpsUsing ? 's' : ''}://localhost:${port} and http${httpsUsing ? 's' : ''}://${address__default["default"].ip()}:${port}`);
|
|
729
711
|
};
|
|
730
712
|
server.listen(port, listener);
|
|
731
|
-
server.on('error', (e) => __awaiter(this, void 0, void 0, function* () {
|
|
713
|
+
server.on('error', (e) => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
732
714
|
if (e.code === 'EADDRINUSE') {
|
|
733
715
|
port++;
|
|
734
716
|
const { userPort } = yield prompt__default["default"]({
|
|
@@ -753,7 +735,7 @@ class InnetJS {
|
|
|
753
735
|
let app;
|
|
754
736
|
return {
|
|
755
737
|
name: 'server',
|
|
756
|
-
writeBundle: () => __awaiter(this, void 0, void 0, function* () {
|
|
738
|
+
writeBundle: () => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
757
739
|
app === null || app === void 0 ? void 0 : app.kill();
|
|
758
740
|
const filePath = path__default["default"].resolve(this.devBuildFolder, 'index.js');
|
|
759
741
|
app = spawn('node', ['-r', 'source-map-support/register', filePath], { stdio: 'inherit' });
|
|
@@ -827,13 +809,14 @@ commander.program
|
|
|
827
809
|
});
|
|
828
810
|
commander.program
|
|
829
811
|
.command('release')
|
|
830
|
-
.description('Release new version of
|
|
812
|
+
.description('Release new version of your library')
|
|
831
813
|
.option('-n, --node', 'Release for node.js')
|
|
832
814
|
.option('-i, --index <index>', 'Root index file name', 'index')
|
|
815
|
+
.option('-p, --public', 'Public the package')
|
|
833
816
|
.addOption(releaseOption)
|
|
834
817
|
.addOption(errorOption)
|
|
835
|
-
.action(({ error, node, index, release }) => {
|
|
836
|
-
innetJS.release({ node, index, release }).catch(e => {
|
|
818
|
+
.action(({ error, node, index, release, public: pub }) => {
|
|
819
|
+
innetJS.release({ node, index, release, pub }).catch(e => {
|
|
837
820
|
if (error) {
|
|
838
821
|
console.error(e);
|
|
839
822
|
process.exit(1);
|
package/constants.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const lintInclude = [
|
|
6
|
+
'**/*.ts',
|
|
7
|
+
'**/*.tsx',
|
|
8
|
+
'**/*.js',
|
|
9
|
+
'**/*.jsx',
|
|
10
|
+
];
|
|
11
|
+
const stringExcludeDom = [
|
|
12
|
+
'**/*.ts',
|
|
13
|
+
'**/*.tsx',
|
|
14
|
+
'**/*.js',
|
|
15
|
+
'**/*.jsx',
|
|
16
|
+
'**/*.json',
|
|
17
|
+
'**/*.css',
|
|
18
|
+
'**/*.scss',
|
|
19
|
+
'**/*.webp',
|
|
20
|
+
'**/*.gif',
|
|
21
|
+
'**/*.png',
|
|
22
|
+
'**/*.jpeg',
|
|
23
|
+
'**/*.jpg',
|
|
24
|
+
'**/*.svg',
|
|
25
|
+
];
|
|
26
|
+
const stringExcludeNode = [
|
|
27
|
+
'**/*.ts',
|
|
28
|
+
'**/*.tsx',
|
|
29
|
+
'**/*.js',
|
|
30
|
+
'**/*.jsx',
|
|
31
|
+
'**/*.json',
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
exports.lintInclude = lintInclude;
|
|
35
|
+
exports.stringExcludeDom = stringExcludeDom;
|
|
36
|
+
exports.stringExcludeNode = stringExcludeNode;
|
package/constants.mjs
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const lintInclude = [
|
|
2
|
+
'**/*.ts',
|
|
3
|
+
'**/*.tsx',
|
|
4
|
+
'**/*.js',
|
|
5
|
+
'**/*.jsx',
|
|
6
|
+
];
|
|
7
|
+
const stringExcludeDom = [
|
|
8
|
+
'**/*.ts',
|
|
9
|
+
'**/*.tsx',
|
|
10
|
+
'**/*.js',
|
|
11
|
+
'**/*.jsx',
|
|
12
|
+
'**/*.json',
|
|
13
|
+
'**/*.css',
|
|
14
|
+
'**/*.scss',
|
|
15
|
+
'**/*.webp',
|
|
16
|
+
'**/*.gif',
|
|
17
|
+
'**/*.png',
|
|
18
|
+
'**/*.jpeg',
|
|
19
|
+
'**/*.jpg',
|
|
20
|
+
'**/*.svg',
|
|
21
|
+
];
|
|
22
|
+
const stringExcludeNode = [
|
|
23
|
+
'**/*.ts',
|
|
24
|
+
'**/*.tsx',
|
|
25
|
+
'**/*.js',
|
|
26
|
+
'**/*.jsx',
|
|
27
|
+
'**/*.json',
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
export { lintInclude, stringExcludeDom, stringExcludeNode };
|
package/extract.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var unzipper = require('unzipper');
|
|
6
|
+
|
|
7
|
+
const Writer = require('fstream').Writer;
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const stream = require('stream');
|
|
10
|
+
const duplexer2 = require('duplexer2');
|
|
11
|
+
const Promise$1 = require('bluebird');
|
|
12
|
+
function Extract(opts, template) {
|
|
13
|
+
const reduceCount = 19 + template.length;
|
|
14
|
+
// make sure path is normalized before using it
|
|
15
|
+
opts.path = path.resolve(path.normalize(opts.path));
|
|
16
|
+
// @ts-expect-error
|
|
17
|
+
const parser = new unzipper.Parse(opts);
|
|
18
|
+
const outStream = new stream.Writable({ objectMode: true });
|
|
19
|
+
outStream._write = function (entry, encoding, cb) {
|
|
20
|
+
if (entry.type === 'Directory')
|
|
21
|
+
return cb();
|
|
22
|
+
const extractPath = path.join(opts.path, entry.path.slice(reduceCount));
|
|
23
|
+
if (extractPath.indexOf(opts.path) !== 0) {
|
|
24
|
+
return cb();
|
|
25
|
+
}
|
|
26
|
+
const writer = opts.getWriter ? opts.getWriter({ path: extractPath }) : Writer({ path: extractPath });
|
|
27
|
+
entry.pipe(writer)
|
|
28
|
+
.on('error', cb)
|
|
29
|
+
.on('close', cb);
|
|
30
|
+
};
|
|
31
|
+
const extract = duplexer2(parser, outStream);
|
|
32
|
+
parser.once('crx-header', function (crxHeader) {
|
|
33
|
+
extract.crxHeader = crxHeader;
|
|
34
|
+
});
|
|
35
|
+
parser
|
|
36
|
+
.pipe(outStream)
|
|
37
|
+
.on('finish', function () {
|
|
38
|
+
extract.emit('close');
|
|
39
|
+
});
|
|
40
|
+
extract.promise = function () {
|
|
41
|
+
return new Promise$1(function (resolve, reject) {
|
|
42
|
+
extract.on('close', resolve);
|
|
43
|
+
extract.on('error', reject);
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
return extract;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
exports.Extract = Extract;
|
package/extract.mjs
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Parse } from 'unzipper';
|
|
2
|
+
|
|
3
|
+
const Writer = require('fstream').Writer;
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const stream = require('stream');
|
|
6
|
+
const duplexer2 = require('duplexer2');
|
|
7
|
+
const Promise$1 = require('bluebird');
|
|
8
|
+
function Extract(opts, template) {
|
|
9
|
+
const reduceCount = 19 + template.length;
|
|
10
|
+
// make sure path is normalized before using it
|
|
11
|
+
opts.path = path.resolve(path.normalize(opts.path));
|
|
12
|
+
// @ts-expect-error
|
|
13
|
+
const parser = new Parse(opts);
|
|
14
|
+
const outStream = new stream.Writable({ objectMode: true });
|
|
15
|
+
outStream._write = function (entry, encoding, cb) {
|
|
16
|
+
if (entry.type === 'Directory')
|
|
17
|
+
return cb();
|
|
18
|
+
const extractPath = path.join(opts.path, entry.path.slice(reduceCount));
|
|
19
|
+
if (extractPath.indexOf(opts.path) !== 0) {
|
|
20
|
+
return cb();
|
|
21
|
+
}
|
|
22
|
+
const writer = opts.getWriter ? opts.getWriter({ path: extractPath }) : Writer({ path: extractPath });
|
|
23
|
+
entry.pipe(writer)
|
|
24
|
+
.on('error', cb)
|
|
25
|
+
.on('close', cb);
|
|
26
|
+
};
|
|
27
|
+
const extract = duplexer2(parser, outStream);
|
|
28
|
+
parser.once('crx-header', function (crxHeader) {
|
|
29
|
+
extract.crxHeader = crxHeader;
|
|
30
|
+
});
|
|
31
|
+
parser
|
|
32
|
+
.pipe(outStream)
|
|
33
|
+
.on('finish', function () {
|
|
34
|
+
extract.emit('close');
|
|
35
|
+
});
|
|
36
|
+
extract.promise = function () {
|
|
37
|
+
return new Promise$1(function (resolve, reject) {
|
|
38
|
+
extract.on('close', resolve);
|
|
39
|
+
extract.on('error', reject);
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
return extract;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { Extract };
|
package/helpers.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var tslib = require('tslib');
|
|
6
|
+
var logger = require('@cantinc/logger');
|
|
7
|
+
var chalk = require('chalk');
|
|
8
|
+
var fs = require('fs-extra');
|
|
9
|
+
var path = require('node:path');
|
|
10
|
+
|
|
11
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
12
|
+
|
|
13
|
+
var logger__default = /*#__PURE__*/_interopDefaultLegacy(logger);
|
|
14
|
+
var chalk__default = /*#__PURE__*/_interopDefaultLegacy(chalk);
|
|
15
|
+
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
16
|
+
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
17
|
+
|
|
18
|
+
function getFile(file) {
|
|
19
|
+
file = path__default["default"].resolve(file);
|
|
20
|
+
if (!fs__default["default"].existsSync(file)) {
|
|
21
|
+
throw Error('Cannot find the file: ' + file);
|
|
22
|
+
}
|
|
23
|
+
if (fs__default["default"].lstatSync(file).isDirectory()) {
|
|
24
|
+
let tmpFile = file;
|
|
25
|
+
if (!fs__default["default"].existsSync(tmpFile = path__default["default"].join(file, 'index.ts')) &&
|
|
26
|
+
!fs__default["default"].existsSync(tmpFile = path__default["default"].join(file, 'index.tsx')) &&
|
|
27
|
+
!fs__default["default"].existsSync(tmpFile = path__default["default"].join(file, 'index.js'))) {
|
|
28
|
+
throw Error('Cannot find index file in: ' + file);
|
|
29
|
+
}
|
|
30
|
+
file = tmpFile;
|
|
31
|
+
}
|
|
32
|
+
else if (!file.endsWith('.ts') && !file.endsWith('.tsx') && !file.endsWith('.js')) {
|
|
33
|
+
throw Error('File should has `.ts` or `.tsx` or `.js` extension: ' + file);
|
|
34
|
+
}
|
|
35
|
+
if (!fs__default["default"].existsSync(file)) {
|
|
36
|
+
throw Error('Cannot find the file: ' + file);
|
|
37
|
+
}
|
|
38
|
+
return file;
|
|
39
|
+
}
|
|
40
|
+
function convertIndexFile(data, version, baseUrl) {
|
|
41
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
return data
|
|
43
|
+
.toString()
|
|
44
|
+
.replace('</head>', `<script type="module" defer src="${baseUrl}index.js${version ? `?v=${version}` : ''}"></script></head>`);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
const reporter = (options, outputOptions, info) => {
|
|
48
|
+
logger__default["default"].log(`${chalk__default["default"].yellow(info.fileName)} ${chalk__default["default"].green(info.bundleSize)} [ gzip: ${chalk__default["default"].green(info.gzipSize)} ]`);
|
|
49
|
+
return '';
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
exports.convertIndexFile = convertIndexFile;
|
|
53
|
+
exports.getFile = getFile;
|
|
54
|
+
exports.reporter = reporter;
|
package/helpers.mjs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { __awaiter } from 'tslib';
|
|
2
|
+
import logger from '@cantinc/logger';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import fs from 'fs-extra';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
|
|
7
|
+
function getFile(file) {
|
|
8
|
+
file = path.resolve(file);
|
|
9
|
+
if (!fs.existsSync(file)) {
|
|
10
|
+
throw Error('Cannot find the file: ' + file);
|
|
11
|
+
}
|
|
12
|
+
if (fs.lstatSync(file).isDirectory()) {
|
|
13
|
+
let tmpFile = file;
|
|
14
|
+
if (!fs.existsSync(tmpFile = path.join(file, 'index.ts')) &&
|
|
15
|
+
!fs.existsSync(tmpFile = path.join(file, 'index.tsx')) &&
|
|
16
|
+
!fs.existsSync(tmpFile = path.join(file, 'index.js'))) {
|
|
17
|
+
throw Error('Cannot find index file in: ' + file);
|
|
18
|
+
}
|
|
19
|
+
file = tmpFile;
|
|
20
|
+
}
|
|
21
|
+
else if (!file.endsWith('.ts') && !file.endsWith('.tsx') && !file.endsWith('.js')) {
|
|
22
|
+
throw Error('File should has `.ts` or `.tsx` or `.js` extension: ' + file);
|
|
23
|
+
}
|
|
24
|
+
if (!fs.existsSync(file)) {
|
|
25
|
+
throw Error('Cannot find the file: ' + file);
|
|
26
|
+
}
|
|
27
|
+
return file;
|
|
28
|
+
}
|
|
29
|
+
function convertIndexFile(data, version, baseUrl) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
return data
|
|
32
|
+
.toString()
|
|
33
|
+
.replace('</head>', `<script type="module" defer src="${baseUrl}index.js${version ? `?v=${version}` : ''}"></script></head>`);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
const reporter = (options, outputOptions, info) => {
|
|
37
|
+
logger.log(`${chalk.yellow(info.fileName)} ${chalk.green(info.bundleSize)} [ gzip: ${chalk.green(info.gzipSize)} ]`);
|
|
38
|
+
return '';
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export { convertIndexFile, getFile, reporter };
|
package/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export interface ReleaseOptions {
|
|
|
3
3
|
node?: boolean;
|
|
4
4
|
index?: string;
|
|
5
5
|
release?: string;
|
|
6
|
+
pub?: boolean;
|
|
6
7
|
}
|
|
7
8
|
export declare const scriptExtensions: string[];
|
|
8
9
|
export declare const indexExt: string;
|
|
@@ -59,7 +60,7 @@ export declare class InnetJS {
|
|
|
59
60
|
index?: string;
|
|
60
61
|
}): Promise<void>;
|
|
61
62
|
run(file: any): Promise<void>;
|
|
62
|
-
release({ node, index, release, }?: ReleaseOptions): Promise<void>;
|
|
63
|
+
release({ node, index, release, pub }?: ReleaseOptions): Promise<void>;
|
|
63
64
|
getPackage(): Promise<Record<string, any>>;
|
|
64
65
|
createClient(key: any, cert: any, pkg: any): rollup.Plugin;
|
|
65
66
|
createServer(): rollup.Plugin;
|