@blueprintui/cli 0.0.3 → 0.0.6
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/.nvmrc +1 -1
- package/README.md +20 -0
- package/custom-elements-manifest.config.mjs +16 -4
- package/import-assert.mjs +1 -1
- package/index.mjs +18 -15
- package/package.json +3 -2
- package/rollup.config.mjs +34 -29
package/.nvmrc
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
18.3.0
|
package/README.md
CHANGED
|
@@ -15,3 +15,23 @@ Web Component libraries. This project is still an experimental work in progress.
|
|
|
15
15
|
| -------------- | ------------------------------------------ |
|
|
16
16
|
| --config | Path for `blueprint.config.js` file |
|
|
17
17
|
| --watch | Runs build in watch mode for development |
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Configuration
|
|
21
|
+
|
|
22
|
+
The `blueprint.config.js` can be used to customize certain aspects of the build.
|
|
23
|
+
Below are the default values unless otherwise specified.
|
|
24
|
+
|
|
25
|
+
```javascript
|
|
26
|
+
export default {
|
|
27
|
+
library: {
|
|
28
|
+
externals: [],
|
|
29
|
+
assets: ['./README.md', './LICENSE.md', './package.json'],
|
|
30
|
+
baseDir: './src',
|
|
31
|
+
outDir: './dist/lib',
|
|
32
|
+
entryPoints: ['./src/**/index.ts'],
|
|
33
|
+
tsconfig: './tsconfig.lib.json',
|
|
34
|
+
sourcemap: false,
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
```
|
|
@@ -2,10 +2,22 @@
|
|
|
2
2
|
import { resolve } from 'path';
|
|
3
3
|
|
|
4
4
|
const cwd = process.cwd();
|
|
5
|
+
const baseSrc = resolve(cwd, 'src');
|
|
6
|
+
|
|
7
|
+
let userConfig = { };
|
|
8
|
+
if (process.env.BLUEPRINTUI_CONFIG) {
|
|
9
|
+
userConfig = await import(process.env.BLUEPRINTUI_CONFIG);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const config = {
|
|
13
|
+
baseDir: './src',
|
|
14
|
+
outDir: './dist/lib',
|
|
15
|
+
...userConfig?.default?.library
|
|
16
|
+
};
|
|
5
17
|
|
|
6
18
|
export default {
|
|
7
|
-
globs: [resolve(cwd,
|
|
8
|
-
outdir:
|
|
19
|
+
globs: [resolve(cwd, config.baseDir)],
|
|
20
|
+
outdir: config.outDir,
|
|
9
21
|
litelement: true,
|
|
10
22
|
plugins: [tsExtensionPlugin(), baseDir(), orderElements()],
|
|
11
23
|
};
|
|
@@ -19,12 +31,12 @@ export function orderElements() {
|
|
|
19
31
|
};
|
|
20
32
|
}
|
|
21
33
|
|
|
22
|
-
export function baseDir(
|
|
34
|
+
export function baseDir() {
|
|
23
35
|
return {
|
|
24
36
|
name: 'base-dir',
|
|
25
37
|
packageLinkPhase({ customElementsManifest }) {
|
|
26
38
|
customElementsManifest.modules = JSON.parse(
|
|
27
|
-
JSON.stringify(customElementsManifest.modules).replaceAll(`"/${
|
|
39
|
+
JSON.stringify(customElementsManifest.modules).replaceAll(`"/${baseSrc}`, '"').replaceAll(`"${baseSrc}`, '"')
|
|
28
40
|
);
|
|
29
41
|
},
|
|
30
42
|
};
|
package/import-assert.mjs
CHANGED
package/index.mjs
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import path from 'path';
|
|
4
3
|
import * as url from 'url';
|
|
5
|
-
import
|
|
4
|
+
import { path } from 'zx';
|
|
5
|
+
import { spinner } from 'zx/experimental';
|
|
6
6
|
import { rollup, watch } from 'rollup';
|
|
7
7
|
import { program } from 'commander';
|
|
8
|
+
import loadConfigFile from 'rollup/loadConfigFile';
|
|
8
9
|
|
|
9
10
|
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
|
|
12
|
+
const status = {
|
|
13
|
+
error: '\x1b[31m%s\x1b[0m',
|
|
14
|
+
warn: '\x1b[33m%s\x1b[0m',
|
|
15
|
+
info: '\x1b[36m%s\x1b[0m',
|
|
16
|
+
success: '\x1b[32m%s\x1b[0m'
|
|
17
|
+
};
|
|
14
18
|
|
|
15
19
|
program
|
|
16
20
|
.command('build')
|
|
@@ -20,7 +24,7 @@ program
|
|
|
20
24
|
.description('build library')
|
|
21
25
|
.action(async (options, command) => {
|
|
22
26
|
process.env.BLUEPRINTUI_BUILD = options.prod || !options.watch ? 'production' : 'development';
|
|
23
|
-
process.env.BLUEPRINTUI_CONFIG = command.args[0] ? path.resolve(command.args[0]) : path.resolve(
|
|
27
|
+
process.env.BLUEPRINTUI_CONFIG = command.args[0] ? path.resolve(command.args[0]) : path.resolve('./blueprint.config.js');
|
|
24
28
|
buildRollup(options);
|
|
25
29
|
});
|
|
26
30
|
|
|
@@ -40,16 +44,15 @@ function buildRollup(args) {
|
|
|
40
44
|
let bundle;
|
|
41
45
|
let buildFailed = false;
|
|
42
46
|
try {
|
|
43
|
-
|
|
44
|
-
bundle = await rollup(options[0]);
|
|
47
|
+
bundle = await spinner('Building...', async () => await rollup(options[0]));
|
|
45
48
|
await bundle.write(options[0].output[0]);
|
|
46
49
|
} catch (error) {
|
|
47
50
|
buildFailed = true;
|
|
48
|
-
console.error(
|
|
51
|
+
console.error(status.error, error);
|
|
49
52
|
}
|
|
50
53
|
if (bundle) {
|
|
51
54
|
const end = Date.now();
|
|
52
|
-
console.log(
|
|
55
|
+
console.log(status.success, `Completed in ${(end - start) / 1000} seconds 🎉`);
|
|
53
56
|
await bundle.close();
|
|
54
57
|
}
|
|
55
58
|
process.exit(buildFailed ? 1 : 0);
|
|
@@ -66,17 +69,17 @@ function buildRollup(args) {
|
|
|
66
69
|
|
|
67
70
|
switch (event.code) {
|
|
68
71
|
case 'START':
|
|
69
|
-
console.log(
|
|
72
|
+
console.log(status.info, 'Building...');
|
|
70
73
|
break;
|
|
71
74
|
case 'ERROR':
|
|
72
|
-
console.error(
|
|
75
|
+
console.error(status.error, event.error);
|
|
73
76
|
event.result.close();
|
|
74
77
|
break;
|
|
75
78
|
case 'WARN':
|
|
76
|
-
console.error(
|
|
79
|
+
console.error(status.warn, event.error);
|
|
77
80
|
break;
|
|
78
81
|
case 'BUNDLE_END':
|
|
79
|
-
console.log(
|
|
82
|
+
console.log(status.success, `Complete in ${event.duration / 1000} seconds`);
|
|
80
83
|
event.result.close();
|
|
81
84
|
break;
|
|
82
85
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blueprintui/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./index.mjs",
|
|
6
6
|
"bin": {
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"rollup-plugin-shell": "^1.0.3",
|
|
34
34
|
"rollup-plugin-terser": "^7.0.2",
|
|
35
35
|
"tslib": "2.3.1",
|
|
36
|
-
"typescript": "4.6.4"
|
|
36
|
+
"typescript": "4.6.4",
|
|
37
|
+
"zx": "^7.0.0"
|
|
37
38
|
}
|
|
38
39
|
}
|
package/rollup.config.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import glob from 'glob';
|
|
1
|
+
import * as csso from 'csso';
|
|
3
2
|
import typescript from '@rollup/plugin-typescript';
|
|
4
3
|
import nodeResolve from '@rollup/plugin-node-resolve';
|
|
5
4
|
import replace from '@rollup/plugin-replace';
|
|
@@ -8,21 +7,17 @@ import copy from 'rollup-plugin-copy';
|
|
|
8
7
|
import del from 'rollup-plugin-delete';
|
|
9
8
|
import minifyHTML from 'rollup-plugin-minify-html-literals';
|
|
10
9
|
import execute from 'rollup-plugin-shell';
|
|
10
|
+
import { $, fs, glob, path } from 'zx';
|
|
11
|
+
import { extname } from 'path';
|
|
11
12
|
import { terser } from 'rollup-plugin-terser';
|
|
12
|
-
import { resolve, extname } from 'path';
|
|
13
|
-
import { importAssertionsPlugin } from './import-assert.mjs';
|
|
14
|
-
// import { importAssertionsPlugin } from 'rollup-plugin-import-assert';
|
|
15
13
|
import { importAssertions } from 'acorn-import-assertions';
|
|
16
14
|
import { idiomaticDecoratorsTransformer, constructorCleanupTransformer } from '@lit/ts-transformers';
|
|
17
|
-
import * as csso from 'csso';
|
|
18
|
-
import { exec as _exec } from 'child_process';
|
|
19
|
-
import { promisify } from 'util';
|
|
20
|
-
import { dirname } from 'path';
|
|
21
15
|
import { fileURLToPath } from 'url';
|
|
16
|
+
import { importAssertionsPlugin } from './import-assert.mjs';
|
|
17
|
+
// import { importAssertionsPlugin } from 'rollup-plugin-import-assert';
|
|
22
18
|
|
|
23
|
-
const exec = promisify(_exec);
|
|
24
19
|
const __filename = fileURLToPath(import.meta.url);
|
|
25
|
-
const __dirname = dirname(__filename);
|
|
20
|
+
const __dirname = path.dirname(__filename);
|
|
26
21
|
|
|
27
22
|
let userConfig = { };
|
|
28
23
|
if (process.env.BLUEPRINTUI_CONFIG) {
|
|
@@ -31,26 +26,25 @@ if (process.env.BLUEPRINTUI_CONFIG) {
|
|
|
31
26
|
|
|
32
27
|
const config = {
|
|
33
28
|
externals: [],
|
|
34
|
-
assets: ['./README.md', './LICENSE', './package.json'],
|
|
29
|
+
assets: ['./README.md', './LICENSE.md', './package.json'],
|
|
35
30
|
baseDir: './src',
|
|
36
31
|
outDir: './dist/lib',
|
|
37
|
-
entryPoints: ['./src/**/index.ts'
|
|
32
|
+
entryPoints: ['./src/**/index.ts'],
|
|
38
33
|
tsconfig: './tsconfig.lib.json',
|
|
39
|
-
customElementsManifestConfig: './custom-elements-manifest.config.mjs',
|
|
40
34
|
sourcemap: false,
|
|
41
|
-
...userConfig.default
|
|
35
|
+
...userConfig.default?.library
|
|
42
36
|
};
|
|
43
37
|
|
|
44
38
|
const cwd = process.cwd();
|
|
45
39
|
const project = {
|
|
46
40
|
externals: config.externals,
|
|
47
|
-
packageFile: resolve(cwd, './package.json'),
|
|
48
|
-
assets: config.assets.map(a => resolve(cwd, a)),
|
|
49
|
-
baseDir: resolve(cwd, config.baseDir),
|
|
50
|
-
outDir: resolve(cwd, config.outDir),
|
|
51
|
-
entryPoints: config.entryPoints.map(e => resolve(cwd, e)),
|
|
52
|
-
tsconfig: resolve(cwd, config.tsconfig),
|
|
53
|
-
customElementsManifestConfig: resolve(
|
|
41
|
+
packageFile: path.resolve(cwd, './package.json'),
|
|
42
|
+
assets: config.assets.map(a => path.resolve(cwd, a)),
|
|
43
|
+
baseDir: path.resolve(cwd, config.baseDir),
|
|
44
|
+
outDir: path.resolve(cwd, config.outDir),
|
|
45
|
+
entryPoints: config.entryPoints.map(e => path.resolve(cwd, e)),
|
|
46
|
+
tsconfig: path.resolve(cwd, config.tsconfig),
|
|
47
|
+
customElementsManifestConfig: config.customElementsManifestConfig ? path.resolve(cwd, config.customElementsManifestConfig) : path.resolve(__dirname, './custom-elements-manifest.config.mjs'),
|
|
54
48
|
prod: process.env.BLUEPRINTUI_BUILD === 'production',
|
|
55
49
|
sourcemap: config.sourcemap
|
|
56
50
|
}
|
|
@@ -84,7 +78,8 @@ export default [
|
|
|
84
78
|
project.prod ? inlinePackageVersion() : [],
|
|
85
79
|
project.prod ? postClean(): [],
|
|
86
80
|
project.prod ? packageCheck() : [],
|
|
87
|
-
|
|
81
|
+
project.prod ? customElementsAnalyzer() : [],
|
|
82
|
+
project.prod ? cleanPackageJson() : []
|
|
88
83
|
],
|
|
89
84
|
},
|
|
90
85
|
];
|
|
@@ -94,7 +89,7 @@ function copyAssets() {
|
|
|
94
89
|
}
|
|
95
90
|
|
|
96
91
|
function createEntrypoints() {
|
|
97
|
-
return virtual({ 'library-entry-points': [...project.entryPoints.flatMap(i => glob.
|
|
92
|
+
return virtual({ 'library-entry-points': [...project.entryPoints.flatMap(i => glob.globbySync(i))].map(entry => `export * from '${entry}';`).join('\n') });
|
|
98
93
|
}
|
|
99
94
|
|
|
100
95
|
function compileTypescript() {
|
|
@@ -137,18 +132,28 @@ function customElementsAnalyzer() {
|
|
|
137
132
|
if (copied) {
|
|
138
133
|
return;
|
|
139
134
|
} else {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
await fs.writeFile(`${project.outDir}/package.json`, JSON.stringify(packageFile, null, 2));
|
|
135
|
+
const cemPath = path.resolve('node_modules', '@custom-elements-manifest/analyzer/index.js');
|
|
136
|
+
await $`${cemPath} analyze --config ${project.customElementsManifestConfig}`;
|
|
137
|
+
copied = true;
|
|
144
138
|
}
|
|
145
139
|
}
|
|
146
140
|
};
|
|
147
141
|
}
|
|
148
142
|
|
|
143
|
+
function cleanPackageJson() {
|
|
144
|
+
return {
|
|
145
|
+
name: 'clean-package-json',
|
|
146
|
+
writeBundle: async () => {
|
|
147
|
+
const json = await fs.readJson(project.packageFile);
|
|
148
|
+
const packageFile = { ...json, scripts: undefined, devDependencies: undefined };
|
|
149
|
+
await fs.writeFile(`${project.outDir}/package.json`, JSON.stringify(packageFile, null, 2));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
149
154
|
function cssOptimize() {
|
|
150
155
|
return {
|
|
151
|
-
load(id) { return id.slice(-4) === '.css' ? this.addWatchFile(resolve(id)) : null },
|
|
156
|
+
load(id) { return id.slice(-4) === '.css' ? this.addWatchFile(path.resolve(id)) : null },
|
|
152
157
|
transform: async (css, id) => id.slice(-4) === '.css' ? ({ code: csso.minify(css, { comments: false }).css, map: { mappings: '' } }) : null
|
|
153
158
|
};
|
|
154
159
|
};
|