leanweb 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/commands/build.js +5 -5
- package/commands/clean.js +0 -1
- package/commands/destroy.js +1 -2
- package/commands/init.js +2 -2
- package/commands/serve.js +2 -22
- package/commands/utils.js +21 -2
- package/package.json +6 -6
- package/templates/lib/lw-element.js +1 -1
package/commands/build.js
CHANGED
|
@@ -28,12 +28,12 @@ import CleanCSS from 'clean-css';
|
|
|
28
28
|
fs.mkdirSync(utils.dirs.build, { recursive: true });
|
|
29
29
|
|
|
30
30
|
const copySrc = () => {
|
|
31
|
-
fse.copySync(`${projectPath}/${utils.dirs.src}/`, utils.dirs.build, { filter: utils.
|
|
31
|
+
fse.copySync(`${projectPath}/${utils.dirs.src}/`, utils.dirs.build, { filter: utils.copyFilter });
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
const copyEnv = () => {
|
|
35
35
|
if (env) {
|
|
36
|
-
fse.copySync(`${utils.dirs.build}/env/${env}.js`, `${utils.dirs.build}/env.js
|
|
36
|
+
fse.copySync(`${utils.dirs.build}/env/${env}.js`, `${utils.dirs.build}/env.js`, { filter: utils.copyFilter });
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
39
|
|
|
@@ -43,7 +43,7 @@ import CleanCSS from 'clean-css';
|
|
|
43
43
|
let importString = `import './components/${cur}/${cmpName}.js';`;
|
|
44
44
|
return acc + importString + '\n';
|
|
45
45
|
}, '');
|
|
46
|
-
|
|
46
|
+
utils.writeIfChanged(`${utils.dirs.build}/${project.name}.js`, jsString);
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
const buildHTML = () => {
|
|
@@ -75,7 +75,7 @@ import CleanCSS from 'clean-css';
|
|
|
75
75
|
ast.componentFullName = project.name + '-' + cmp.replace(/\//g, '-');
|
|
76
76
|
ast.runtimeVersion = project.version;
|
|
77
77
|
ast.builderVersion = leanwebPackageJSON.version;
|
|
78
|
-
|
|
78
|
+
utils.writeIfChanged(`${utils.dirs.build}/components/${cmp}/ast.js`, `export default ${JSON.stringify(ast, null, 0)};`);
|
|
79
79
|
}
|
|
80
80
|
});
|
|
81
81
|
};
|
|
@@ -87,7 +87,7 @@ import CleanCSS from 'clean-css';
|
|
|
87
87
|
const projectScssString = fs.readFileSync(projectScssFilename, 'utf8');
|
|
88
88
|
projectCssString += utils.buildCSS(projectScssString, utils.dirs.build);
|
|
89
89
|
}
|
|
90
|
-
|
|
90
|
+
utils.writeIfChanged(`${utils.dirs.build}/${project.name}.css`, projectCssString);
|
|
91
91
|
};
|
|
92
92
|
|
|
93
93
|
copySrc();
|
package/commands/clean.js
CHANGED
package/commands/destroy.js
CHANGED
|
@@ -8,7 +8,7 @@ import * as utils from './utils.js';
|
|
|
8
8
|
const args = process.argv;
|
|
9
9
|
if (args.length < 3) {
|
|
10
10
|
console.log('Usage: lw destroy project-name');
|
|
11
|
-
console.log(`This will delete ${utils.dirs.src}/ ${utils.dirs.build}/
|
|
11
|
+
console.log(`This will delete ${utils.dirs.src}/ ${utils.dirs.build}/ and ${utils.dirs.dist}/.`);
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
14
14
|
|
|
@@ -24,5 +24,4 @@ import * as utils from './utils.js';
|
|
|
24
24
|
fs.rmSync(utils.dirs.build + '/', { recursive: true, force: true });
|
|
25
25
|
fs.rmSync(utils.dirs.dist + '/', { recursive: true, force: true });
|
|
26
26
|
fs.rmSync(utils.dirs.src + '/', { recursive: true, force: true });
|
|
27
|
-
fs.rmSync(utils.dirs.serve + '/', { recursive: true, force: true });
|
|
28
27
|
})();
|
package/commands/init.js
CHANGED
|
@@ -74,9 +74,9 @@ import * as utils from './utils.js';
|
|
|
74
74
|
await git.init({ fs, dir: process.cwd() });
|
|
75
75
|
|
|
76
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
|
|
77
|
+
fs.appendFileSync(`${process.cwd()}/.gitignore`, `\n${utils.dirs.build}/\n${utils.dirs.dist}/\n`, 'utf8');
|
|
78
78
|
} else {
|
|
79
|
-
fs.writeFileSync(`${process.cwd()}/.gitignore`, `${utils.dirs.build}/\n${utils.dirs.dist}/\n
|
|
79
|
+
fs.writeFileSync(`${process.cwd()}/.gitignore`, `${utils.dirs.build}/\n${utils.dirs.dist}/\n`, 'utf8');
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
const paths = await globby(['./**', './**/.*'], { gitignore: true });
|
package/commands/serve.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import { createRequire } from "module";
|
|
2
|
-
const require = createRequire(import.meta.url);
|
|
3
|
-
|
|
4
|
-
import fs from 'fs';
|
|
5
|
-
import fse from 'fs-extra';
|
|
6
1
|
import * as utils from './utils.js';
|
|
7
2
|
import watch from 'node-watch';
|
|
8
3
|
import liveServer from 'live-server';
|
|
@@ -20,24 +15,9 @@ const noopen = process.env.noopen || false;
|
|
|
20
15
|
|
|
21
16
|
(async () => {
|
|
22
17
|
|
|
23
|
-
const project = require(`${process.cwd()}/${utils.dirs.src}/leanweb.json`);
|
|
24
|
-
|
|
25
18
|
const build = async (eventType, filename) => {
|
|
26
19
|
// console.log(eventType + ': ', filename);
|
|
27
|
-
|
|
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
|
-
}
|
|
20
|
+
await utils.exec(`npx leanweb build ${env}`);
|
|
41
21
|
};
|
|
42
22
|
|
|
43
23
|
const throttledBuild = utils.throttle(build);
|
|
@@ -54,7 +34,7 @@ const noopen = process.env.noopen || false;
|
|
|
54
34
|
open: !noopen,
|
|
55
35
|
file: 'index.html',
|
|
56
36
|
wait: 1000,
|
|
57
|
-
logLevel:
|
|
37
|
+
logLevel: 1,
|
|
58
38
|
};
|
|
59
39
|
liveServer.start(params);
|
|
60
40
|
})();
|
package/commands/utils.js
CHANGED
|
@@ -2,20 +2,39 @@ import { execSync } from 'child_process';
|
|
|
2
2
|
import sass from 'sass';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import net from 'net';
|
|
5
|
+
import fs from 'fs';
|
|
5
6
|
import fse from 'fs-extra';
|
|
6
7
|
|
|
7
8
|
export const dirs = {
|
|
8
9
|
src: 'src',
|
|
9
10
|
build: 'build',
|
|
10
|
-
serve: 'serve',
|
|
11
11
|
dist: 'dist',
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
export const
|
|
14
|
+
export const copyFilter = (src, dest) => {
|
|
15
|
+
const srcStats = fse.existsSync(src) && fse.lstatSync(src);
|
|
15
16
|
const destStats = fse.existsSync(dest) && fse.lstatSync(dest);
|
|
17
|
+
if (srcStats?.isFile?.() && destStats?.isFile?.()) {
|
|
18
|
+
const srcBuf = fs.readFileSync(src);
|
|
19
|
+
const destBuf = fs.readFileSync(dest);
|
|
20
|
+
if (srcBuf.equals(destBuf)) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
16
24
|
return !destStats?.isSymbolicLink?.();
|
|
17
25
|
};
|
|
18
26
|
|
|
27
|
+
export const writeIfChanged = (file, string) => {
|
|
28
|
+
const stats = fse.existsSync(file) && fse.lstatSync(file);
|
|
29
|
+
if (stats?.isFile?.()) {
|
|
30
|
+
const data = fs.readFileSync(file, 'utf8');
|
|
31
|
+
if (data === string) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
fs.writeFileSync(file, string);
|
|
36
|
+
};
|
|
37
|
+
|
|
19
38
|
export const exec = command => execSync(command, { encoding: 'utf8', stdio: 'inherit' });
|
|
20
39
|
|
|
21
40
|
export const buildCSS = (scssString, ...currentPaths) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "leanweb",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
4
4
|
"description": "Builds framework agnostic web components.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"leanweb": "leanweb.js",
|
|
@@ -20,17 +20,17 @@
|
|
|
20
20
|
"author": "Qian Chen",
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@babel/parser": "^7.20.
|
|
23
|
+
"@babel/parser": "^7.20.7",
|
|
24
24
|
"clean-css": "^5.3.1",
|
|
25
|
-
"esbuild": "^0.
|
|
25
|
+
"esbuild": "^0.16.12",
|
|
26
26
|
"fs-extra": "^11.1.0",
|
|
27
|
-
"globby": "^13.1.
|
|
27
|
+
"globby": "^13.1.3",
|
|
28
28
|
"html-minifier": "^4.0.0",
|
|
29
29
|
"isomorphic-git": "^1.21.0",
|
|
30
30
|
"live-server": "^1.2.2",
|
|
31
31
|
"node-watch": "^0.7.3",
|
|
32
32
|
"parse5": "^7.1.2",
|
|
33
|
-
"sass": "^1.
|
|
33
|
+
"sass": "^1.57.1",
|
|
34
34
|
"semver": "^7.3.8"
|
|
35
35
|
}
|
|
36
|
-
}
|
|
36
|
+
}
|
|
@@ -282,7 +282,7 @@ export default class LWElement extends HTMLElement {
|
|
|
282
282
|
propertyExpr = astModel.name;
|
|
283
283
|
}
|
|
284
284
|
|
|
285
|
-
if (modelNode.type === 'number') {
|
|
285
|
+
if (modelNode.type === 'number' || modelNode.type === 'range') {
|
|
286
286
|
// set do_not_update mark for cases when user inputs 0.01, 0.0 will not be evaluated prematurely
|
|
287
287
|
modelNode.do_not_update = true;
|
|
288
288
|
object[propertyExpr] = modelNode.value * 1;
|