leanweb 1.3.6 → 2.0.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/README.md +0 -29
- package/commands/build.js +93 -121
- package/commands/clean.js +3 -3
- package/commands/destroy.js +19 -20
- package/commands/dist.js +47 -52
- package/commands/generate.js +40 -41
- package/commands/help.js +23 -23
- package/commands/init.js +71 -80
- package/commands/serve.js +42 -63
- package/commands/upgrade.js +14 -43
- package/commands/utils.js +56 -124
- package/commands/version.js +1 -0
- package/leanweb.js +50 -51
- package/lib/lw-html-parser.js +82 -82
- package/package.json +35 -43
- package/templates/component.js +43 -43
- package/templates/env/prod.js +1 -1
- package/templates/env/test.js +1 -1
- package/templates/env.js +1 -1
- package/templates/index.html +6 -6
- package/templates/lib/api-client.js +50 -50
- package/templates/lib/lw-element.js +437 -438
- package/templates/lib/lw-event-bus.js +34 -34
- package/templates/lib/lw-expr-parser.js +163 -163
- package/commands/electron.js +0 -71
- package/templates/electron.js +0 -43
package/commands/init.js
CHANGED
|
@@ -1,51 +1,44 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import fse from 'fs-extra';
|
|
3
|
-
import git from 'isomorphic-git';
|
|
4
|
-
import { globby } from 'globby';
|
|
5
|
-
import * as utils from './utils.js';
|
|
6
|
-
|
|
7
1
|
import path from 'path';
|
|
8
2
|
import { fileURLToPath } from 'url';
|
|
9
3
|
const __filename = fileURLToPath(import.meta.url);
|
|
10
4
|
const __dirname = path.dirname(__filename);
|
|
11
|
-
|
|
12
5
|
import { createRequire } from "module";
|
|
13
6
|
const require = createRequire(import.meta.url);
|
|
14
7
|
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
import fs from 'fs';
|
|
9
|
+
import fse from 'fs-extra';
|
|
10
|
+
import git from 'isomorphic-git';
|
|
11
|
+
import { globby } from 'globby';
|
|
12
|
+
import * as utils from './utils.js';
|
|
17
13
|
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
(async () => {
|
|
15
|
+
const args = process.argv;
|
|
20
16
|
|
|
21
|
-
|
|
17
|
+
const leanwebJSONExisted = fs.existsSync(`${process.cwd()}/${utils.dirs.src}/leanweb.json`);
|
|
22
18
|
|
|
23
|
-
|
|
24
|
-
console.error('Error: leanweb.json existed.');
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
19
|
+
const lwPackage = require(`${__dirname}/../package.json`);
|
|
27
20
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
if (leanwebJSONExisted) {
|
|
22
|
+
console.error('Error: leanweb.json existed.');
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
31
25
|
|
|
32
|
-
|
|
26
|
+
let projectName = path.basename(path.resolve());
|
|
33
27
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
if (args.length >= 3) {
|
|
29
|
+
projectName = args[2];
|
|
30
|
+
}
|
|
37
31
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
resources
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
};
|
|
32
|
+
const leanwebData = {
|
|
33
|
+
name: projectName,
|
|
34
|
+
version: lwPackage.version,
|
|
35
|
+
components: [],
|
|
36
|
+
resources: [
|
|
37
|
+
'resources/'
|
|
38
|
+
],
|
|
39
|
+
};
|
|
47
40
|
|
|
48
|
-
|
|
41
|
+
const projectScss = `// html,
|
|
49
42
|
// body {
|
|
50
43
|
// height: 100%;
|
|
51
44
|
// width: 100%;
|
|
@@ -56,55 +49,53 @@ const require = createRequire(import.meta.url);
|
|
|
56
49
|
// }
|
|
57
50
|
`
|
|
58
51
|
|
|
59
|
-
|
|
52
|
+
const globalScss = `// div {
|
|
60
53
|
// color: tomato;
|
|
61
54
|
// }
|
|
62
55
|
`;
|
|
63
56
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
console.log('"lw h" to get more help information.');
|
|
109
|
-
}
|
|
57
|
+
fs.mkdirSync(`${utils.dirs.src}/resources/`, { recursive: true });
|
|
58
|
+
fs.writeFileSync(`${utils.dirs.src}/leanweb.json`, JSON.stringify(leanwebData, null, 2));
|
|
59
|
+
|
|
60
|
+
utils.exec(`npx leanweb generate root`);
|
|
61
|
+
|
|
62
|
+
fse.copySync(`${__dirname}/../templates/lib`, `./${utils.dirs.src}/lib/`);
|
|
63
|
+
|
|
64
|
+
let htmlString = fs.readFileSync(`${__dirname}/../templates/index.html`, 'utf8');
|
|
65
|
+
htmlString = htmlString.replace(/\$\{project\.name\}/g, projectName);
|
|
66
|
+
fs.writeFileSync(`./${utils.dirs.src}/index.html`, htmlString);
|
|
67
|
+
fs.writeFileSync(`./src/${projectName}.scss`, projectScss);
|
|
68
|
+
fs.writeFileSync(`./${utils.dirs.src}/global-styles.scss`, globalScss);
|
|
69
|
+
fse.copySync(`${__dirname}/../templates/favicon.svg`, `./${utils.dirs.src}/favicon.svg`);
|
|
70
|
+
fse.copySync(`${__dirname}/../templates/env.js`, `./${utils.dirs.src}/env.js`);
|
|
71
|
+
fse.copySync(`${__dirname}/../templates/env/`, `./${utils.dirs.src}/env/`);
|
|
72
|
+
|
|
73
|
+
if (!(fs.existsSync(`${process.cwd()}/.git/`) && fs.statSync(`${process.cwd()}/.git/`).isDirectory())) {
|
|
74
|
+
await git.init({ fs, dir: process.cwd() });
|
|
75
|
+
|
|
76
|
+
if (fs.existsSync(`${process.cwd()}/.gitignore`) && fs.statSync(`${process.cwd()}/.gitignore`).isFile()) {
|
|
77
|
+
fs.appendFileSync(`${process.cwd()}/.gitignore`, `\n${utils.dirs.build}/\n${utils.dirs.dist}/\n${utils.dirs.serve}/\n`, 'utf8');
|
|
78
|
+
} else {
|
|
79
|
+
fs.writeFileSync(`${process.cwd()}/.gitignore`, `${utils.dirs.build}/\n${utils.dirs.dist}/\n${utils.dirs.serve}/\n`, 'utf8');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const paths = await globby(['./**', './**/.*'], { gitignore: true });
|
|
83
|
+
for (const filepath of paths) {
|
|
84
|
+
await git.add({ fs, dir: process.cwd(), filepath });
|
|
85
|
+
}
|
|
86
|
+
await git.commit({
|
|
87
|
+
fs,
|
|
88
|
+
dir: process.cwd(),
|
|
89
|
+
author: {
|
|
90
|
+
name: 'Leanweb',
|
|
91
|
+
email: 'leanweb@leanweb.app',
|
|
92
|
+
},
|
|
93
|
+
message: 'lw init'
|
|
94
|
+
});
|
|
95
|
+
console.log('\nSome useful commands:');
|
|
96
|
+
console.log('"lw s" to start the dev server.');
|
|
97
|
+
console.log('"lw di" to build for production. The output will be in dist/ directory.');
|
|
98
|
+
console.log('"lw g my-new-component" to generate a new standard web component.');
|
|
99
|
+
console.log('"lw h" to get more help information.');
|
|
100
|
+
}
|
|
110
101
|
})();
|
package/commands/serve.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
+
import { createRequire } from "module";
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
|
|
1
4
|
import fs from 'fs';
|
|
2
5
|
import fse from 'fs-extra';
|
|
3
6
|
import * as utils from './utils.js';
|
|
4
|
-
import webpack from 'webpack';
|
|
5
7
|
import watch from 'node-watch';
|
|
6
|
-
import
|
|
8
|
+
import liveServer from 'live-server';
|
|
7
9
|
|
|
8
|
-
import { createRequire } from "module";
|
|
9
|
-
const require = createRequire(import.meta.url);
|
|
10
10
|
|
|
11
11
|
let env = '';
|
|
12
12
|
const args = process.argv;
|
|
13
13
|
if (args.length >= 3) {
|
|
14
|
-
|
|
14
|
+
env = args[2];
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
const host = process.env.host || '127.0.0.1';
|
|
@@ -20,62 +20,41 @@ const noopen = process.env.noopen || false;
|
|
|
20
20
|
|
|
21
21
|
(async () => {
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const compiler = webpack(webpackDevConfig);
|
|
63
|
-
|
|
64
|
-
while (await utils.portInUse(port, host)) {
|
|
65
|
-
++port;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const devServerOptions = {
|
|
69
|
-
...webpackDevConfig.devServer,
|
|
70
|
-
static: {
|
|
71
|
-
directory: process.cwd() + `/${utils.dirs.serve}/`,
|
|
72
|
-
watch: true,
|
|
73
|
-
},
|
|
74
|
-
port,
|
|
75
|
-
host,
|
|
76
|
-
open: !noopen,
|
|
77
|
-
};
|
|
78
|
-
const server = new WebpackDevServer(devServerOptions, compiler);
|
|
79
|
-
|
|
80
|
-
server.start();
|
|
23
|
+
const project = require(`${process.cwd()}/${utils.dirs.src}/leanweb.json`);
|
|
24
|
+
|
|
25
|
+
const build = async (eventType, filename) => {
|
|
26
|
+
// console.log(eventType + ': ', filename);
|
|
27
|
+
try {
|
|
28
|
+
await utils.exec(`npx leanweb build ${env}`);
|
|
29
|
+
fse.copySync(`./${utils.dirs.build}/index.html`, `./${utils.dirs.serve}/index.html`);
|
|
30
|
+
fse.copySync(`./${utils.dirs.build}/${project.name}.css`, `./${utils.dirs.serve}/${project.name}.css`);
|
|
31
|
+
fse.copySync(`./${utils.dirs.build}/favicon.svg`, `./${utils.dirs.serve}/favicon.svg`);
|
|
32
|
+
project.resources?.forEach(resource => {
|
|
33
|
+
const source = `./${utils.dirs.build}/${resource}`;
|
|
34
|
+
if (fs.existsSync(source)) {
|
|
35
|
+
fse.copySync(source, `./${utils.dirs.serve}/${resource}`, { filter: utils.copySymbolLinkFilter });
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
} catch (e) {
|
|
39
|
+
console.error(e);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const throttledBuild = utils.throttle(build);
|
|
44
|
+
watch(process.cwd() + `/${utils.dirs.src}/`, { recursive: true }, (eventType, filename) => {
|
|
45
|
+
throttledBuild(eventType, filename);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
build();
|
|
49
|
+
|
|
50
|
+
const params = {
|
|
51
|
+
port,
|
|
52
|
+
host,
|
|
53
|
+
root: utils.dirs.build,
|
|
54
|
+
open: !noopen,
|
|
55
|
+
file: 'index.html',
|
|
56
|
+
wait: 1000,
|
|
57
|
+
logLevel: 0,
|
|
58
|
+
};
|
|
59
|
+
liveServer.start(params);
|
|
81
60
|
})();
|
package/commands/upgrade.js
CHANGED
|
@@ -1,61 +1,32 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import fse from 'fs-extra';
|
|
3
|
-
import semver from 'semver';
|
|
4
|
-
import * as utils from './utils.js';
|
|
5
|
-
|
|
6
1
|
import path from 'path';
|
|
7
2
|
import { fileURLToPath } from 'url';
|
|
8
3
|
const __filename = fileURLToPath(import.meta.url);
|
|
9
4
|
const __dirname = path.dirname(__filename);
|
|
10
|
-
|
|
11
5
|
import { createRequire } from "module";
|
|
12
6
|
const require = createRequire(import.meta.url);
|
|
13
7
|
|
|
8
|
+
import fs from 'fs';
|
|
9
|
+
import fse from 'fs-extra';
|
|
10
|
+
import semver from 'semver';
|
|
11
|
+
import * as utils from './utils.js';
|
|
12
|
+
|
|
14
13
|
const leanwebPackageJSON = require(`${__dirname}/../package.json`);
|
|
15
14
|
const projectLeanwebJSON = require(`${process.cwd()}/${utils.dirs.src}/leanweb.json`);
|
|
16
15
|
|
|
17
|
-
const upgradeTo045 = () => {
|
|
18
|
-
const projectName = projectLeanwebJSON.name;
|
|
19
|
-
projectLeanwebJSON.components.forEach(cmp => {
|
|
20
|
-
const component = projectName + '-' + cmp;
|
|
21
|
-
|
|
22
|
-
const filePath = process.cwd() + `/${utils.dirs.src}/components/` + cmp + '/' + cmp + '.js';
|
|
23
|
-
const oldSrc = fs.readFileSync(filePath, 'utf8');
|
|
24
|
-
const newSrc = oldSrc.replace(/import\s+interpolation\s+from\s+\'.\/ast\.js\';/, 'import ast from \'./ast.js\';')
|
|
25
|
-
.replace(/const\s+component\s+=\s+{\s+id\:\s+'.+?',\s+interpolation\s+};/, '')
|
|
26
|
-
.replace(/component\.id/g, '\'' + component + '\'')
|
|
27
|
-
.replace(/super\(component\);/, 'super(ast);');
|
|
28
|
-
fs.writeFileSync(filePath, newSrc);
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const upgradeTo081 = () => {
|
|
33
|
-
fse.copySync(`${__dirname}/../templates/env`, `./${utils.dirs.src}/env/`);
|
|
34
|
-
fse.copySync(`${__dirname}/../templates/env.js`, `./${utils.dirs.src}/env.js`);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
16
|
const upgradeTo088 = () => {
|
|
38
|
-
|
|
17
|
+
utils.exec(`npm i -D @babel/runtime --loglevel=error`);
|
|
39
18
|
};
|
|
40
19
|
|
|
41
20
|
const upgradeAvailable = semver.gt(leanwebPackageJSON.version, projectLeanwebJSON.version);
|
|
42
21
|
if (upgradeAvailable) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (semver.gte(leanwebPackageJSON.version, '0.4.5') && semver.lt(oldVersion, '0.4.5')) {
|
|
49
|
-
upgradeTo045();
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (semver.gte(leanwebPackageJSON.version, '0.8.1') && semver.lt(oldVersion, '0.8.1')) {
|
|
53
|
-
upgradeTo081();
|
|
54
|
-
}
|
|
22
|
+
fse.copySync(`${__dirname}/../templates/lib`, `./${utils.dirs.src}/lib/`, { dereference: true });
|
|
23
|
+
const oldVersion = projectLeanwebJSON.version;
|
|
24
|
+
projectLeanwebJSON.version = leanwebPackageJSON.version;
|
|
25
|
+
fs.writeFileSync(`${process.cwd()}/${utils.dirs.src}/leanweb.json`, JSON.stringify(projectLeanwebJSON, null, 2));
|
|
55
26
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
27
|
+
if (semver.gte(leanwebPackageJSON.version, '0.8.8') && semver.lt(oldVersion, '0.8.8')) {
|
|
28
|
+
upgradeTo088();
|
|
29
|
+
}
|
|
59
30
|
|
|
60
|
-
|
|
31
|
+
console.log('Leanweb upgraded:', oldVersion, '=>', leanwebPackageJSON.version);
|
|
61
32
|
}
|
package/commands/utils.js
CHANGED
|
@@ -1,139 +1,76 @@
|
|
|
1
|
-
// const { execSync } = require('child_process');
|
|
2
1
|
import { execSync } from 'child_process';
|
|
3
|
-
// const sass = require('sass');
|
|
4
2
|
import sass from 'sass';
|
|
5
|
-
// import path from 'path';
|
|
6
3
|
import path from 'path';
|
|
7
|
-
// const net = require('net');
|
|
8
4
|
import net from 'net';
|
|
9
|
-
|
|
10
|
-
// import fse from 'fs-extra';
|
|
11
5
|
import fse from 'fs-extra';
|
|
12
6
|
|
|
13
|
-
import { createRequire } from "module";
|
|
14
|
-
const require = createRequire(import.meta.url);
|
|
15
|
-
|
|
16
7
|
export const dirs = {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
electron: 'electron',
|
|
8
|
+
src: 'src',
|
|
9
|
+
build: 'build',
|
|
10
|
+
serve: 'serve',
|
|
11
|
+
dist: 'dist',
|
|
22
12
|
};
|
|
23
13
|
|
|
24
14
|
export const copySymbolLinkFilter = (src, dest) => {
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
const destStats = fse.existsSync(dest) && fse.lstatSync(dest);
|
|
16
|
+
return !destStats?.isSymbolicLink?.();
|
|
27
17
|
};
|
|
28
18
|
|
|
29
19
|
export const exec = command => execSync(command, { encoding: 'utf8', stdio: 'inherit' });
|
|
30
20
|
|
|
31
21
|
export const buildCSS = (scssString, ...currentPaths) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
22
|
+
if (scssString.trim()) {
|
|
23
|
+
const loadPaths = [...currentPaths, path.resolve(process.cwd(), dirs.build)];
|
|
24
|
+
const cssResult = sass.compileString(scssString, { loadPaths });
|
|
25
|
+
return cssResult.css.toString().trim();
|
|
26
|
+
}
|
|
27
|
+
return '';
|
|
38
28
|
};
|
|
39
29
|
|
|
40
30
|
export const getComponentName = cmp => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
31
|
+
const indexOfLastSlash = cmp.lastIndexOf('/');
|
|
32
|
+
if (indexOfLastSlash > -1) {
|
|
33
|
+
return cmp.substring(indexOfLastSlash + 1);
|
|
34
|
+
}
|
|
35
|
+
return cmp;
|
|
46
36
|
};
|
|
47
37
|
|
|
48
38
|
export const getPathLevels = filePath => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
39
|
+
filePath = path.normalize(filePath);
|
|
40
|
+
const numSlashes = filePath.replace(/[^\/]/g, '').length;
|
|
41
|
+
let ret = '';
|
|
42
|
+
for (let i = 0; i < numSlashes; ++i) {
|
|
43
|
+
ret += '../';
|
|
44
|
+
}
|
|
45
|
+
return ret;
|
|
56
46
|
};
|
|
57
47
|
|
|
58
48
|
export const throttle = (callback, limit = 100) => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
export const getWebPackConfig = (outputDir, project) => {
|
|
72
|
-
return {
|
|
73
|
-
entry: process.cwd() + `/${dirs.build}/${project.name}.js`,
|
|
74
|
-
output: {
|
|
75
|
-
path: process.cwd() + `/${outputDir}/`,
|
|
76
|
-
filename: `${project.name}.js`,
|
|
77
|
-
},
|
|
78
|
-
module: {
|
|
79
|
-
rules: [{
|
|
80
|
-
test: path.resolve(process.cwd()),
|
|
81
|
-
exclude: /node_modules/,
|
|
82
|
-
loader: require.resolve('babel-loader'),
|
|
83
|
-
options: {
|
|
84
|
-
presets: [require.resolve('@babel/preset-env'), {
|
|
85
|
-
plugins: [
|
|
86
|
-
'@babel/plugin-transform-runtime'
|
|
87
|
-
].map(require.resolve)
|
|
88
|
-
}]
|
|
89
|
-
},
|
|
90
|
-
}, {
|
|
91
|
-
test: /\.(scss|sass|css)$/i,
|
|
92
|
-
use: [
|
|
93
|
-
{
|
|
94
|
-
loader: require.resolve('css-loader'),
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
loader: require.resolve('sass-loader'),
|
|
98
|
-
options: {
|
|
99
|
-
sassOptions: {
|
|
100
|
-
includePaths: [path.resolve(process.cwd(), 'node_modules')],
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
},
|
|
104
|
-
],
|
|
105
|
-
}, {
|
|
106
|
-
test: /\.json$/i,
|
|
107
|
-
loader: require.resolve('json5-loader'),
|
|
108
|
-
options: {
|
|
109
|
-
esModule: true,
|
|
110
|
-
},
|
|
111
|
-
type: 'javascript/auto',
|
|
112
|
-
}, {
|
|
113
|
-
loader: require.resolve('raw-loader'),
|
|
114
|
-
exclude: [
|
|
115
|
-
/\.(js|mjs|jsx|ts|tsx)$/i,
|
|
116
|
-
/\.(json|json5)$/i,
|
|
117
|
-
/\.(css|scss|sass)$/i
|
|
118
|
-
],
|
|
119
|
-
}]
|
|
120
|
-
},
|
|
121
|
-
}
|
|
49
|
+
let wait = false;
|
|
50
|
+
return function () {
|
|
51
|
+
if (!wait) {
|
|
52
|
+
wait = true;
|
|
53
|
+
setTimeout(() => {
|
|
54
|
+
wait = false;
|
|
55
|
+
callback.apply(null, arguments);
|
|
56
|
+
}, limit);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
122
59
|
};
|
|
123
60
|
|
|
124
61
|
export const portInUse = (port, address = '127.0.0.1') => {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
62
|
+
return new Promise((resolve, reject) => {
|
|
63
|
+
const server = net.createServer(socket => socket.pipe(socket));
|
|
64
|
+
|
|
65
|
+
server.listen(port, address);
|
|
66
|
+
server.on('error', e => {
|
|
67
|
+
resolve(true);
|
|
68
|
+
});
|
|
69
|
+
server.on('listening', e => {
|
|
70
|
+
server.close();
|
|
71
|
+
resolve(false);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
137
74
|
};
|
|
138
75
|
|
|
139
76
|
const initNote = `Usage: leanweb init or leanweb init project-name
|
|
@@ -216,10 +153,6 @@ const upgradeNote = `Usage: leanweb upgrade
|
|
|
216
153
|
This will upgrade leanweb runtime in the src/lib directory.
|
|
217
154
|
`;
|
|
218
155
|
|
|
219
|
-
const electronNote = `Usage: leanweb electron [env]
|
|
220
|
-
This will run the app as native desktop app using Electron.
|
|
221
|
-
`;
|
|
222
|
-
|
|
223
156
|
const destroyNote = `Usage leanweb destroy project-name
|
|
224
157
|
This will remove the src/, build/ and dist/ directory. Please
|
|
225
158
|
note the src directory will be deleted by this command.
|
|
@@ -236,15 +169,14 @@ const versionNote = `Usage: leanweb version
|
|
|
236
169
|
Print version information for leanweb.`;
|
|
237
170
|
|
|
238
171
|
export const targets = {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
'version': { file: 'version.js', note: versionNote },
|
|
172
|
+
'init': { file: 'init.js', note: initNote },
|
|
173
|
+
'generate': { file: 'generate.js', note: generateNote },
|
|
174
|
+
'serve': { file: 'serve.js', note: serveNote },
|
|
175
|
+
'build': { file: 'build.js', note: buildNote },
|
|
176
|
+
'dist': { file: 'dist.js', note: distNote },
|
|
177
|
+
'upgrade': { file: 'upgrade.js', note: upgradeNote },
|
|
178
|
+
'clean': { file: 'clean.js', note: cleanNote },
|
|
179
|
+
'destroy': { file: 'destroy.js', note: destroyNote },
|
|
180
|
+
'help': { file: 'help.js', note: helpNote },
|
|
181
|
+
'version': { file: 'version.js', note: versionNote },
|
|
250
182
|
};
|