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.
@@ -1,3 +1,4 @@
1
+ import { __awaiter } from 'tslib';
1
2
  import logger from '@cantinc/logger';
2
3
  import commonjs from '@rollup/plugin-commonjs';
3
4
  import eslint from '@rollup/plugin-eslint';
@@ -13,10 +14,10 @@ import express from 'express';
13
14
  import proxy from 'express-http-proxy';
14
15
  import fs, { promises } from 'fs-extra';
15
16
  import glob from 'glob';
16
- import http from 'http';
17
- import https from 'https';
17
+ import http from 'node:http';
18
+ import https from 'node:https';
18
19
  import { LinesAndColumns } from 'lines-and-columns';
19
- import path$1 from 'path';
20
+ import path from 'node:path';
20
21
  import prompt from 'prompts';
21
22
  import rollup from 'rollup';
22
23
  import filesize from 'rollup-plugin-filesize';
@@ -29,138 +30,10 @@ import styles from 'rollup-plugin-styles';
29
30
  import { terser } from 'rollup-plugin-terser';
30
31
  import typescript from 'rollup-plugin-typescript2';
31
32
  import tmp from 'tmp';
32
- import { promisify } from 'util';
33
- import { Parse } from 'unzipper';
34
-
35
- /******************************************************************************
36
- Copyright (c) Microsoft Corporation.
37
-
38
- Permission to use, copy, modify, and/or distribute this software for any
39
- purpose with or without fee is hereby granted.
40
-
41
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
42
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
43
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
44
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
45
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
46
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
47
- PERFORMANCE OF THIS SOFTWARE.
48
- ***************************************************************************** */
49
-
50
- function __awaiter(thisArg, _arguments, P, generator) {
51
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
52
- return new (P || (P = Promise))(function (resolve, reject) {
53
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
54
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
55
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
56
- step((generator = generator.apply(thisArg, _arguments || [])).next());
57
- });
58
- }
59
-
60
- const lintInclude = [
61
- '**/*.ts',
62
- '**/*.tsx',
63
- '**/*.js',
64
- '**/*.jsx',
65
- ];
66
- const stringExcludeDom = [
67
- '**/*.ts',
68
- '**/*.tsx',
69
- '**/*.js',
70
- '**/*.jsx',
71
- '**/*.json',
72
- '**/*.css',
73
- '**/*.scss',
74
- '**/*.webp',
75
- '**/*.gif',
76
- '**/*.png',
77
- '**/*.jpeg',
78
- '**/*.jpg',
79
- '**/*.svg',
80
- ];
81
- const stringExcludeNode = [
82
- '**/*.ts',
83
- '**/*.tsx',
84
- '**/*.js',
85
- '**/*.jsx',
86
- '**/*.json',
87
- ];
88
-
89
- const Writer = require('fstream').Writer;
90
- const path = require('path');
91
- const stream = require('stream');
92
- const duplexer2 = require('duplexer2');
93
- const Promise$1 = require('bluebird');
94
- function Extract(opts, template) {
95
- const reduceCount = 19 + template.length;
96
- // make sure path is normalized before using it
97
- opts.path = path.resolve(path.normalize(opts.path));
98
- // @ts-expect-error
99
- const parser = new Parse(opts);
100
- const outStream = new stream.Writable({ objectMode: true });
101
- outStream._write = function (entry, encoding, cb) {
102
- if (entry.type === 'Directory')
103
- return cb();
104
- const extractPath = path.join(opts.path, entry.path.slice(reduceCount));
105
- if (extractPath.indexOf(opts.path) !== 0) {
106
- return cb();
107
- }
108
- const writer = opts.getWriter ? opts.getWriter({ path: extractPath }) : Writer({ path: extractPath });
109
- entry.pipe(writer)
110
- .on('error', cb)
111
- .on('close', cb);
112
- };
113
- const extract = duplexer2(parser, outStream);
114
- parser.once('crx-header', function (crxHeader) {
115
- extract.crxHeader = crxHeader;
116
- });
117
- parser
118
- .pipe(outStream)
119
- .on('finish', function () {
120
- extract.emit('close');
121
- });
122
- extract.promise = function () {
123
- return new Promise$1(function (resolve, reject) {
124
- extract.on('close', resolve);
125
- extract.on('error', reject);
126
- });
127
- };
128
- return extract;
129
- }
130
-
131
- function getFile(file) {
132
- file = path$1.resolve(file);
133
- if (!fs.existsSync(file)) {
134
- throw Error('Cannot find the file: ' + file);
135
- }
136
- if (fs.lstatSync(file).isDirectory()) {
137
- let tmpFile = file;
138
- if (!fs.existsSync(tmpFile = path$1.join(file, 'index.ts')) &&
139
- !fs.existsSync(tmpFile = path$1.join(file, 'index.tsx')) &&
140
- !fs.existsSync(tmpFile = path$1.join(file, 'index.js'))) {
141
- throw Error('Cannot find index file in: ' + file);
142
- }
143
- file = tmpFile;
144
- }
145
- else if (!file.endsWith('.ts') && !file.endsWith('.tsx') && !file.endsWith('.js')) {
146
- throw Error('File should has `.ts` or `.tsx` or `.js` extension: ' + file);
147
- }
148
- if (!fs.existsSync(file)) {
149
- throw Error('Cannot find the file: ' + file);
150
- }
151
- return file;
152
- }
153
- function convertIndexFile(data, version, baseUrl) {
154
- return __awaiter(this, void 0, void 0, function* () {
155
- return data
156
- .toString()
157
- .replace('</head>', `<script type="module" defer src="${baseUrl}index.js${version ? `?v=${version}` : ''}"></script></head>`);
158
- });
159
- }
160
- const reporter = (options, outputOptions, info) => {
161
- logger.log(`${chalk.yellow(info.fileName)} ${chalk.green(info.bundleSize)} [ gzip: ${chalk.green(info.gzipSize)} ]`);
162
- return '';
163
- };
33
+ import { promisify } from 'node:util';
34
+ import { lintInclude, stringExcludeNode, stringExcludeDom } from './constants.mjs';
35
+ import { Extract } from './extract.mjs';
36
+ import { reporter, convertIndexFile, getFile } from './helpers.mjs';
164
37
 
165
38
  const livereload = require('rollup-plugin-livereload');
166
39
  const { string } = require('rollup-plugin-string');
@@ -186,21 +59,21 @@ const scriptExtensions = ['ts', 'js', 'tsx', 'jsx'];
186
59
  const indexExt = scriptExtensions.join(',');
187
60
  class InnetJS {
188
61
  constructor({ projectFolder = process.env.PROJECT_FOLDER || '', baseUrl = process.env.BASE_URL || '/', publicFolder = process.env.PUBLIC_FOLDER || 'public', releaseFolder = process.env.RELEASE_FOLDER || 'release', 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/?*', } = {}) {
189
- this.projectFolder = path$1.resolve(projectFolder);
190
- this.publicFolder = path$1.resolve(publicFolder);
191
- this.releaseFolder = path$1.resolve(releaseFolder);
192
- this.buildFolder = path$1.resolve(buildFolder);
193
- this.srcFolder = path$1.resolve(srcFolder);
194
- this.licenseFile = path$1.join(projectFolder, 'LICENSE');
195
- this.licenseReleaseFile = path$1.join(releaseFolder, 'LICENSE');
196
- this.readmeFile = path$1.join(projectFolder, 'README.md');
197
- this.readmeReleaseFile = path$1.join(releaseFolder, 'README.md');
198
- this.declarationFile = path$1.join(srcFolder, 'declaration.d.ts');
199
- this.declarationReleaseFile = path$1.join(releaseFolder, 'declaration.d.ts');
200
- this.publicIndexFile = path$1.join(publicFolder, 'index.html');
201
- this.buildIndexFile = path$1.join(buildFolder, 'index.html');
202
- this.devBuildFolder = path$1.resolve(projectFolder, 'node_modules', '.cache', 'innetjs', 'build');
203
- this.devBuildIndexFile = path$1.join(this.devBuildFolder, 'index.html');
62
+ this.projectFolder = path.resolve(projectFolder);
63
+ this.publicFolder = path.resolve(publicFolder);
64
+ this.releaseFolder = path.resolve(releaseFolder);
65
+ this.buildFolder = path.resolve(buildFolder);
66
+ this.srcFolder = path.resolve(srcFolder);
67
+ this.licenseFile = path.join(projectFolder, 'LICENSE');
68
+ this.licenseReleaseFile = path.join(releaseFolder, 'LICENSE');
69
+ this.readmeFile = path.join(projectFolder, 'README.md');
70
+ this.readmeReleaseFile = path.join(releaseFolder, 'README.md');
71
+ this.declarationFile = path.join(srcFolder, 'declaration.d.ts');
72
+ this.declarationReleaseFile = path.join(releaseFolder, 'declaration.d.ts');
73
+ this.publicIndexFile = path.join(publicFolder, 'index.html');
74
+ this.buildIndexFile = path.join(buildFolder, 'index.html');
75
+ this.devBuildFolder = path.resolve(projectFolder, 'node_modules', '.cache', 'innetjs', 'build');
76
+ this.devBuildIndexFile = path.join(this.devBuildFolder, 'index.html');
204
77
  this.sourcemap = sourcemap;
205
78
  this.cssModules = cssModules;
206
79
  this.cssInJs = cssInJs;
@@ -214,7 +87,7 @@ class InnetJS {
214
87
  // Methods
215
88
  init(appName, { template, force = false } = {}) {
216
89
  return __awaiter(this, void 0, void 0, function* () {
217
- const appPath = path$1.resolve(appName);
90
+ const appPath = path.resolve(appName);
218
91
  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'); }));
219
92
  const templates = data.map(({ name }) => name).filter(name => name !== 'main');
220
93
  if (!template || !templates.includes(template)) {
@@ -288,7 +161,7 @@ class InnetJS {
288
161
  outputOptions.format = 'cjs';
289
162
  inputOptions.external = Object.keys((pkg === null || pkg === void 0 ? void 0 : pkg.dependencies) || {});
290
163
  inputOptions.plugins.push(nodeResolve({
291
- moduleDirectories: [path$1.resolve(this.buildFolder, 'node_modules')],
164
+ moduleDirectories: [path.resolve(this.buildFolder, 'node_modules')],
292
165
  }), string({
293
166
  include: '**/*.*',
294
167
  exclude: stringExcludeNode,
@@ -332,12 +205,12 @@ class InnetJS {
332
205
  const data = Object.assign({}, pkg);
333
206
  delete data.private;
334
207
  delete data.devDependencies;
335
- yield fs.writeFile(path$1.resolve(this.buildFolder, 'package.json'), JSON.stringify(data, undefined, 2), 'UTF-8');
208
+ yield fs.writeFile(path.resolve(this.buildFolder, 'package.json'), JSON.stringify(data, undefined, 2), 'UTF-8');
336
209
  }));
337
- const pkgLockPath = path$1.resolve(this.projectFolder, 'package-lock.json');
210
+ const pkgLockPath = path.resolve(this.projectFolder, 'package-lock.json');
338
211
  if (fs.existsSync(pkgLockPath)) {
339
212
  yield logger.start('Copy package-lock.json', () => {
340
- return fs.copy(pkgLockPath, path$1.resolve(this.buildFolder, 'package-lock.json'));
213
+ return fs.copy(pkgLockPath, path.resolve(this.buildFolder, 'package-lock.json'));
341
214
  });
342
215
  }
343
216
  }
@@ -379,19 +252,19 @@ class InnetJS {
379
252
  options.output.format = 'cjs';
380
253
  options.external = Object.keys((pkg === null || pkg === void 0 ? void 0 : pkg.dependencies) || {});
381
254
  options.plugins.push(nodeResolve({
382
- moduleDirectories: [path$1.resolve(this.srcFolder, 'node_modules')],
255
+ moduleDirectories: [path.resolve(this.srcFolder, 'node_modules')],
383
256
  }), string({
384
257
  include: '**/*.*',
385
258
  exclude: stringExcludeNode,
386
259
  }), this.createServer());
387
260
  }
388
261
  else {
389
- const key = path$1.basename(this.sslKey) !== this.sslKey
262
+ const key = path.basename(this.sslKey) !== this.sslKey
390
263
  ? this.sslKey
391
264
  : fs.existsSync(this.sslKey)
392
265
  ? fs.readFileSync(this.sslKey)
393
266
  : undefined;
394
- const cert = path$1.basename(this.sslCrt) !== this.sslCrt
267
+ const cert = path.basename(this.sslCrt) !== this.sslCrt
395
268
  ? this.sslCrt
396
269
  : fs.existsSync(this.sslCrt)
397
270
  ? fs.readFileSync(this.sslCrt)
@@ -488,7 +361,7 @@ class InnetJS {
488
361
  }));
489
362
  });
490
363
  }
491
- release({ node = false, index = 'index', release, } = {}) {
364
+ release({ node = false, index = 'index', release, pub } = {}) {
492
365
  return __awaiter(this, void 0, void 0, function* () {
493
366
  const { releaseFolder, cssModules } = this;
494
367
  yield logger.start('Remove previous release', () => fs.remove(releaseFolder));
@@ -514,7 +387,7 @@ class InnetJS {
514
387
  default: return;
515
388
  }
516
389
  pkg.version = version.join('.');
517
- yield fs.writeFile(path$1.resolve(this.projectFolder, 'package.json'), JSON.stringify(pkg, undefined, 2), 'UTF-8');
390
+ yield fs.writeFile(path.resolve(this.projectFolder, 'package.json'), JSON.stringify(pkg, undefined, 2), 'UTF-8');
518
391
  }));
519
392
  function build(format) {
520
393
  var _a, _b;
@@ -594,7 +467,7 @@ class InnetJS {
594
467
  const data = Object.assign({}, pkg);
595
468
  delete data.private;
596
469
  delete data.devDependencies;
597
- yield fs.writeFile(path$1.resolve(this.releaseFolder, 'package.json'), JSON.stringify(data, undefined, 2), 'UTF-8');
470
+ yield fs.writeFile(path.resolve(this.releaseFolder, 'package.json'), JSON.stringify(data, undefined, 2), 'UTF-8');
598
471
  }));
599
472
  if (pkg.bin) {
600
473
  yield logger.start('Build bin', () => __awaiter(this, void 0, void 0, function* () {
@@ -602,7 +475,7 @@ class InnetJS {
602
475
  for (const name in bin) {
603
476
  const value = bin[name];
604
477
  const input = glob.sync(`src/${value}.{${scriptExtensions.join(',')}}`);
605
- const file = path$1.join(this.releaseFolder, value);
478
+ const file = path.join(this.releaseFolder, value);
606
479
  const options = {
607
480
  input,
608
481
  external: [...Object.keys(pkg.dependencies), 'tslib'],
@@ -646,6 +519,12 @@ class InnetJS {
646
519
  yield promises.copyFile(this.declarationFile, this.declarationReleaseFile);
647
520
  }));
648
521
  }
522
+ if (pub) {
523
+ const date = (Date.now() / 1000) | 0;
524
+ yield logger.start(`publishing v${pkg.version} ${date}`, () => __awaiter(this, void 0, void 0, function* () {
525
+ yield execAsync(`npm publish ${this.releaseFolder}`);
526
+ }));
527
+ }
649
528
  });
650
529
  }
651
530
  getPackage() {
@@ -653,7 +532,7 @@ class InnetJS {
653
532
  if (this.package) {
654
533
  return this.package;
655
534
  }
656
- const packageFolder = path$1.resolve(this.projectFolder, 'package.json');
535
+ const packageFolder = path.resolve(this.projectFolder, 'package.json');
657
536
  yield logger.start('Check package.json', () => __awaiter(this, void 0, void 0, function* () {
658
537
  if (fs.existsSync(packageFolder)) {
659
538
  this.package = yield fs.readJson(packageFolder);
@@ -721,7 +600,7 @@ class InnetJS {
721
600
  name: 'server',
722
601
  writeBundle: () => __awaiter(this, void 0, void 0, function* () {
723
602
  app === null || app === void 0 ? void 0 : app.kill();
724
- const filePath = path$1.resolve(this.devBuildFolder, 'index.js');
603
+ const filePath = path.resolve(this.devBuildFolder, 'index.js');
725
604
  app = spawn('node', ['-r', 'source-map-support/register', filePath], { stdio: 'inherit' });
726
605
  }),
727
606
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "innetjs",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "description": "CLI for innet boilerplate",
5
5
  "homepage": "https://github.com/d8corp/innetjs",
6
6
  "author": "Mikhail Lysikov <d8corp@mail.ru>",
@@ -13,6 +13,18 @@
13
13
  "bin": {
14
14
  "innetjs": "bin/innet"
15
15
  },
16
+ "scripts": {
17
+ "build": "innetjs release -n",
18
+ "test": "jest",
19
+ "lint": "eslint src --ext .ts,.tsx",
20
+ "lint:fix": "eslint src --ext .ts,.tsx --fix",
21
+ "start": "npm run build && cd lib && npm link",
22
+ "stop": "npm unlink innetjs -g",
23
+ "restart": "npm run stop && npm start",
24
+ "patch": "innetjs release -n -r patch",
25
+ "minor": "innetjs release -n -r minor",
26
+ "major": "innetjs release -n -r major"
27
+ },
16
28
  "repository": {
17
29
  "type": "git",
18
30
  "url": "https://github.com/d8corp/innetjs.git"
@@ -74,4 +86,4 @@
74
86
  "typescript": "^4.8.4",
75
87
  "unzipper": "^0.10.11"
76
88
  }
77
- }
89
+ }