innetjs 2.0.1 → 2.0.4
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 +126 -57
- package/constants.d.ts +3 -0
- package/helpers.d.ts +5 -0
- package/index.es6.js +123 -56
- package/index.js +125 -56
- package/package.json +4 -1
package/bin/innet
CHANGED
|
@@ -21,9 +21,12 @@ var json = require('@rollup/plugin-json');
|
|
|
21
21
|
var tmp = require('tmp');
|
|
22
22
|
var proxy = require('express-http-proxy');
|
|
23
23
|
var selector = require('cli-select');
|
|
24
|
+
var prompt = require('prompts');
|
|
24
25
|
var jsx = require('rollup-plugin-innet-jsx');
|
|
25
26
|
var filesize = require('rollup-plugin-filesize');
|
|
26
27
|
var image = require('@rollup/plugin-image');
|
|
28
|
+
var eslint = require('@rollup/plugin-eslint');
|
|
29
|
+
var linesAndColumns = require('lines-and-columns');
|
|
27
30
|
var unzipper = require('unzipper');
|
|
28
31
|
var commander = require('commander');
|
|
29
32
|
|
|
@@ -46,9 +49,11 @@ var json__default = /*#__PURE__*/_interopDefaultLegacy(json);
|
|
|
46
49
|
var tmp__default = /*#__PURE__*/_interopDefaultLegacy(tmp);
|
|
47
50
|
var proxy__default = /*#__PURE__*/_interopDefaultLegacy(proxy);
|
|
48
51
|
var selector__default = /*#__PURE__*/_interopDefaultLegacy(selector);
|
|
52
|
+
var prompt__default = /*#__PURE__*/_interopDefaultLegacy(prompt);
|
|
49
53
|
var jsx__default = /*#__PURE__*/_interopDefaultLegacy(jsx);
|
|
50
54
|
var filesize__default = /*#__PURE__*/_interopDefaultLegacy(filesize);
|
|
51
55
|
var image__default = /*#__PURE__*/_interopDefaultLegacy(image);
|
|
56
|
+
var eslint__default = /*#__PURE__*/_interopDefaultLegacy(eslint);
|
|
52
57
|
|
|
53
58
|
/******************************************************************************
|
|
54
59
|
Copyright (c) Microsoft Corporation.
|
|
@@ -117,13 +122,35 @@ function Extract(opts, template) {
|
|
|
117
122
|
return extract;
|
|
118
123
|
}
|
|
119
124
|
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
const lintIncludeDom = [
|
|
126
|
+
'**/*.ts',
|
|
127
|
+
'**/*.tsx',
|
|
128
|
+
'**/*.js',
|
|
129
|
+
'**/*.jsx',
|
|
130
|
+
];
|
|
131
|
+
const stringExcludeDom = [
|
|
132
|
+
'**/*.ts',
|
|
133
|
+
'**/*.tsx',
|
|
134
|
+
'**/*.js',
|
|
135
|
+
'**/*.jsx',
|
|
136
|
+
'**/*.json',
|
|
137
|
+
'**/*.css',
|
|
138
|
+
'**/*.scss',
|
|
139
|
+
'**/*.webp',
|
|
140
|
+
'**/*.gif',
|
|
141
|
+
'**/*.png',
|
|
142
|
+
'**/*.jpeg',
|
|
143
|
+
'**/*.jpg',
|
|
144
|
+
'**/*.svg',
|
|
145
|
+
];
|
|
146
|
+
const stringExcludeNode = [
|
|
147
|
+
'**/*.ts',
|
|
148
|
+
'**/*.tsx',
|
|
149
|
+
'**/*.js',
|
|
150
|
+
'**/*.jsx',
|
|
151
|
+
'**/*.json',
|
|
152
|
+
];
|
|
153
|
+
|
|
127
154
|
function getFile(file) {
|
|
128
155
|
file = path__default["default"].resolve(file);
|
|
129
156
|
if (!fs__default["default"].existsSync(file)) {
|
|
@@ -156,31 +183,17 @@ function convertIndexFile(data, version) {
|
|
|
156
183
|
const reporter = (options, outputOptions, info) => {
|
|
157
184
|
logger__default["default"].log(`${chalk__default["default"].yellow(info.fileName)} ${chalk__default["default"].green(info.bundleSize)} [ gzip: ${chalk__default["default"].green(info.gzipSize)} ]`);
|
|
158
185
|
return '';
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
'**/*.webp',
|
|
169
|
-
'**/*.gif',
|
|
170
|
-
'**/*.png',
|
|
171
|
-
'**/*.jpeg',
|
|
172
|
-
'**/*.jpg',
|
|
173
|
-
'**/*.svg',
|
|
174
|
-
];
|
|
175
|
-
const stringExcludeNode = [
|
|
176
|
-
'**/*.ts',
|
|
177
|
-
'**/*.tsx',
|
|
178
|
-
'**/*.js',
|
|
179
|
-
'**/*.jsx',
|
|
180
|
-
'**/*.json',
|
|
181
|
-
];
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
const livereload = require('rollup-plugin-livereload');
|
|
189
|
+
const { string } = require('rollup-plugin-string');
|
|
190
|
+
const { exec, spawn } = require('child_process');
|
|
191
|
+
const readline = require('readline');
|
|
192
|
+
const execAsync = util.promisify(exec);
|
|
193
|
+
const copyFiles = util.promisify(fs__default["default"].copy);
|
|
194
|
+
require('dotenv').config();
|
|
182
195
|
class InnetJS {
|
|
183
|
-
constructor({ projectFolder = process.env.PROJECT_FOLDER || '', publicFolder = process.env.PUBLIC_FOLDER || 'public', buildFolder = process.env.BUILD_FOLDER || 'build', srcFolder = process.env.SRC_FOLDER || 'src', sourcemap = process.env.SOURCEMAP ? process.env.SOURCEMAP === 'true' : false, cssModules = process.env.CSS_MODULES ? process.env.CSS_MODULES === 'true' : true, cssInJs = process.env.CSS_IN_JS ? process.env.CSS_IN_JS === 'true' : true, sslKey = process.env.SSL_KEY || 'localhost.key', sslCrt = process.env.SSL_CRT || 'localhost.crt', proxy = process.env.PROXY || '', port = process.env.PORT ? +process.env.PORT : 3000, api = process.env.API || '
|
|
196
|
+
constructor({ projectFolder = process.env.PROJECT_FOLDER || '', publicFolder = process.env.PUBLIC_FOLDER || 'public', buildFolder = process.env.BUILD_FOLDER || 'build', srcFolder = process.env.SRC_FOLDER || 'src', sourcemap = process.env.SOURCEMAP ? process.env.SOURCEMAP === 'true' : false, cssModules = process.env.CSS_MODULES ? process.env.CSS_MODULES === 'true' : true, cssInJs = process.env.CSS_IN_JS ? process.env.CSS_IN_JS === 'true' : true, sslKey = process.env.SSL_KEY || 'localhost.key', sslCrt = process.env.SSL_CRT || 'localhost.crt', proxy = process.env.PROXY || '', port = process.env.PORT ? +process.env.PORT : 3000, api = process.env.API || '/api/?*', } = {}) {
|
|
184
197
|
this.projectFolder = path__default["default"].resolve(projectFolder);
|
|
185
198
|
this.publicFolder = path__default["default"].resolve(publicFolder);
|
|
186
199
|
this.buildFolder = path__default["default"].resolve(buildFolder);
|
|
@@ -276,17 +289,26 @@ class InnetJS {
|
|
|
276
289
|
}));
|
|
277
290
|
}
|
|
278
291
|
else {
|
|
279
|
-
inputOptions.plugins
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
292
|
+
inputOptions.plugins = [
|
|
293
|
+
eslint__default["default"]({
|
|
294
|
+
include: lintIncludeDom,
|
|
295
|
+
}),
|
|
296
|
+
...inputOptions.plugins,
|
|
297
|
+
pluginNodeResolve.nodeResolve(),
|
|
298
|
+
image__default["default"](),
|
|
299
|
+
styles__default["default"]({
|
|
300
|
+
mode: this.cssInJs ? 'inject' : 'extract',
|
|
301
|
+
url: true,
|
|
302
|
+
plugins: [autoprefixer__default["default"]()],
|
|
303
|
+
modules: this.cssModules,
|
|
304
|
+
sourceMap: this.sourcemap,
|
|
305
|
+
minimize: true,
|
|
306
|
+
}),
|
|
307
|
+
string({
|
|
308
|
+
include: '**/*.*',
|
|
309
|
+
exclude: stringExcludeDom,
|
|
310
|
+
}),
|
|
311
|
+
];
|
|
290
312
|
outputOptions.format = 'es';
|
|
291
313
|
outputOptions.plugins = [
|
|
292
314
|
rollupPluginTerser.terser(),
|
|
@@ -369,21 +391,49 @@ class InnetJS {
|
|
|
369
391
|
? fs__default["default"].readFileSync(this.sslCrt)
|
|
370
392
|
: undefined;
|
|
371
393
|
options.output.format = 'es';
|
|
372
|
-
options.plugins
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
394
|
+
options.plugins = [
|
|
395
|
+
eslint__default["default"]({
|
|
396
|
+
include: lintIncludeDom,
|
|
397
|
+
}),
|
|
398
|
+
...options.plugins,
|
|
399
|
+
pluginNodeResolve.nodeResolve(),
|
|
400
|
+
image__default["default"](),
|
|
401
|
+
styles__default["default"]({
|
|
402
|
+
mode: this.cssInJs ? 'inject' : 'extract',
|
|
403
|
+
url: true,
|
|
404
|
+
plugins: [autoprefixer__default["default"]()],
|
|
405
|
+
modules: this.cssModules,
|
|
406
|
+
sourceMap: true,
|
|
407
|
+
}),
|
|
408
|
+
string({
|
|
409
|
+
include: '**/*.*',
|
|
410
|
+
exclude: stringExcludeDom,
|
|
411
|
+
}),
|
|
412
|
+
this.createClient(key, cert, pkg),
|
|
413
|
+
livereload(Object.assign({ watch: this.publicFolder, verbose: false }, (key && cert ? { https: { key, cert } } : {})))
|
|
414
|
+
];
|
|
382
415
|
}
|
|
383
416
|
const watcher = rollup__default["default"].watch(options);
|
|
384
417
|
watcher.on('event', (e) => __awaiter(this, void 0, void 0, function* () {
|
|
385
418
|
if (e.code == 'ERROR') {
|
|
386
|
-
|
|
419
|
+
if (e.error.code === 'UNRESOLVED_IMPORT') {
|
|
420
|
+
const [, importer, file] = e.error.message.match(/^Could not resolve '(.+)' from (.+)$/) || [];
|
|
421
|
+
const text = (yield fs__default["default"].readFile(file)).toString();
|
|
422
|
+
const lines = new linesAndColumns.LinesAndColumns(text);
|
|
423
|
+
const { line, column } = lines.locationForIndex(text.indexOf(importer));
|
|
424
|
+
logger__default["default"].end('Bundling', e.error.message);
|
|
425
|
+
console.log(`ERROR in ${file}:${line + 1}:${column + 1}`);
|
|
426
|
+
}
|
|
427
|
+
else if (e.error.code === 'PLUGIN_ERROR' && ['rpt2', 'commonjs'].includes(e.error.plugin)) {
|
|
428
|
+
const [, file, line, column] = e.error.message.match(/^[^(]+(src[^(]+)\((\d+),(\d+)\)/) || [];
|
|
429
|
+
logger__default["default"].end('Bundling', e.error.message);
|
|
430
|
+
if (file) {
|
|
431
|
+
console.log(`ERROR in ${file}:${line}:${column}`);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
else {
|
|
435
|
+
logger__default["default"].end('Bundling', error ? e.error.stack : e.error.message);
|
|
436
|
+
}
|
|
387
437
|
}
|
|
388
438
|
else if (e.code === 'BUNDLE_START') {
|
|
389
439
|
logger__default["default"].start('Bundling');
|
|
@@ -509,9 +559,28 @@ class InnetJS {
|
|
|
509
559
|
res.sendFile(this.devBuildFolder + '/index.html');
|
|
510
560
|
});
|
|
511
561
|
const server = httpsUsing ? https__default["default"].createServer({ key, cert }, app) : http__default["default"].createServer(app);
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
562
|
+
let port = this.port;
|
|
563
|
+
const listener = () => {
|
|
564
|
+
console.log(`${chalk__default["default"].green('➤')} Server started on http${httpsUsing ? 's' : ''}://localhost:${port}`);
|
|
565
|
+
};
|
|
566
|
+
server.listen(port, listener);
|
|
567
|
+
server.on('error', (e) => __awaiter(this, void 0, void 0, function* () {
|
|
568
|
+
if (e.code === 'EADDRINUSE') {
|
|
569
|
+
port++;
|
|
570
|
+
const { userPort } = yield prompt__default["default"]({
|
|
571
|
+
name: 'userPort',
|
|
572
|
+
type: 'number',
|
|
573
|
+
message: `Port ${e.port} is reserved, please enter another one [${port}]:`
|
|
574
|
+
});
|
|
575
|
+
if (userPort) {
|
|
576
|
+
port = userPort;
|
|
577
|
+
}
|
|
578
|
+
server.listen(port);
|
|
579
|
+
}
|
|
580
|
+
else {
|
|
581
|
+
throw e;
|
|
582
|
+
}
|
|
583
|
+
}));
|
|
515
584
|
}
|
|
516
585
|
})
|
|
517
586
|
};
|
|
@@ -532,7 +601,7 @@ class InnetJS {
|
|
|
532
601
|
}
|
|
533
602
|
}
|
|
534
603
|
|
|
535
|
-
var version = "2.0.
|
|
604
|
+
var version = "2.0.4";
|
|
536
605
|
|
|
537
606
|
require('dotenv').config();
|
|
538
607
|
const innetJS = new InnetJS();
|
package/constants.d.ts
ADDED
package/helpers.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { FileSizeRender } from 'rollup-plugin-filesize';
|
|
3
|
+
export declare function getFile(file: any): any;
|
|
4
|
+
export declare function convertIndexFile(data: Buffer, version: string): Promise<string>;
|
|
5
|
+
export declare const reporter: FileSizeRender<string | Promise<string>>;
|
package/index.es6.js
CHANGED
|
@@ -18,9 +18,12 @@ import json from '@rollup/plugin-json';
|
|
|
18
18
|
import tmp from 'tmp';
|
|
19
19
|
import proxy from 'express-http-proxy';
|
|
20
20
|
import selector from 'cli-select';
|
|
21
|
+
import prompt from 'prompts';
|
|
21
22
|
import jsx from 'rollup-plugin-innet-jsx';
|
|
22
23
|
import filesize from 'rollup-plugin-filesize';
|
|
23
24
|
import image from '@rollup/plugin-image';
|
|
25
|
+
import eslint from '@rollup/plugin-eslint';
|
|
26
|
+
import { LinesAndColumns } from 'lines-and-columns';
|
|
24
27
|
import { Parse } from 'unzipper';
|
|
25
28
|
|
|
26
29
|
/******************************************************************************
|
|
@@ -90,13 +93,35 @@ function Extract(opts, template) {
|
|
|
90
93
|
return extract;
|
|
91
94
|
}
|
|
92
95
|
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
const lintIncludeDom = [
|
|
97
|
+
'**/*.ts',
|
|
98
|
+
'**/*.tsx',
|
|
99
|
+
'**/*.js',
|
|
100
|
+
'**/*.jsx',
|
|
101
|
+
];
|
|
102
|
+
const stringExcludeDom = [
|
|
103
|
+
'**/*.ts',
|
|
104
|
+
'**/*.tsx',
|
|
105
|
+
'**/*.js',
|
|
106
|
+
'**/*.jsx',
|
|
107
|
+
'**/*.json',
|
|
108
|
+
'**/*.css',
|
|
109
|
+
'**/*.scss',
|
|
110
|
+
'**/*.webp',
|
|
111
|
+
'**/*.gif',
|
|
112
|
+
'**/*.png',
|
|
113
|
+
'**/*.jpeg',
|
|
114
|
+
'**/*.jpg',
|
|
115
|
+
'**/*.svg',
|
|
116
|
+
];
|
|
117
|
+
const stringExcludeNode = [
|
|
118
|
+
'**/*.ts',
|
|
119
|
+
'**/*.tsx',
|
|
120
|
+
'**/*.js',
|
|
121
|
+
'**/*.jsx',
|
|
122
|
+
'**/*.json',
|
|
123
|
+
];
|
|
124
|
+
|
|
100
125
|
function getFile(file) {
|
|
101
126
|
file = path$1.resolve(file);
|
|
102
127
|
if (!fs.existsSync(file)) {
|
|
@@ -129,31 +154,17 @@ function convertIndexFile(data, version) {
|
|
|
129
154
|
const reporter = (options, outputOptions, info) => {
|
|
130
155
|
logger.log(`${chalk.yellow(info.fileName)} ${chalk.green(info.bundleSize)} [ gzip: ${chalk.green(info.gzipSize)} ]`);
|
|
131
156
|
return '';
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
'**/*.webp',
|
|
142
|
-
'**/*.gif',
|
|
143
|
-
'**/*.png',
|
|
144
|
-
'**/*.jpeg',
|
|
145
|
-
'**/*.jpg',
|
|
146
|
-
'**/*.svg',
|
|
147
|
-
];
|
|
148
|
-
const stringExcludeNode = [
|
|
149
|
-
'**/*.ts',
|
|
150
|
-
'**/*.tsx',
|
|
151
|
-
'**/*.js',
|
|
152
|
-
'**/*.jsx',
|
|
153
|
-
'**/*.json',
|
|
154
|
-
];
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
const livereload = require('rollup-plugin-livereload');
|
|
160
|
+
const { string } = require('rollup-plugin-string');
|
|
161
|
+
const { exec, spawn } = require('child_process');
|
|
162
|
+
const readline = require('readline');
|
|
163
|
+
const execAsync = promisify(exec);
|
|
164
|
+
const copyFiles = promisify(fs.copy);
|
|
165
|
+
require('dotenv').config();
|
|
155
166
|
class InnetJS {
|
|
156
|
-
constructor({ projectFolder = process.env.PROJECT_FOLDER || '', publicFolder = process.env.PUBLIC_FOLDER || 'public', buildFolder = process.env.BUILD_FOLDER || 'build', srcFolder = process.env.SRC_FOLDER || 'src', sourcemap = process.env.SOURCEMAP ? process.env.SOURCEMAP === 'true' : false, cssModules = process.env.CSS_MODULES ? process.env.CSS_MODULES === 'true' : true, cssInJs = process.env.CSS_IN_JS ? process.env.CSS_IN_JS === 'true' : true, sslKey = process.env.SSL_KEY || 'localhost.key', sslCrt = process.env.SSL_CRT || 'localhost.crt', proxy = process.env.PROXY || '', port = process.env.PORT ? +process.env.PORT : 3000, api = process.env.API || '
|
|
167
|
+
constructor({ projectFolder = process.env.PROJECT_FOLDER || '', publicFolder = process.env.PUBLIC_FOLDER || 'public', buildFolder = process.env.BUILD_FOLDER || 'build', srcFolder = process.env.SRC_FOLDER || 'src', sourcemap = process.env.SOURCEMAP ? process.env.SOURCEMAP === 'true' : false, cssModules = process.env.CSS_MODULES ? process.env.CSS_MODULES === 'true' : true, cssInJs = process.env.CSS_IN_JS ? process.env.CSS_IN_JS === 'true' : true, sslKey = process.env.SSL_KEY || 'localhost.key', sslCrt = process.env.SSL_CRT || 'localhost.crt', proxy = process.env.PROXY || '', port = process.env.PORT ? +process.env.PORT : 3000, api = process.env.API || '/api/?*', } = {}) {
|
|
157
168
|
this.projectFolder = path$1.resolve(projectFolder);
|
|
158
169
|
this.publicFolder = path$1.resolve(publicFolder);
|
|
159
170
|
this.buildFolder = path$1.resolve(buildFolder);
|
|
@@ -249,17 +260,26 @@ class InnetJS {
|
|
|
249
260
|
}));
|
|
250
261
|
}
|
|
251
262
|
else {
|
|
252
|
-
inputOptions.plugins
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
+
inputOptions.plugins = [
|
|
264
|
+
eslint({
|
|
265
|
+
include: lintIncludeDom,
|
|
266
|
+
}),
|
|
267
|
+
...inputOptions.plugins,
|
|
268
|
+
nodeResolve(),
|
|
269
|
+
image(),
|
|
270
|
+
styles({
|
|
271
|
+
mode: this.cssInJs ? 'inject' : 'extract',
|
|
272
|
+
url: true,
|
|
273
|
+
plugins: [autoprefixer()],
|
|
274
|
+
modules: this.cssModules,
|
|
275
|
+
sourceMap: this.sourcemap,
|
|
276
|
+
minimize: true,
|
|
277
|
+
}),
|
|
278
|
+
string({
|
|
279
|
+
include: '**/*.*',
|
|
280
|
+
exclude: stringExcludeDom,
|
|
281
|
+
}),
|
|
282
|
+
];
|
|
263
283
|
outputOptions.format = 'es';
|
|
264
284
|
outputOptions.plugins = [
|
|
265
285
|
terser(),
|
|
@@ -342,21 +362,49 @@ class InnetJS {
|
|
|
342
362
|
? fs.readFileSync(this.sslCrt)
|
|
343
363
|
: undefined;
|
|
344
364
|
options.output.format = 'es';
|
|
345
|
-
options.plugins
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
365
|
+
options.plugins = [
|
|
366
|
+
eslint({
|
|
367
|
+
include: lintIncludeDom,
|
|
368
|
+
}),
|
|
369
|
+
...options.plugins,
|
|
370
|
+
nodeResolve(),
|
|
371
|
+
image(),
|
|
372
|
+
styles({
|
|
373
|
+
mode: this.cssInJs ? 'inject' : 'extract',
|
|
374
|
+
url: true,
|
|
375
|
+
plugins: [autoprefixer()],
|
|
376
|
+
modules: this.cssModules,
|
|
377
|
+
sourceMap: true,
|
|
378
|
+
}),
|
|
379
|
+
string({
|
|
380
|
+
include: '**/*.*',
|
|
381
|
+
exclude: stringExcludeDom,
|
|
382
|
+
}),
|
|
383
|
+
this.createClient(key, cert, pkg),
|
|
384
|
+
livereload(Object.assign({ watch: this.publicFolder, verbose: false }, (key && cert ? { https: { key, cert } } : {})))
|
|
385
|
+
];
|
|
355
386
|
}
|
|
356
387
|
const watcher = rollup.watch(options);
|
|
357
388
|
watcher.on('event', (e) => __awaiter(this, void 0, void 0, function* () {
|
|
358
389
|
if (e.code == 'ERROR') {
|
|
359
|
-
|
|
390
|
+
if (e.error.code === 'UNRESOLVED_IMPORT') {
|
|
391
|
+
const [, importer, file] = e.error.message.match(/^Could not resolve '(.+)' from (.+)$/) || [];
|
|
392
|
+
const text = (yield fs.readFile(file)).toString();
|
|
393
|
+
const lines = new LinesAndColumns(text);
|
|
394
|
+
const { line, column } = lines.locationForIndex(text.indexOf(importer));
|
|
395
|
+
logger.end('Bundling', e.error.message);
|
|
396
|
+
console.log(`ERROR in ${file}:${line + 1}:${column + 1}`);
|
|
397
|
+
}
|
|
398
|
+
else if (e.error.code === 'PLUGIN_ERROR' && ['rpt2', 'commonjs'].includes(e.error.plugin)) {
|
|
399
|
+
const [, file, line, column] = e.error.message.match(/^[^(]+(src[^(]+)\((\d+),(\d+)\)/) || [];
|
|
400
|
+
logger.end('Bundling', e.error.message);
|
|
401
|
+
if (file) {
|
|
402
|
+
console.log(`ERROR in ${file}:${line}:${column}`);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
else {
|
|
406
|
+
logger.end('Bundling', error ? e.error.stack : e.error.message);
|
|
407
|
+
}
|
|
360
408
|
}
|
|
361
409
|
else if (e.code === 'BUNDLE_START') {
|
|
362
410
|
logger.start('Bundling');
|
|
@@ -482,9 +530,28 @@ class InnetJS {
|
|
|
482
530
|
res.sendFile(this.devBuildFolder + '/index.html');
|
|
483
531
|
});
|
|
484
532
|
const server = httpsUsing ? https.createServer({ key, cert }, app) : http.createServer(app);
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
533
|
+
let port = this.port;
|
|
534
|
+
const listener = () => {
|
|
535
|
+
console.log(`${chalk.green('➤')} Server started on http${httpsUsing ? 's' : ''}://localhost:${port}`);
|
|
536
|
+
};
|
|
537
|
+
server.listen(port, listener);
|
|
538
|
+
server.on('error', (e) => __awaiter(this, void 0, void 0, function* () {
|
|
539
|
+
if (e.code === 'EADDRINUSE') {
|
|
540
|
+
port++;
|
|
541
|
+
const { userPort } = yield prompt({
|
|
542
|
+
name: 'userPort',
|
|
543
|
+
type: 'number',
|
|
544
|
+
message: `Port ${e.port} is reserved, please enter another one [${port}]:`
|
|
545
|
+
});
|
|
546
|
+
if (userPort) {
|
|
547
|
+
port = userPort;
|
|
548
|
+
}
|
|
549
|
+
server.listen(port);
|
|
550
|
+
}
|
|
551
|
+
else {
|
|
552
|
+
throw e;
|
|
553
|
+
}
|
|
554
|
+
}));
|
|
488
555
|
}
|
|
489
556
|
})
|
|
490
557
|
};
|
package/index.js
CHANGED
|
@@ -20,9 +20,12 @@ var json = require('@rollup/plugin-json');
|
|
|
20
20
|
var tmp = require('tmp');
|
|
21
21
|
var proxy = require('express-http-proxy');
|
|
22
22
|
var selector = require('cli-select');
|
|
23
|
+
var prompt = require('prompts');
|
|
23
24
|
var jsx = require('rollup-plugin-innet-jsx');
|
|
24
25
|
var filesize = require('rollup-plugin-filesize');
|
|
25
26
|
var image = require('@rollup/plugin-image');
|
|
27
|
+
var eslint = require('@rollup/plugin-eslint');
|
|
28
|
+
var linesAndColumns = require('lines-and-columns');
|
|
26
29
|
var unzipper = require('unzipper');
|
|
27
30
|
|
|
28
31
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -44,9 +47,11 @@ var json__default = /*#__PURE__*/_interopDefaultLegacy(json);
|
|
|
44
47
|
var tmp__default = /*#__PURE__*/_interopDefaultLegacy(tmp);
|
|
45
48
|
var proxy__default = /*#__PURE__*/_interopDefaultLegacy(proxy);
|
|
46
49
|
var selector__default = /*#__PURE__*/_interopDefaultLegacy(selector);
|
|
50
|
+
var prompt__default = /*#__PURE__*/_interopDefaultLegacy(prompt);
|
|
47
51
|
var jsx__default = /*#__PURE__*/_interopDefaultLegacy(jsx);
|
|
48
52
|
var filesize__default = /*#__PURE__*/_interopDefaultLegacy(filesize);
|
|
49
53
|
var image__default = /*#__PURE__*/_interopDefaultLegacy(image);
|
|
54
|
+
var eslint__default = /*#__PURE__*/_interopDefaultLegacy(eslint);
|
|
50
55
|
|
|
51
56
|
/******************************************************************************
|
|
52
57
|
Copyright (c) Microsoft Corporation.
|
|
@@ -115,13 +120,35 @@ function Extract(opts, template) {
|
|
|
115
120
|
return extract;
|
|
116
121
|
}
|
|
117
122
|
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
const lintIncludeDom = [
|
|
124
|
+
'**/*.ts',
|
|
125
|
+
'**/*.tsx',
|
|
126
|
+
'**/*.js',
|
|
127
|
+
'**/*.jsx',
|
|
128
|
+
];
|
|
129
|
+
const stringExcludeDom = [
|
|
130
|
+
'**/*.ts',
|
|
131
|
+
'**/*.tsx',
|
|
132
|
+
'**/*.js',
|
|
133
|
+
'**/*.jsx',
|
|
134
|
+
'**/*.json',
|
|
135
|
+
'**/*.css',
|
|
136
|
+
'**/*.scss',
|
|
137
|
+
'**/*.webp',
|
|
138
|
+
'**/*.gif',
|
|
139
|
+
'**/*.png',
|
|
140
|
+
'**/*.jpeg',
|
|
141
|
+
'**/*.jpg',
|
|
142
|
+
'**/*.svg',
|
|
143
|
+
];
|
|
144
|
+
const stringExcludeNode = [
|
|
145
|
+
'**/*.ts',
|
|
146
|
+
'**/*.tsx',
|
|
147
|
+
'**/*.js',
|
|
148
|
+
'**/*.jsx',
|
|
149
|
+
'**/*.json',
|
|
150
|
+
];
|
|
151
|
+
|
|
125
152
|
function getFile(file) {
|
|
126
153
|
file = path__default["default"].resolve(file);
|
|
127
154
|
if (!fs__default["default"].existsSync(file)) {
|
|
@@ -154,31 +181,17 @@ function convertIndexFile(data, version) {
|
|
|
154
181
|
const reporter = (options, outputOptions, info) => {
|
|
155
182
|
logger__default["default"].log(`${chalk__default["default"].yellow(info.fileName)} ${chalk__default["default"].green(info.bundleSize)} [ gzip: ${chalk__default["default"].green(info.gzipSize)} ]`);
|
|
156
183
|
return '';
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
'**/*.webp',
|
|
167
|
-
'**/*.gif',
|
|
168
|
-
'**/*.png',
|
|
169
|
-
'**/*.jpeg',
|
|
170
|
-
'**/*.jpg',
|
|
171
|
-
'**/*.svg',
|
|
172
|
-
];
|
|
173
|
-
const stringExcludeNode = [
|
|
174
|
-
'**/*.ts',
|
|
175
|
-
'**/*.tsx',
|
|
176
|
-
'**/*.js',
|
|
177
|
-
'**/*.jsx',
|
|
178
|
-
'**/*.json',
|
|
179
|
-
];
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
const livereload = require('rollup-plugin-livereload');
|
|
187
|
+
const { string } = require('rollup-plugin-string');
|
|
188
|
+
const { exec, spawn } = require('child_process');
|
|
189
|
+
const readline = require('readline');
|
|
190
|
+
const execAsync = util.promisify(exec);
|
|
191
|
+
const copyFiles = util.promisify(fs__default["default"].copy);
|
|
192
|
+
require('dotenv').config();
|
|
180
193
|
class InnetJS {
|
|
181
|
-
constructor({ projectFolder = process.env.PROJECT_FOLDER || '', publicFolder = process.env.PUBLIC_FOLDER || 'public', buildFolder = process.env.BUILD_FOLDER || 'build', srcFolder = process.env.SRC_FOLDER || 'src', sourcemap = process.env.SOURCEMAP ? process.env.SOURCEMAP === 'true' : false, cssModules = process.env.CSS_MODULES ? process.env.CSS_MODULES === 'true' : true, cssInJs = process.env.CSS_IN_JS ? process.env.CSS_IN_JS === 'true' : true, sslKey = process.env.SSL_KEY || 'localhost.key', sslCrt = process.env.SSL_CRT || 'localhost.crt', proxy = process.env.PROXY || '', port = process.env.PORT ? +process.env.PORT : 3000, api = process.env.API || '
|
|
194
|
+
constructor({ projectFolder = process.env.PROJECT_FOLDER || '', publicFolder = process.env.PUBLIC_FOLDER || 'public', buildFolder = process.env.BUILD_FOLDER || 'build', srcFolder = process.env.SRC_FOLDER || 'src', sourcemap = process.env.SOURCEMAP ? process.env.SOURCEMAP === 'true' : false, cssModules = process.env.CSS_MODULES ? process.env.CSS_MODULES === 'true' : true, cssInJs = process.env.CSS_IN_JS ? process.env.CSS_IN_JS === 'true' : true, sslKey = process.env.SSL_KEY || 'localhost.key', sslCrt = process.env.SSL_CRT || 'localhost.crt', proxy = process.env.PROXY || '', port = process.env.PORT ? +process.env.PORT : 3000, api = process.env.API || '/api/?*', } = {}) {
|
|
182
195
|
this.projectFolder = path__default["default"].resolve(projectFolder);
|
|
183
196
|
this.publicFolder = path__default["default"].resolve(publicFolder);
|
|
184
197
|
this.buildFolder = path__default["default"].resolve(buildFolder);
|
|
@@ -274,17 +287,26 @@ class InnetJS {
|
|
|
274
287
|
}));
|
|
275
288
|
}
|
|
276
289
|
else {
|
|
277
|
-
inputOptions.plugins
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
290
|
+
inputOptions.plugins = [
|
|
291
|
+
eslint__default["default"]({
|
|
292
|
+
include: lintIncludeDom,
|
|
293
|
+
}),
|
|
294
|
+
...inputOptions.plugins,
|
|
295
|
+
pluginNodeResolve.nodeResolve(),
|
|
296
|
+
image__default["default"](),
|
|
297
|
+
styles__default["default"]({
|
|
298
|
+
mode: this.cssInJs ? 'inject' : 'extract',
|
|
299
|
+
url: true,
|
|
300
|
+
plugins: [autoprefixer__default["default"]()],
|
|
301
|
+
modules: this.cssModules,
|
|
302
|
+
sourceMap: this.sourcemap,
|
|
303
|
+
minimize: true,
|
|
304
|
+
}),
|
|
305
|
+
string({
|
|
306
|
+
include: '**/*.*',
|
|
307
|
+
exclude: stringExcludeDom,
|
|
308
|
+
}),
|
|
309
|
+
];
|
|
288
310
|
outputOptions.format = 'es';
|
|
289
311
|
outputOptions.plugins = [
|
|
290
312
|
rollupPluginTerser.terser(),
|
|
@@ -367,21 +389,49 @@ class InnetJS {
|
|
|
367
389
|
? fs__default["default"].readFileSync(this.sslCrt)
|
|
368
390
|
: undefined;
|
|
369
391
|
options.output.format = 'es';
|
|
370
|
-
options.plugins
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
392
|
+
options.plugins = [
|
|
393
|
+
eslint__default["default"]({
|
|
394
|
+
include: lintIncludeDom,
|
|
395
|
+
}),
|
|
396
|
+
...options.plugins,
|
|
397
|
+
pluginNodeResolve.nodeResolve(),
|
|
398
|
+
image__default["default"](),
|
|
399
|
+
styles__default["default"]({
|
|
400
|
+
mode: this.cssInJs ? 'inject' : 'extract',
|
|
401
|
+
url: true,
|
|
402
|
+
plugins: [autoprefixer__default["default"]()],
|
|
403
|
+
modules: this.cssModules,
|
|
404
|
+
sourceMap: true,
|
|
405
|
+
}),
|
|
406
|
+
string({
|
|
407
|
+
include: '**/*.*',
|
|
408
|
+
exclude: stringExcludeDom,
|
|
409
|
+
}),
|
|
410
|
+
this.createClient(key, cert, pkg),
|
|
411
|
+
livereload(Object.assign({ watch: this.publicFolder, verbose: false }, (key && cert ? { https: { key, cert } } : {})))
|
|
412
|
+
];
|
|
380
413
|
}
|
|
381
414
|
const watcher = rollup__default["default"].watch(options);
|
|
382
415
|
watcher.on('event', (e) => __awaiter(this, void 0, void 0, function* () {
|
|
383
416
|
if (e.code == 'ERROR') {
|
|
384
|
-
|
|
417
|
+
if (e.error.code === 'UNRESOLVED_IMPORT') {
|
|
418
|
+
const [, importer, file] = e.error.message.match(/^Could not resolve '(.+)' from (.+)$/) || [];
|
|
419
|
+
const text = (yield fs__default["default"].readFile(file)).toString();
|
|
420
|
+
const lines = new linesAndColumns.LinesAndColumns(text);
|
|
421
|
+
const { line, column } = lines.locationForIndex(text.indexOf(importer));
|
|
422
|
+
logger__default["default"].end('Bundling', e.error.message);
|
|
423
|
+
console.log(`ERROR in ${file}:${line + 1}:${column + 1}`);
|
|
424
|
+
}
|
|
425
|
+
else if (e.error.code === 'PLUGIN_ERROR' && ['rpt2', 'commonjs'].includes(e.error.plugin)) {
|
|
426
|
+
const [, file, line, column] = e.error.message.match(/^[^(]+(src[^(]+)\((\d+),(\d+)\)/) || [];
|
|
427
|
+
logger__default["default"].end('Bundling', e.error.message);
|
|
428
|
+
if (file) {
|
|
429
|
+
console.log(`ERROR in ${file}:${line}:${column}`);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
else {
|
|
433
|
+
logger__default["default"].end('Bundling', error ? e.error.stack : e.error.message);
|
|
434
|
+
}
|
|
385
435
|
}
|
|
386
436
|
else if (e.code === 'BUNDLE_START') {
|
|
387
437
|
logger__default["default"].start('Bundling');
|
|
@@ -507,9 +557,28 @@ class InnetJS {
|
|
|
507
557
|
res.sendFile(this.devBuildFolder + '/index.html');
|
|
508
558
|
});
|
|
509
559
|
const server = httpsUsing ? https__default["default"].createServer({ key, cert }, app) : http__default["default"].createServer(app);
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
560
|
+
let port = this.port;
|
|
561
|
+
const listener = () => {
|
|
562
|
+
console.log(`${chalk__default["default"].green('➤')} Server started on http${httpsUsing ? 's' : ''}://localhost:${port}`);
|
|
563
|
+
};
|
|
564
|
+
server.listen(port, listener);
|
|
565
|
+
server.on('error', (e) => __awaiter(this, void 0, void 0, function* () {
|
|
566
|
+
if (e.code === 'EADDRINUSE') {
|
|
567
|
+
port++;
|
|
568
|
+
const { userPort } = yield prompt__default["default"]({
|
|
569
|
+
name: 'userPort',
|
|
570
|
+
type: 'number',
|
|
571
|
+
message: `Port ${e.port} is reserved, please enter another one [${port}]:`
|
|
572
|
+
});
|
|
573
|
+
if (userPort) {
|
|
574
|
+
port = userPort;
|
|
575
|
+
}
|
|
576
|
+
server.listen(port);
|
|
577
|
+
}
|
|
578
|
+
else {
|
|
579
|
+
throw e;
|
|
580
|
+
}
|
|
581
|
+
}));
|
|
513
582
|
}
|
|
514
583
|
})
|
|
515
584
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "innetjs",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
4
4
|
"description": "CLI for innet boilerplate",
|
|
5
5
|
"homepage": "https://github.com/d8corp/innetjs",
|
|
6
6
|
"author": "Mikhail Lysikov <d8corp@mail.ru>",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@cantinc/logger": "^1.1.0",
|
|
35
35
|
"@rollup/plugin-commonjs": "^22.0.2",
|
|
36
|
+
"@rollup/plugin-eslint": "^8.0.2",
|
|
36
37
|
"@rollup/plugin-image": "^2.1.1",
|
|
37
38
|
"@rollup/plugin-json": "^4.1.0",
|
|
38
39
|
"@rollup/plugin-node-resolve": "^13.3.0",
|
|
@@ -45,8 +46,10 @@
|
|
|
45
46
|
"express": "^4.18.1",
|
|
46
47
|
"express-http-proxy": "^1.6.3",
|
|
47
48
|
"fs-extra": "^10.1.0",
|
|
49
|
+
"lines-and-columns": "^2.0.3",
|
|
48
50
|
"node-sass": "^7.0.1",
|
|
49
51
|
"postcss": "^8.4.16",
|
|
52
|
+
"prompts": "^2.4.2",
|
|
50
53
|
"rollup": "^2.77.2",
|
|
51
54
|
"rollup-plugin-filesize": "^9.1.2",
|
|
52
55
|
"rollup-plugin-innet-jsx": "^1.3.0",
|