leanweb 2.0.4 → 3.0.0
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/addpage.js +49 -0
- package/commands/build.js +60 -78
- package/commands/clean.js +2 -4
- package/commands/dist.js +42 -36
- package/commands/generate.js +2 -2
- package/commands/init.js +14 -14
- package/commands/serve.js +22 -25
- package/commands/utils.js +15 -14
- package/package.json +9 -11
- package/templates/lib/api-client.js +1 -1
- package/templates/lib/lw-element.js +2 -5
- package/templates/page.html +13 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { fileURLToPath } from 'url';
|
|
3
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
4
|
+
const __dirname = path.dirname(__filename);
|
|
5
|
+
import { createRequire } from "module";
|
|
6
|
+
const require = createRequire(import.meta.url);
|
|
7
|
+
|
|
8
|
+
import fs from 'fs';
|
|
9
|
+
import * as utils from './utils.js';
|
|
10
|
+
|
|
11
|
+
(async () => {
|
|
12
|
+
const args = process.argv;
|
|
13
|
+
if (args.length < 3) {
|
|
14
|
+
console.error('Usage: lw addpage page names');
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const leanwebJSONPath = `${process.cwd()}/${utils.dirs.src}/leanweb.json`;
|
|
19
|
+
const leanwebJSON = require(leanwebJSONPath);
|
|
20
|
+
const pages = args.slice(2);
|
|
21
|
+
|
|
22
|
+
const projectName = path.basename(path.resolve());
|
|
23
|
+
|
|
24
|
+
leanwebJSON.pages = leanwebJSON.pages ?? [];
|
|
25
|
+
for (const pageJSON of leanwebJSON.pages) {
|
|
26
|
+
for (const page of pages) {
|
|
27
|
+
if (pageJSON === page) {
|
|
28
|
+
console.error(`Error: page ${pageJSON} existed.`);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
leanwebJSON.pages.push(...pages);
|
|
35
|
+
fs.writeFileSync(leanwebJSONPath, JSON.stringify(leanwebJSON, null, 2));
|
|
36
|
+
|
|
37
|
+
for (const page of pages) {
|
|
38
|
+
const pageName = utils.getComponentName(page);
|
|
39
|
+
const pagePath = `${utils.dirs.src}/${utils.getComponentPath(page)}`;
|
|
40
|
+
fs.mkdirSync(pagePath, { recursive: true });
|
|
41
|
+
if (!fs.existsSync(`${pagePath}/${pageName}.html`)) {
|
|
42
|
+
let htmlString = fs.readFileSync(`${__dirname}/../templates/page.html`, 'utf8');
|
|
43
|
+
htmlString = htmlString.replace(/\$\{project\.name\}/g, projectName);
|
|
44
|
+
htmlString = htmlString.replace(/\$\{page\.name\}/g, pageName);
|
|
45
|
+
htmlString = htmlString.replace(/\$\{pathLevels\}/g, utils.getPathLevels(page));
|
|
46
|
+
fs.writeFileSync(`${pagePath}/${pageName}.html`, htmlString);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
})();
|
package/commands/build.js
CHANGED
|
@@ -10,95 +10,77 @@ import fse from 'fs-extra';
|
|
|
10
10
|
import { minify } from 'html-minifier';
|
|
11
11
|
import * as utils from './utils.js';
|
|
12
12
|
import * as parser from '../lib/lw-html-parser.js';
|
|
13
|
-
import CleanCSS from 'clean-css';
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
14
|
+
let env;
|
|
15
|
+
const args = process.argv;
|
|
16
|
+
if (args.length >= 3) {
|
|
17
|
+
env = args[2];
|
|
18
|
+
}
|
|
21
19
|
|
|
22
|
-
|
|
20
|
+
const leanwebPackageJSON = require(`${__dirname}/../package.json`);
|
|
23
21
|
|
|
24
|
-
|
|
22
|
+
const buildModule = (projectPath) => {
|
|
25
23
|
|
|
26
|
-
|
|
24
|
+
const project = require(`${projectPath}/${utils.dirs.src}/leanweb.json`);
|
|
27
25
|
|
|
28
|
-
|
|
26
|
+
fs.mkdirSync(utils.dirs.build, { recursive: true });
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
const copySrc = () => {
|
|
29
|
+
fse.copySync(`${projectPath}/${utils.dirs.src}/`, utils.dirs.build, { filter: utils.copyFilter });
|
|
30
|
+
};
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
const copyEnv = () => {
|
|
33
|
+
if (env) {
|
|
34
|
+
fse.copySync(`${utils.dirs.build}/env/${env}.js`, `${utils.dirs.build}/env.js`, { filter: utils.copyFilter });
|
|
35
|
+
}
|
|
36
|
+
};
|
|
39
37
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
38
|
+
const buildJS = () => {
|
|
39
|
+
const jsString = project.components.reduce((acc, cur) => {
|
|
40
|
+
const cmpName = utils.getComponentName(cur);
|
|
41
|
+
let importString = `import './components/${cur}/${cmpName}.js';`;
|
|
42
|
+
return acc + importString + '\n';
|
|
43
|
+
}, '');
|
|
44
|
+
utils.writeIfChanged(`${utils.dirs.build}/${project.name}.js`, jsString);
|
|
45
|
+
};
|
|
48
46
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
scssString += fs.readFileSync(scssFilename, 'utf8');
|
|
61
|
-
scssString += '\n[lw-false],[lw-for]{display:none !important;}\n';
|
|
62
|
-
cssString = utils.buildCSS(scssString, utils.dirs.build, `${utils.dirs.build}/components/${cmp}`);
|
|
63
|
-
}
|
|
64
|
-
const htmlString = fs.readFileSync(htmlFilename, 'utf8');
|
|
65
|
-
const minifiedHtml = minify(htmlString, {
|
|
66
|
-
caseSensitive: true,
|
|
67
|
-
collapseWhitespace: true,
|
|
68
|
-
minifyCSS: true,
|
|
69
|
-
minifyJS: true,
|
|
70
|
-
removeComments: true,
|
|
71
|
-
});
|
|
72
|
-
const ast = parser.parse(minifiedHtml);
|
|
73
|
-
const minifiedCss = new CleanCSS({}).minify(cssString ?? '');
|
|
74
|
-
ast.css = minifiedCss.styles ?? '';
|
|
75
|
-
ast.componentFullName = project.name + '-' + cmp.replace(/\//g, '-');
|
|
76
|
-
ast.runtimeVersion = project.version;
|
|
77
|
-
ast.builderVersion = leanwebPackageJSON.version;
|
|
78
|
-
utils.writeIfChanged(`${utils.dirs.build}/components/${cmp}/ast.js`, `export default ${JSON.stringify(ast, null, 0)};`);
|
|
47
|
+
const buildHTML = () => {
|
|
48
|
+
project.components.forEach(cmp => {
|
|
49
|
+
const cmpName = utils.getComponentName(cmp);
|
|
50
|
+
const htmlFilename = `${utils.dirs.build}/components/${cmp}/${cmpName}.html`;
|
|
51
|
+
const htmlFileExists = fs.existsSync(htmlFilename);
|
|
52
|
+
if (htmlFileExists) {
|
|
53
|
+
const cssFilename = `${utils.dirs.build}/components/${cmp}/${cmpName}.css`;
|
|
54
|
+
const cssFileExists = fs.existsSync(cssFilename);
|
|
55
|
+
let cssString = `@import "global-styles.css";\n`;
|
|
56
|
+
if (cssFileExists) {
|
|
57
|
+
cssString += fs.readFileSync(cssFilename, 'utf8');
|
|
79
58
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
59
|
+
cssString += '\n[lw-false],[lw-for]{display:none !important;}\n';
|
|
60
|
+
const htmlString = fs.readFileSync(htmlFilename, 'utf8');
|
|
61
|
+
const minifiedHtml = minify(htmlString, {
|
|
62
|
+
caseSensitive: true,
|
|
63
|
+
collapseWhitespace: true,
|
|
64
|
+
minifyCSS: true,
|
|
65
|
+
minifyJS: true,
|
|
66
|
+
removeComments: true,
|
|
67
|
+
});
|
|
68
|
+
const ast = parser.parse(minifiedHtml);
|
|
69
|
+
ast.css = cssString;
|
|
70
|
+
ast.componentFullName = project.name + '-' + cmp.replace(/\//g, '-');
|
|
71
|
+
ast.runtimeVersion = project.version;
|
|
72
|
+
ast.builderVersion = leanwebPackageJSON.version;
|
|
73
|
+
utils.writeIfChanged(`${utils.dirs.build}/components/${cmp}/ast.js`, `export default ${JSON.stringify(ast, null, 0)};`);
|
|
89
74
|
}
|
|
90
|
-
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
copySrc();
|
|
94
|
-
copyEnv();
|
|
95
|
-
buildJS();
|
|
96
|
-
buildSCSS();
|
|
97
|
-
buildHTML();
|
|
98
|
-
|
|
99
|
-
return project.name;
|
|
75
|
+
});
|
|
100
76
|
};
|
|
101
77
|
|
|
102
|
-
|
|
78
|
+
copySrc();
|
|
79
|
+
copyEnv();
|
|
80
|
+
buildJS();
|
|
81
|
+
buildHTML();
|
|
82
|
+
|
|
83
|
+
return project.name;
|
|
84
|
+
};
|
|
103
85
|
|
|
104
|
-
|
|
86
|
+
buildModule(process.cwd());
|
package/commands/clean.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import * as utils from './utils.js';
|
|
3
3
|
|
|
4
|
-
(
|
|
5
|
-
|
|
6
|
-
fs.rmSync(utils.dirs.dist + '/', { recursive: true, force: true });
|
|
7
|
-
})();
|
|
4
|
+
fs.rmSync(utils.dirs.build + '/', { recursive: true, force: true });
|
|
5
|
+
fs.rmSync(utils.dirs.dist + '/', { recursive: true, force: true });
|
package/commands/dist.js
CHANGED
|
@@ -5,7 +5,6 @@ import * as utils from './utils.js';
|
|
|
5
5
|
import fs from 'fs';
|
|
6
6
|
import fse from 'fs-extra';
|
|
7
7
|
import { minify } from 'html-minifier';
|
|
8
|
-
import CleanCSS from 'clean-css';
|
|
9
8
|
|
|
10
9
|
import esbuild from 'esbuild';
|
|
11
10
|
|
|
@@ -17,51 +16,58 @@ if (args.length >= 3) {
|
|
|
17
16
|
|
|
18
17
|
const verbose = process.env.verbose || false;
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
const project = require(`${process.cwd()}/${utils.dirs.src}/leanweb.json`);
|
|
19
|
+
const project = require(`${process.cwd()}/${utils.dirs.src}/leanweb.json`);
|
|
22
20
|
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
utils.exec(`npx leanweb clean`);
|
|
22
|
+
utils.exec(`npx leanweb build ${env}`);
|
|
25
23
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
24
|
+
fs.mkdirSync(utils.dirs.dist, { recursive: true });
|
|
25
|
+
const result = await esbuild.build({
|
|
26
|
+
entryPoints: [`./${utils.dirs.build}/${project.name}.js`],
|
|
27
|
+
bundle: true,
|
|
28
|
+
minify: true,
|
|
29
|
+
sourcemap: true,
|
|
30
|
+
format: 'esm',
|
|
31
|
+
outfile: `./${utils.dirs.dist}/${project.name}.js`,
|
|
32
|
+
metafile: !!verbose,
|
|
33
|
+
});
|
|
34
|
+
if (verbose) {
|
|
35
|
+
const text = await esbuild.analyzeMetafile(result.metafile);
|
|
36
|
+
console.log(text);
|
|
37
|
+
}
|
|
40
38
|
|
|
41
|
-
|
|
42
|
-
const
|
|
39
|
+
const minimizePage = page => {
|
|
40
|
+
const html = fs.readFileSync(`./${utils.dirs.build}/${page}.html`, 'utf8');
|
|
41
|
+
const minifiedIndexHtml = minify(html, {
|
|
43
42
|
caseSensitive: true,
|
|
44
43
|
collapseWhitespace: true,
|
|
45
44
|
minifyCSS: true,
|
|
46
45
|
minifyJS: true,
|
|
47
46
|
removeComments: true,
|
|
48
47
|
});
|
|
49
|
-
fs.writeFileSync(`./${utils.dirs.dist}/index.html`, minifiedIndexHtml);
|
|
50
48
|
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
fs.
|
|
49
|
+
const pageName = utils.getComponentName(page);
|
|
50
|
+
const pagePath = `${utils.dirs.dist}/${utils.getComponentPath(page)}`;
|
|
51
|
+
fs.mkdirSync(pagePath, { recursive: true });
|
|
52
|
+
fs.writeFileSync(`${pagePath}/${pageName}.html`, minifiedIndexHtml);
|
|
53
|
+
};
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
});
|
|
55
|
+
project.pages.push('index');
|
|
56
|
+
project.pages.forEach(minimizePage);
|
|
57
|
+
|
|
58
|
+
const appCSS = fs.readFileSync(`./${utils.dirs.build}/${project.name}.css`, 'utf8');
|
|
59
|
+
fs.writeFileSync(`./${utils.dirs.dist}/${project.name}.css`, appCSS);
|
|
62
60
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
fse.copySync(`./${utils.dirs.build}/favicon.svg`, `./${utils.dirs.dist}/favicon.svg`);
|
|
62
|
+
fse.copySync(`./${utils.dirs.build}/global-styles.css`, `./${utils.dirs.dist}/global-styles.css`);
|
|
63
|
+
project.resources?.forEach(resource => {
|
|
64
|
+
const source = `./${utils.dirs.build}/${resource}`;
|
|
65
|
+
if (fs.existsSync(source)) {
|
|
66
|
+
fse.copySync(source, `./${utils.dirs.dist}/${resource}`, { dereference: true });
|
|
66
67
|
}
|
|
67
|
-
})
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const postDistFile = './post-dist';
|
|
71
|
+
if (fs.existsSync(postDistFile) && fs.statSync(postDistFile).isFile()) {
|
|
72
|
+
utils.exec(postDistFile);
|
|
73
|
+
}
|
package/commands/generate.js
CHANGED
|
@@ -50,8 +50,8 @@ import * as utils from './utils.js';
|
|
|
50
50
|
fs.writeFileSync(`${cmpPath}/${cmpName}.html`, `<div>${leanwebJSON.name}-${cmpName} works!</div>`);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
if (!fs.existsSync(`${cmpPath}/${cmpName}.
|
|
54
|
-
fs.writeFileSync(`${cmpPath}/${cmpName}.
|
|
53
|
+
if (!fs.existsSync(`${cmpPath}/${cmpName}.css`)) {
|
|
54
|
+
fs.writeFileSync(`${cmpPath}/${cmpName}.css`, '');
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
})();
|
package/commands/init.js
CHANGED
|
@@ -23,7 +23,7 @@ import * as utils from './utils.js';
|
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
const projectName = path.basename(path.resolve());
|
|
27
27
|
|
|
28
28
|
if (args.length >= 3) {
|
|
29
29
|
projectName = args[2];
|
|
@@ -38,20 +38,20 @@ import * as utils from './utils.js';
|
|
|
38
38
|
],
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
const projectCss = `/* html,
|
|
42
|
+
body {
|
|
43
|
+
height: 100%;
|
|
44
|
+
width: 100%;
|
|
45
|
+
margin: 0 auto;
|
|
46
|
+
padding: 0;
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
font-family: "Roboto", "Helvetica", "Arial", sans-serif;
|
|
49
|
+
} */
|
|
50
50
|
`
|
|
51
51
|
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
const globalCss = `/* div {
|
|
53
|
+
color: tomato;
|
|
54
|
+
} */
|
|
55
55
|
`;
|
|
56
56
|
|
|
57
57
|
fs.mkdirSync(`${utils.dirs.src}/resources/`, { recursive: true });
|
|
@@ -64,8 +64,8 @@ import * as utils from './utils.js';
|
|
|
64
64
|
let htmlString = fs.readFileSync(`${__dirname}/../templates/index.html`, 'utf8');
|
|
65
65
|
htmlString = htmlString.replace(/\$\{project\.name\}/g, projectName);
|
|
66
66
|
fs.writeFileSync(`./${utils.dirs.src}/index.html`, htmlString);
|
|
67
|
-
fs.writeFileSync(`./src/${projectName}.
|
|
68
|
-
fs.writeFileSync(`./${utils.dirs.src}/global-styles.
|
|
67
|
+
fs.writeFileSync(`./src/${projectName}.css`, projectCss);
|
|
68
|
+
fs.writeFileSync(`./${utils.dirs.src}/global-styles.css`, globalCss);
|
|
69
69
|
fse.copySync(`${__dirname}/../templates/favicon.svg`, `./${utils.dirs.src}/favicon.svg`);
|
|
70
70
|
fse.copySync(`${__dirname}/../templates/env.js`, `./${utils.dirs.src}/env.js`);
|
|
71
71
|
fse.copySync(`${__dirname}/../templates/env/`, `./${utils.dirs.src}/env/`);
|
package/commands/serve.js
CHANGED
|
@@ -13,28 +13,25 @@ const host = process.env.host || '127.0.0.1';
|
|
|
13
13
|
let port = process.env.port || 2020;
|
|
14
14
|
const noopen = process.env.noopen || false;
|
|
15
15
|
|
|
16
|
-
(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
};
|
|
39
|
-
liveServer.start(params);
|
|
40
|
-
})();
|
|
16
|
+
const build = (eventType, filename) => {
|
|
17
|
+
// console.log(eventType + ': ', filename);
|
|
18
|
+
utils.exec(`npx leanweb build ${env}`);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const throttledBuild = utils.throttle(build);
|
|
22
|
+
watch(process.cwd() + `/${utils.dirs.src}/`, { recursive: true }, (eventType, filename) => {
|
|
23
|
+
throttledBuild(eventType, filename);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
build();
|
|
27
|
+
|
|
28
|
+
const params = {
|
|
29
|
+
port,
|
|
30
|
+
host,
|
|
31
|
+
root: utils.dirs.build,
|
|
32
|
+
open: !noopen,
|
|
33
|
+
file: 'index.html',
|
|
34
|
+
wait: 1000,
|
|
35
|
+
logLevel: 1,
|
|
36
|
+
};
|
|
37
|
+
liveServer.start(params);
|
package/commands/utils.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { execSync } from 'child_process';
|
|
2
|
-
import sass from 'sass';
|
|
3
2
|
import path from 'path';
|
|
4
3
|
import net from 'net';
|
|
5
4
|
import fs from 'fs';
|
|
@@ -37,15 +36,6 @@ export const writeIfChanged = (file, string) => {
|
|
|
37
36
|
|
|
38
37
|
export const exec = command => execSync(command, { encoding: 'utf8', stdio: 'inherit' });
|
|
39
38
|
|
|
40
|
-
export const buildCSS = (scssString, ...currentPaths) => {
|
|
41
|
-
if (scssString.trim()) {
|
|
42
|
-
const loadPaths = [...currentPaths, path.resolve(process.cwd(), dirs.build)];
|
|
43
|
-
const cssResult = sass.compileString(scssString, { loadPaths });
|
|
44
|
-
return cssResult.css.toString().trim();
|
|
45
|
-
}
|
|
46
|
-
return '';
|
|
47
|
-
};
|
|
48
|
-
|
|
49
39
|
export const getComponentName = cmp => {
|
|
50
40
|
const indexOfLastSlash = cmp.lastIndexOf('/');
|
|
51
41
|
if (indexOfLastSlash > -1) {
|
|
@@ -54,6 +44,14 @@ export const getComponentName = cmp => {
|
|
|
54
44
|
return cmp;
|
|
55
45
|
};
|
|
56
46
|
|
|
47
|
+
export const getComponentPath = cmp => {
|
|
48
|
+
const indexOfLastSlash = cmp.lastIndexOf('/');
|
|
49
|
+
if (indexOfLastSlash > -1) {
|
|
50
|
+
return cmp.substring(0, indexOfLastSlash);
|
|
51
|
+
}
|
|
52
|
+
return '';
|
|
53
|
+
};
|
|
54
|
+
|
|
57
55
|
export const getPathLevels = filePath => {
|
|
58
56
|
filePath = path.normalize(filePath);
|
|
59
57
|
const numSlashes = filePath.replace(/[^\/]/g, '').length;
|
|
@@ -115,12 +113,12 @@ will be created. demo-root web component contains 3 files:
|
|
|
115
113
|
|
|
116
114
|
root.html
|
|
117
115
|
root.js
|
|
118
|
-
root.
|
|
116
|
+
root.css
|
|
119
117
|
|
|
120
|
-
Under src/ directory, global-styles.
|
|
118
|
+
Under src/ directory, global-styles.css is created for global styling.
|
|
121
119
|
`;
|
|
122
120
|
|
|
123
|
-
const generateNote = `Usage: leanweb generate component-
|
|
121
|
+
const generateNote = `Usage: leanweb generate component-names
|
|
124
122
|
For example leanweb g login will create demo-login web component in
|
|
125
123
|
src/components directory. The leanweb.json will be updated to look like:
|
|
126
124
|
|
|
@@ -140,12 +138,14 @@ demo-login web component will contain 3 files:
|
|
|
140
138
|
|
|
141
139
|
login.html
|
|
142
140
|
login.js
|
|
143
|
-
login.
|
|
141
|
+
login.css
|
|
144
142
|
|
|
145
143
|
Now, the demo-login component can be added in root.html as follows:
|
|
146
144
|
<demo-login></demo-login>
|
|
147
145
|
`;
|
|
148
146
|
|
|
147
|
+
const addpageNote = `Usage: leanweb addpage page-names`;
|
|
148
|
+
|
|
149
149
|
const serveNote = `Usage: leabweb [env] serve or lw s [env]
|
|
150
150
|
Running this command will start the dev server and open the app in a new
|
|
151
151
|
browser window. Any chances to the source code will cause the dev server to
|
|
@@ -189,6 +189,7 @@ Print version information for leanweb.`;
|
|
|
189
189
|
|
|
190
190
|
export const targets = {
|
|
191
191
|
'init': { file: 'init.js', note: initNote },
|
|
192
|
+
'addpage': { file: 'addpage.js', note: addpageNote },
|
|
192
193
|
'generate': { file: 'generate.js', note: generateNote },
|
|
193
194
|
'serve': { file: 'serve.js', note: serveNote },
|
|
194
195
|
'build': { file: 'build.js', note: buildNote },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "leanweb",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Builds framework agnostic web components.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"leanweb": "leanweb.js",
|
|
@@ -20,17 +20,15 @@
|
|
|
20
20
|
"author": "Qian Chen",
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@babel/parser": "^7.
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"globby": "^13.1.3",
|
|
23
|
+
"@babel/parser": "^7.24.1",
|
|
24
|
+
"esbuild": "^0.20.2",
|
|
25
|
+
"fs-extra": "^11.2.0",
|
|
26
|
+
"globby": "^14.0.1",
|
|
28
27
|
"html-minifier": "^4.0.0",
|
|
29
|
-
"isomorphic-git": "^1.
|
|
28
|
+
"isomorphic-git": "^1.25.6",
|
|
30
29
|
"live-server": "^1.2.2",
|
|
31
|
-
"node-watch": "^0.7.
|
|
30
|
+
"node-watch": "^0.7.4",
|
|
32
31
|
"parse5": "^7.1.2",
|
|
33
|
-
"
|
|
34
|
-
"semver": "^7.3.8"
|
|
32
|
+
"semver": "^7.6.0"
|
|
35
33
|
}
|
|
36
|
-
}
|
|
34
|
+
}
|
|
@@ -271,11 +271,8 @@ export default class LWElement extends HTMLElement {
|
|
|
271
271
|
let object;
|
|
272
272
|
let propertyExpr;
|
|
273
273
|
if (astModel.type === 'MemberExpression') {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
// . false and [] true
|
|
277
|
-
propertyExpr = parser.evaluate([astModel.property], context, interpolation.loc)[0];
|
|
278
|
-
}
|
|
274
|
+
// . false and [] true
|
|
275
|
+
propertyExpr = astModel.computed ? parser.evaluate([astModel.property], context, interpolation.loc)[0] : astModel.property.name;
|
|
279
276
|
object = parser.evaluate([astModel.object], context, interpolation.loc)[0];
|
|
280
277
|
} else if (astModel.type === 'Identifier') {
|
|
281
278
|
object = this;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<title>${page.name} - ${project.name}</title>
|
|
6
|
+
<script type="module" src="${pathLevels}${project.name}.js"></script>
|
|
7
|
+
<link rel="stylesheet" href="${pathLevels}${project.name}.css">
|
|
8
|
+
<link rel="icon" type="image/svg+xml" href="${pathLevels}favicon.svg">
|
|
9
|
+
</head>
|
|
10
|
+
<body style="opacity: 0;" onload="document.body.style.opacity=1">
|
|
11
|
+
${page.name} works!
|
|
12
|
+
</body>
|
|
13
|
+
</html>
|