leanweb 2.0.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/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 -15
- package/commands/utils.js +21 -1
- package/package.json +2 -2
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
|
@@ -24,20 +24,7 @@ const noopen = process.env.noopen || false;
|
|
|
24
24
|
|
|
25
25
|
const build = async (eventType, filename) => {
|
|
26
26
|
// 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
|
-
}
|
|
27
|
+
await utils.exec(`npx leanweb build ${env}`);
|
|
41
28
|
};
|
|
42
29
|
|
|
43
30
|
const throttledBuild = utils.throttle(build);
|
|
@@ -54,7 +41,7 @@ const noopen = process.env.noopen || false;
|
|
|
54
41
|
open: !noopen,
|
|
55
42
|
file: 'index.html',
|
|
56
43
|
wait: 1000,
|
|
57
|
-
logLevel:
|
|
44
|
+
logLevel: 1,
|
|
58
45
|
};
|
|
59
46
|
liveServer.start(params);
|
|
60
47
|
})();
|
package/commands/utils.js
CHANGED
|
@@ -2,6 +2,7 @@ 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 = {
|
|
@@ -11,11 +12,30 @@ export const dirs = {
|
|
|
11
12
|
dist: 'dist',
|
|
12
13
|
};
|
|
13
14
|
|
|
14
|
-
export const
|
|
15
|
+
export const copyFilter = (src, dest) => {
|
|
16
|
+
const srcStats = fse.existsSync(src) && fse.lstatSync(src);
|
|
15
17
|
const destStats = fse.existsSync(dest) && fse.lstatSync(dest);
|
|
18
|
+
if (srcStats?.isFile?.() && destStats?.isFile?.()) {
|
|
19
|
+
const srcBuf = fs.readFileSync(src);
|
|
20
|
+
const destBuf = fs.readFileSync(dest);
|
|
21
|
+
if (srcBuf.equals(destBuf)) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
16
25
|
return !destStats?.isSymbolicLink?.();
|
|
17
26
|
};
|
|
18
27
|
|
|
28
|
+
export const writeIfChanged = (file, string) => {
|
|
29
|
+
const stats = fse.existsSync(file) && fse.lstatSync(file);
|
|
30
|
+
if (stats?.isFile?.()) {
|
|
31
|
+
const data = fs.readFileSync(file, 'utf8');
|
|
32
|
+
if (data === string) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
fs.writeFileSync(file, string);
|
|
37
|
+
}
|
|
38
|
+
|
|
19
39
|
export const exec = command => execSync(command, { encoding: 'utf8', stdio: 'inherit' });
|
|
20
40
|
|
|
21
41
|
export const buildCSS = (scssString, ...currentPaths) => {
|
package/package.json
CHANGED