innetjs 1.12.1 → 2.0.2
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 +0 -3
- package/bin/innet +202 -85
- package/constants.d.ts +3 -0
- package/declaration.d.ts +39 -0
- package/extract.d.ts +1 -0
- package/helpers.d.ts +5 -0
- package/index.d.ts +6 -2
- package/index.es6.js +222 -108
- package/index.js +201 -84
- package/package.json +19 -14
- package/templates/be/.env +0 -1
- package/templates/be/README.md +0 -15
- package/templates/be/package.json +0 -13
- package/templates/be/src/controller/index.tsx +0 -7
- package/templates/be/src/declaration.d.ts +0 -4
- package/templates/be/src/index.tsx +0 -6
- package/templates/be/src/view/App/App.css +0 -12
- package/templates/be/src/view/App/App.tsx +0 -15
- package/templates/be/src/view/App/index.ts +0 -1
- package/templates/be/src/view/Page/Page.css +0 -7
- package/templates/be/src/view/Page/Page.tsx +0 -24
- package/templates/be/src/view/Page/index.ts +0 -1
- package/templates/be/src/view/index.ts +0 -2
- package/templates/be/tsconfig.json +0 -31
- package/templates/fe/.env +0 -1
- package/templates/fe/README.md +0 -84
- package/templates/fe/package.json +0 -16
- package/templates/fe/public/favicon.ico +0 -0
- package/templates/fe/public/index.html +0 -14
- package/templates/fe/src/App.scss +0 -48
- package/templates/fe/src/App.tsx +0 -36
- package/templates/fe/src/componenst/Page/Page.scss +0 -22
- package/templates/fe/src/componenst/Page/Page.tsx +0 -18
- package/templates/fe/src/componenst/Page/index.ts +0 -1
- package/templates/fe/src/declaration.d.ts +0 -9
- package/templates/fe/src/index.tsx +0 -6
- package/templates/fe/src/pages/HomePage/HomePage.scss +0 -25
- package/templates/fe/src/pages/HomePage/HomePage.tsx +0 -24
- package/templates/fe/src/pages/HomePage/index.ts +0 -1
- package/templates/fe/tsconfig.json +0 -30
package/index.es6.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import fs from 'fs-extra';
|
|
1
|
+
import path$1 from 'path';
|
|
2
|
+
import fs, { promises } from 'fs-extra';
|
|
3
3
|
import http from 'http';
|
|
4
4
|
import https from 'https';
|
|
5
|
+
import { promisify } from 'util';
|
|
6
|
+
import axios from 'axios';
|
|
5
7
|
import logger from '@cantinc/logger';
|
|
6
8
|
import chalk from 'chalk';
|
|
7
|
-
import { promisify } from 'util';
|
|
8
9
|
import rollup from 'rollup';
|
|
9
10
|
import commonjs from '@rollup/plugin-commonjs';
|
|
10
11
|
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
|
11
12
|
import { terser } from 'rollup-plugin-terser';
|
|
12
13
|
import typescript from 'rollup-plugin-typescript2';
|
|
13
|
-
import
|
|
14
|
+
import styles from 'rollup-plugin-styles';
|
|
14
15
|
import autoprefixer from 'autoprefixer';
|
|
15
16
|
import express from 'express';
|
|
16
17
|
import json from '@rollup/plugin-json';
|
|
@@ -19,8 +20,12 @@ import proxy from 'express-http-proxy';
|
|
|
19
20
|
import selector from 'cli-select';
|
|
20
21
|
import jsx from 'rollup-plugin-innet-jsx';
|
|
21
22
|
import filesize from 'rollup-plugin-filesize';
|
|
23
|
+
import image from '@rollup/plugin-image';
|
|
24
|
+
import eslint from '@rollup/plugin-eslint';
|
|
25
|
+
import { LinesAndColumns } from 'lines-and-columns';
|
|
26
|
+
import { Parse } from 'unzipper';
|
|
22
27
|
|
|
23
|
-
|
|
28
|
+
/******************************************************************************
|
|
24
29
|
Copyright (c) Microsoft Corporation.
|
|
25
30
|
|
|
26
31
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
@@ -45,22 +50,87 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
45
50
|
});
|
|
46
51
|
}
|
|
47
52
|
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
|
|
53
|
+
const Writer = require('fstream').Writer;
|
|
54
|
+
const path = require('path');
|
|
55
|
+
const stream = require('stream');
|
|
56
|
+
const duplexer2 = require('duplexer2');
|
|
57
|
+
const Promise$1 = require('bluebird');
|
|
58
|
+
function Extract(opts, template) {
|
|
59
|
+
const reduceCount = 19 + template.length;
|
|
60
|
+
// make sure path is normalized before using it
|
|
61
|
+
opts.path = path.resolve(path.normalize(opts.path));
|
|
62
|
+
// @ts-ignore
|
|
63
|
+
const parser = new Parse(opts);
|
|
64
|
+
const outStream = new stream.Writable({ objectMode: true });
|
|
65
|
+
outStream._write = function (entry, encoding, cb) {
|
|
66
|
+
if (entry.type === 'Directory')
|
|
67
|
+
return cb();
|
|
68
|
+
const extractPath = path.join(opts.path, entry.path.slice(reduceCount));
|
|
69
|
+
if (extractPath.indexOf(opts.path) !== 0) {
|
|
70
|
+
return cb();
|
|
71
|
+
}
|
|
72
|
+
const writer = opts.getWriter ? opts.getWriter({ path: extractPath }) : Writer({ path: extractPath });
|
|
73
|
+
entry.pipe(writer)
|
|
74
|
+
.on('error', cb)
|
|
75
|
+
.on('close', cb);
|
|
76
|
+
};
|
|
77
|
+
const extract = duplexer2(parser, outStream);
|
|
78
|
+
parser.once('crx-header', function (crxHeader) {
|
|
79
|
+
extract.crxHeader = crxHeader;
|
|
80
|
+
});
|
|
81
|
+
parser
|
|
82
|
+
.pipe(outStream)
|
|
83
|
+
.on('finish', function () {
|
|
84
|
+
extract.emit('close');
|
|
85
|
+
});
|
|
86
|
+
extract.promise = function () {
|
|
87
|
+
return new Promise$1(function (resolve, reject) {
|
|
88
|
+
extract.on('close', resolve);
|
|
89
|
+
extract.on('error', reject);
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
return extract;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const lintIncludeDom = [
|
|
96
|
+
'**/*.ts',
|
|
97
|
+
'**/*.tsx',
|
|
98
|
+
'**/*.js',
|
|
99
|
+
'**/*.jsx',
|
|
100
|
+
];
|
|
101
|
+
const stringExcludeDom = [
|
|
102
|
+
'**/*.ts',
|
|
103
|
+
'**/*.tsx',
|
|
104
|
+
'**/*.js',
|
|
105
|
+
'**/*.jsx',
|
|
106
|
+
'**/*.json',
|
|
107
|
+
'**/*.css',
|
|
108
|
+
'**/*.scss',
|
|
109
|
+
'**/*.webp',
|
|
110
|
+
'**/*.gif',
|
|
111
|
+
'**/*.png',
|
|
112
|
+
'**/*.jpeg',
|
|
113
|
+
'**/*.jpg',
|
|
114
|
+
'**/*.svg',
|
|
115
|
+
];
|
|
116
|
+
const stringExcludeNode = [
|
|
117
|
+
'**/*.ts',
|
|
118
|
+
'**/*.tsx',
|
|
119
|
+
'**/*.js',
|
|
120
|
+
'**/*.jsx',
|
|
121
|
+
'**/*.json',
|
|
122
|
+
];
|
|
123
|
+
|
|
54
124
|
function getFile(file) {
|
|
55
|
-
file = path.resolve(file);
|
|
125
|
+
file = path$1.resolve(file);
|
|
56
126
|
if (!fs.existsSync(file)) {
|
|
57
127
|
throw Error('Cannot find the file: ' + file);
|
|
58
128
|
}
|
|
59
129
|
if (fs.lstatSync(file).isDirectory()) {
|
|
60
130
|
let tmpFile = file;
|
|
61
|
-
if (!fs.existsSync(tmpFile = path.join(file, 'index.ts')) &&
|
|
62
|
-
!fs.existsSync(tmpFile = path.join(file, 'index.tsx')) &&
|
|
63
|
-
!fs.existsSync(tmpFile = path.join(file, 'index.js'))) {
|
|
131
|
+
if (!fs.existsSync(tmpFile = path$1.join(file, 'index.ts')) &&
|
|
132
|
+
!fs.existsSync(tmpFile = path$1.join(file, 'index.tsx')) &&
|
|
133
|
+
!fs.existsSync(tmpFile = path$1.join(file, 'index.js'))) {
|
|
64
134
|
throw Error('Cannot find index file in: ' + file);
|
|
65
135
|
}
|
|
66
136
|
file = tmpFile;
|
|
@@ -73,16 +143,35 @@ function getFile(file) {
|
|
|
73
143
|
}
|
|
74
144
|
return file;
|
|
75
145
|
}
|
|
146
|
+
function convertIndexFile(data, version) {
|
|
147
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
148
|
+
return data
|
|
149
|
+
.toString()
|
|
150
|
+
.replace('</head>', `<script type="module" defer src="index.js${version ? `?v=${version}` : ''}"></script></head>`);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
76
153
|
const reporter = (options, outputOptions, info) => {
|
|
77
154
|
logger.log(`${chalk.yellow(info.fileName)} ${chalk.green(info.bundleSize)} [ gzip: ${chalk.green(info.gzipSize)} ]`);
|
|
78
155
|
return '';
|
|
79
|
-
};
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const livereload = require('rollup-plugin-livereload');
|
|
159
|
+
const { string } = require('rollup-plugin-string');
|
|
160
|
+
const { exec, spawn } = require('child_process');
|
|
161
|
+
const readline = require('readline');
|
|
162
|
+
const execAsync = promisify(exec);
|
|
163
|
+
const copyFiles = promisify(fs.copy);
|
|
164
|
+
require('dotenv').config();
|
|
80
165
|
class InnetJS {
|
|
81
|
-
constructor({ projectFolder = process.env.PROJECT_FOLDER || '', publicFolder = process.env.PUBLIC_FOLDER || 'public', buildFolder = process.env.BUILD_FOLDER ||
|
|
82
|
-
this.projectFolder = path.resolve(projectFolder);
|
|
83
|
-
this.publicFolder = path.resolve(publicFolder);
|
|
84
|
-
this.buildFolder = path.resolve(buildFolder);
|
|
85
|
-
this.srcFolder = path.resolve(srcFolder);
|
|
166
|
+
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
|
+
this.projectFolder = path$1.resolve(projectFolder);
|
|
168
|
+
this.publicFolder = path$1.resolve(publicFolder);
|
|
169
|
+
this.buildFolder = path$1.resolve(buildFolder);
|
|
170
|
+
this.srcFolder = path$1.resolve(srcFolder);
|
|
171
|
+
this.publicIndexFile = path$1.join(publicFolder, 'index.html');
|
|
172
|
+
this.buildIndexFile = path$1.join(buildFolder, 'index.html');
|
|
173
|
+
this.devBuildFolder = path$1.resolve(projectFolder, 'node_modules', '.cache', 'innetjs', 'build');
|
|
174
|
+
this.devBuildIndexFile = path$1.join(this.devBuildFolder, 'index.html');
|
|
86
175
|
this.sourcemap = sourcemap;
|
|
87
176
|
this.cssModules = cssModules;
|
|
88
177
|
this.cssInJs = cssInJs;
|
|
@@ -95,15 +184,19 @@ class InnetJS {
|
|
|
95
184
|
// Methods
|
|
96
185
|
init(appName, { template, force = false } = {}) {
|
|
97
186
|
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
-
const appPath = path.resolve(appName);
|
|
99
|
-
|
|
187
|
+
const appPath = path$1.resolve(appName);
|
|
188
|
+
const { data } = yield logger.start('Get templates list', () => __awaiter(this, void 0, void 0, function* () { return yield axios.get('https://api.github.com/repos/d8corp/innetjs-templates/branches'); }));
|
|
189
|
+
const templates = data.map(({ name }) => name).filter(name => name !== 'main');
|
|
190
|
+
if (!template || !templates.includes(template)) {
|
|
100
191
|
logger.log(chalk.green(`Select one of those templates`));
|
|
101
192
|
const { value } = yield selector({
|
|
102
|
-
values:
|
|
193
|
+
values: templates
|
|
103
194
|
});
|
|
104
195
|
template = value;
|
|
105
196
|
readline.moveCursor(process.stdout, 0, -1);
|
|
106
|
-
|
|
197
|
+
const text = `Selected template: ${chalk.white(value)}`;
|
|
198
|
+
logger.start(text);
|
|
199
|
+
logger.end(text);
|
|
107
200
|
}
|
|
108
201
|
if (!force) {
|
|
109
202
|
yield logger.start('Check if app folder is available', () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -123,14 +216,16 @@ class InnetJS {
|
|
|
123
216
|
}
|
|
124
217
|
}));
|
|
125
218
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
219
|
+
yield logger.start('Download template', () => __awaiter(this, void 0, void 0, function* () {
|
|
220
|
+
const { data } = yield axios.get(`https://github.com/d8corp/innetjs-templates/archive/refs/heads/${template}.zip`, {
|
|
221
|
+
responseType: 'stream'
|
|
222
|
+
});
|
|
223
|
+
yield new Promise((resolve, reject) => {
|
|
224
|
+
data.pipe(Extract({
|
|
225
|
+
path: appPath,
|
|
226
|
+
}, template)).on('finish', resolve).on('error', reject);
|
|
227
|
+
});
|
|
132
228
|
}));
|
|
133
|
-
yield logger.start('Copy files', () => fs.copy(templatePath, appPath));
|
|
134
229
|
yield logger.start('Install packages', () => execAsync(`cd ${appPath} && npm i`));
|
|
135
230
|
});
|
|
136
231
|
}
|
|
@@ -140,7 +235,8 @@ class InnetJS {
|
|
|
140
235
|
yield logger.start('Remove build', () => fs.remove(this.buildFolder));
|
|
141
236
|
const pkg = node && (yield this.getPackage());
|
|
142
237
|
const inputOptions = {
|
|
143
|
-
input: path.resolve(this.srcFolder, `index.${indexExtension}`),
|
|
238
|
+
input: path$1.resolve(this.srcFolder, `index.${indexExtension}`),
|
|
239
|
+
preserveEntrySignatures: 'strict',
|
|
144
240
|
plugins: [
|
|
145
241
|
commonjs(),
|
|
146
242
|
json(),
|
|
@@ -156,37 +252,33 @@ class InnetJS {
|
|
|
156
252
|
outputOptions.format = 'cjs';
|
|
157
253
|
inputOptions.external = Object.keys((pkg === null || pkg === void 0 ? void 0 : pkg.dependencies) || {});
|
|
158
254
|
inputOptions.plugins.push(nodeResolve({
|
|
159
|
-
moduleDirectories: [path.resolve(this.buildFolder, 'node_modules')]
|
|
255
|
+
moduleDirectories: [path$1.resolve(this.buildFolder, 'node_modules')]
|
|
160
256
|
}), string({
|
|
161
257
|
include: '**/*.*',
|
|
162
|
-
exclude:
|
|
163
|
-
'**/*.ts',
|
|
164
|
-
'**/*.tsx',
|
|
165
|
-
'**/*.js',
|
|
166
|
-
'**/*.jsx',
|
|
167
|
-
'**/*.json',
|
|
168
|
-
]
|
|
258
|
+
exclude: stringExcludeNode,
|
|
169
259
|
}));
|
|
170
260
|
}
|
|
171
261
|
else {
|
|
172
|
-
inputOptions.plugins
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
'
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
262
|
+
inputOptions.plugins = [
|
|
263
|
+
eslint({
|
|
264
|
+
include: lintIncludeDom,
|
|
265
|
+
}),
|
|
266
|
+
...inputOptions.plugins,
|
|
267
|
+
nodeResolve(),
|
|
268
|
+
image(),
|
|
269
|
+
styles({
|
|
270
|
+
mode: this.cssInJs ? 'inject' : 'extract',
|
|
271
|
+
url: true,
|
|
272
|
+
plugins: [autoprefixer()],
|
|
273
|
+
modules: this.cssModules,
|
|
274
|
+
sourceMap: this.sourcemap,
|
|
275
|
+
minimize: true,
|
|
276
|
+
}),
|
|
277
|
+
string({
|
|
278
|
+
include: '**/*.*',
|
|
279
|
+
exclude: stringExcludeDom,
|
|
280
|
+
}),
|
|
281
|
+
];
|
|
190
282
|
outputOptions.format = 'es';
|
|
191
283
|
outputOptions.plugins = [
|
|
192
284
|
terser(),
|
|
@@ -199,18 +291,24 @@ class InnetJS {
|
|
|
199
291
|
const bundle = yield rollup.rollup(inputOptions);
|
|
200
292
|
yield bundle.write(outputOptions);
|
|
201
293
|
yield bundle.close();
|
|
294
|
+
if (!node) {
|
|
295
|
+
yield copyFiles(this.publicFolder, this.buildFolder);
|
|
296
|
+
const data = yield promises.readFile(this.publicIndexFile);
|
|
297
|
+
const pkg = yield this.getPackage();
|
|
298
|
+
yield promises.writeFile(this.buildIndexFile, yield convertIndexFile(data, pkg.version));
|
|
299
|
+
}
|
|
202
300
|
}));
|
|
203
301
|
if (pkg) {
|
|
204
302
|
yield logger.start('Copy package.json', () => __awaiter(this, void 0, void 0, function* () {
|
|
205
303
|
const data = Object.assign({}, pkg);
|
|
206
304
|
delete data.private;
|
|
207
305
|
delete data.devDependencies;
|
|
208
|
-
yield fs.writeFile(path.resolve(this.buildFolder, 'package.json'), JSON.stringify(data, undefined, 2), 'UTF-8');
|
|
306
|
+
yield fs.writeFile(path$1.resolve(this.buildFolder, 'package.json'), JSON.stringify(data, undefined, 2), 'UTF-8');
|
|
209
307
|
}));
|
|
210
|
-
const pkgLockPath = path.resolve(this.projectFolder, 'package-lock.json');
|
|
308
|
+
const pkgLockPath = path$1.resolve(this.projectFolder, 'package-lock.json');
|
|
211
309
|
if (fs.existsSync(pkgLockPath)) {
|
|
212
310
|
yield logger.start('Copy package-lock.json', () => {
|
|
213
|
-
return fs.copy(pkgLockPath, path.resolve(this.buildFolder, 'package-lock.json'));
|
|
311
|
+
return fs.copy(pkgLockPath, path$1.resolve(this.buildFolder, 'package-lock.json'));
|
|
214
312
|
});
|
|
215
313
|
}
|
|
216
314
|
}
|
|
@@ -219,12 +317,13 @@ class InnetJS {
|
|
|
219
317
|
start({ node = false, error = false } = {}) {
|
|
220
318
|
return __awaiter(this, void 0, void 0, function* () {
|
|
221
319
|
const indexExtension = yield this.getProjectExtension();
|
|
222
|
-
const pkg =
|
|
223
|
-
yield logger.start('Remove build', () => fs.remove(this.
|
|
320
|
+
const pkg = yield this.getPackage();
|
|
321
|
+
yield logger.start('Remove build', () => fs.remove(this.devBuildFolder));
|
|
224
322
|
const options = {
|
|
225
|
-
input: path.resolve(this.srcFolder, `index.${indexExtension}`),
|
|
323
|
+
input: path$1.resolve(this.srcFolder, `index.${indexExtension}`),
|
|
324
|
+
preserveEntrySignatures: 'strict',
|
|
226
325
|
output: {
|
|
227
|
-
dir: this.
|
|
326
|
+
dir: this.devBuildFolder,
|
|
228
327
|
sourcemap: true
|
|
229
328
|
},
|
|
230
329
|
plugins: [
|
|
@@ -244,52 +343,60 @@ class InnetJS {
|
|
|
244
343
|
options.output.format = 'cjs';
|
|
245
344
|
options.external = Object.keys((pkg === null || pkg === void 0 ? void 0 : pkg.dependencies) || {});
|
|
246
345
|
options.plugins.push(nodeResolve({
|
|
247
|
-
moduleDirectories: [path.resolve(this.srcFolder, 'node_modules')]
|
|
346
|
+
moduleDirectories: [path$1.resolve(this.srcFolder, 'node_modules')]
|
|
248
347
|
}), string({
|
|
249
348
|
include: '**/*.*',
|
|
250
|
-
exclude:
|
|
251
|
-
'**/*.ts',
|
|
252
|
-
'**/*.tsx',
|
|
253
|
-
'**/*.js',
|
|
254
|
-
'**/*.jsx',
|
|
255
|
-
'**/*.json',
|
|
256
|
-
]
|
|
349
|
+
exclude: stringExcludeNode,
|
|
257
350
|
}), this.createServer(options.external));
|
|
258
351
|
}
|
|
259
352
|
else {
|
|
260
|
-
const key = path.basename(this.sslKey) !== this.sslKey
|
|
353
|
+
const key = path$1.basename(this.sslKey) !== this.sslKey
|
|
261
354
|
? this.sslKey
|
|
262
355
|
: fs.existsSync(this.sslKey)
|
|
263
356
|
? fs.readFileSync(this.sslKey)
|
|
264
357
|
: undefined;
|
|
265
|
-
const cert = path.basename(this.sslCrt) !== this.sslCrt
|
|
358
|
+
const cert = path$1.basename(this.sslCrt) !== this.sslCrt
|
|
266
359
|
? this.sslCrt
|
|
267
360
|
: fs.existsSync(this.sslCrt)
|
|
268
361
|
? fs.readFileSync(this.sslCrt)
|
|
269
362
|
: undefined;
|
|
270
363
|
options.output.format = 'es';
|
|
271
|
-
options.plugins
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
'
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
364
|
+
options.plugins = [
|
|
365
|
+
eslint({
|
|
366
|
+
include: lintIncludeDom,
|
|
367
|
+
}),
|
|
368
|
+
...options.plugins,
|
|
369
|
+
nodeResolve(),
|
|
370
|
+
image(),
|
|
371
|
+
styles({
|
|
372
|
+
mode: this.cssInJs ? 'inject' : 'extract',
|
|
373
|
+
url: true,
|
|
374
|
+
plugins: [autoprefixer()],
|
|
375
|
+
modules: this.cssModules,
|
|
376
|
+
sourceMap: true,
|
|
377
|
+
}),
|
|
378
|
+
string({
|
|
379
|
+
include: '**/*.*',
|
|
380
|
+
exclude: stringExcludeDom,
|
|
381
|
+
}),
|
|
382
|
+
this.createClient(key, cert, pkg),
|
|
383
|
+
livereload(Object.assign({ watch: this.publicFolder, verbose: false }, (key && cert ? { https: { key, cert } } : {})))
|
|
384
|
+
];
|
|
288
385
|
}
|
|
289
386
|
const watcher = rollup.watch(options);
|
|
290
|
-
watcher.on('event', e => {
|
|
387
|
+
watcher.on('event', (e) => __awaiter(this, void 0, void 0, function* () {
|
|
291
388
|
if (e.code == 'ERROR') {
|
|
292
|
-
|
|
389
|
+
if (e.error.code === 'UNRESOLVED_IMPORT') {
|
|
390
|
+
const [, importer, file] = e.error.message.match(/^Could not resolve '(.+)' from (.+)$/);
|
|
391
|
+
const text = (yield fs.readFile(file)).toString();
|
|
392
|
+
const lines = new LinesAndColumns(text);
|
|
393
|
+
const { line, column } = lines.locationForIndex(text.indexOf(importer));
|
|
394
|
+
logger.end('Bundling', e.error.message);
|
|
395
|
+
console.log(`ERROR in ${file}:${line + 1}:${column + 1}`);
|
|
396
|
+
}
|
|
397
|
+
else {
|
|
398
|
+
logger.end('Bundling', error ? e.error.stack : e.error.message);
|
|
399
|
+
}
|
|
293
400
|
}
|
|
294
401
|
else if (e.code === 'BUNDLE_START') {
|
|
295
402
|
logger.start('Bundling');
|
|
@@ -297,7 +404,7 @@ class InnetJS {
|
|
|
297
404
|
else if (e.code === 'BUNDLE_END') {
|
|
298
405
|
logger.end('Bundling');
|
|
299
406
|
}
|
|
300
|
-
});
|
|
407
|
+
}));
|
|
301
408
|
});
|
|
302
409
|
}
|
|
303
410
|
run(file) {
|
|
@@ -356,16 +463,16 @@ class InnetJS {
|
|
|
356
463
|
}
|
|
357
464
|
});
|
|
358
465
|
yield logger.start('Detection of index file', () => {
|
|
359
|
-
if (fs.existsSync(path.join(this.srcFolder, 'index.js'))) {
|
|
466
|
+
if (fs.existsSync(path$1.join(this.srcFolder, 'index.js'))) {
|
|
360
467
|
this.projectExtension = 'js';
|
|
361
468
|
}
|
|
362
|
-
else if (fs.existsSync(path.join(this.srcFolder, 'index.ts'))) {
|
|
469
|
+
else if (fs.existsSync(path$1.join(this.srcFolder, 'index.ts'))) {
|
|
363
470
|
this.projectExtension = 'ts';
|
|
364
471
|
}
|
|
365
|
-
else if (fs.existsSync(path.join(this.srcFolder, 'index.tsx'))) {
|
|
472
|
+
else if (fs.existsSync(path$1.join(this.srcFolder, 'index.tsx'))) {
|
|
366
473
|
this.projectExtension = 'tsx';
|
|
367
474
|
}
|
|
368
|
-
else if (fs.existsSync(path.join(this.srcFolder, 'index.jsx'))) {
|
|
475
|
+
else if (fs.existsSync(path$1.join(this.srcFolder, 'index.jsx'))) {
|
|
369
476
|
this.projectExtension = 'jsx';
|
|
370
477
|
}
|
|
371
478
|
else {
|
|
@@ -380,7 +487,7 @@ class InnetJS {
|
|
|
380
487
|
if (this.package) {
|
|
381
488
|
return this.package;
|
|
382
489
|
}
|
|
383
|
-
const packageFolder = path.resolve(this.projectFolder, 'package.json');
|
|
490
|
+
const packageFolder = path$1.resolve(this.projectFolder, 'package.json');
|
|
384
491
|
yield logger.start('Check package.json', () => __awaiter(this, void 0, void 0, function* () {
|
|
385
492
|
if (fs.existsSync(packageFolder)) {
|
|
386
493
|
this.package = yield fs.readJson(packageFolder);
|
|
@@ -389,14 +496,21 @@ class InnetJS {
|
|
|
389
496
|
return this.package;
|
|
390
497
|
});
|
|
391
498
|
}
|
|
392
|
-
createClient(key, cert) {
|
|
499
|
+
createClient(key, cert, pkg) {
|
|
393
500
|
let app;
|
|
394
501
|
return {
|
|
395
|
-
writeBundle: () => {
|
|
502
|
+
writeBundle: () => __awaiter(this, void 0, void 0, function* () {
|
|
396
503
|
var _a;
|
|
397
504
|
if (!app) {
|
|
398
|
-
const httpsUsing = !!(cert && key);
|
|
399
505
|
app = express();
|
|
506
|
+
const update = () => __awaiter(this, void 0, void 0, function* () {
|
|
507
|
+
const data = yield promises.readFile(this.publicIndexFile);
|
|
508
|
+
yield promises.writeFile(this.devBuildIndexFile, yield convertIndexFile(data, pkg.version));
|
|
509
|
+
});
|
|
510
|
+
fs.watch(this.publicIndexFile, update);
|
|
511
|
+
yield update();
|
|
512
|
+
const httpsUsing = !!(cert && key);
|
|
513
|
+
app.use(express.static(this.devBuildFolder));
|
|
400
514
|
app.use(express.static(this.publicFolder));
|
|
401
515
|
if ((_a = this.proxy) === null || _a === void 0 ? void 0 : _a.startsWith('http')) {
|
|
402
516
|
app.use(this.api, proxy(this.proxy, {
|
|
@@ -405,14 +519,14 @@ class InnetJS {
|
|
|
405
519
|
}));
|
|
406
520
|
}
|
|
407
521
|
app.use(/^[^.]+$/, (req, res) => {
|
|
408
|
-
res.sendFile(this.
|
|
522
|
+
res.sendFile(this.devBuildFolder + '/index.html');
|
|
409
523
|
});
|
|
410
524
|
const server = httpsUsing ? https.createServer({ key, cert }, app) : http.createServer(app);
|
|
411
525
|
server.listen(this.port, () => {
|
|
412
526
|
console.log(`${chalk.green('➤')} Server started on http${httpsUsing ? 's' : ''}://localhost:${this.port}`);
|
|
413
527
|
});
|
|
414
528
|
}
|
|
415
|
-
}
|
|
529
|
+
})
|
|
416
530
|
};
|
|
417
531
|
}
|
|
418
532
|
createServer(external) {
|
|
@@ -420,10 +534,10 @@ class InnetJS {
|
|
|
420
534
|
return {
|
|
421
535
|
writeBundle: () => __awaiter(this, void 0, void 0, function* () {
|
|
422
536
|
app === null || app === void 0 ? void 0 : app.kill();
|
|
423
|
-
const filePath = path.resolve(this.buildFolder, 'index.js');
|
|
537
|
+
const filePath = path$1.resolve(this.buildFolder, 'index.js');
|
|
424
538
|
let data = yield fs.readFile(filePath, 'UTF-8');
|
|
425
539
|
const regExp = new RegExp(`require\\('(${external.join('|')})'\\)`, 'g');
|
|
426
|
-
data = data.replace(regExp, `require('${path.resolve(this.projectFolder, 'node_modules', '$1')}')`);
|
|
540
|
+
data = data.replace(regExp, `require('${path$1.resolve(this.projectFolder, 'node_modules', '$1')}')`);
|
|
427
541
|
yield fs.writeFile(filePath, data);
|
|
428
542
|
app = spawn('node', ['-r', 'source-map-support/register', filePath], { stdio: 'inherit' });
|
|
429
543
|
})
|