@blueprintui/cli 0.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.
@@ -0,0 +1,40 @@
1
+ // import { readonlyPlugin } from 'cem-plugin-readonly';
2
+ import { resolve } from 'path';
3
+
4
+ const cwd = process.cwd();
5
+
6
+ export default {
7
+ globs: [resolve(cwd, './src/**/element.ts')],
8
+ outdir: './dist/lib',
9
+ litelement: true,
10
+ plugins: [tsExtensionPlugin(), baseDir(), orderElements()],
11
+ };
12
+
13
+ export function orderElements() {
14
+ return {
15
+ name: 'order-elements',
16
+ packageLinkPhase({ customElementsManifest }) {
17
+ customElementsManifest.modules.sort((a, b) => (a.path < b.path ? -1 : 1));
18
+ },
19
+ };
20
+ }
21
+
22
+ export function baseDir(config = { baseDir: 'src' }) {
23
+ return {
24
+ name: 'base-dir',
25
+ packageLinkPhase({ customElementsManifest }) {
26
+ customElementsManifest.modules = JSON.parse(
27
+ JSON.stringify(customElementsManifest.modules).replaceAll(`"/${config.baseDir}/`, '"').replaceAll(`"${config.baseDir}/`, '"')
28
+ );
29
+ },
30
+ };
31
+ }
32
+
33
+ export function tsExtensionPlugin() {
34
+ return {
35
+ name: 'ts-extensions',
36
+ packageLinkPhase({ customElementsManifest }) {
37
+ customElementsManifest.modules = JSON.parse(JSON.stringify(customElementsManifest.modules).replace(/\.ts"/g, '.js"'));
38
+ },
39
+ };
40
+ }
package/index.mjs ADDED
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env node
2
+
3
+ // const path = require('path');
4
+ // const url = require('url');
5
+ // const loadConfigFile = require('rollup/loadConfigFile');
6
+ // const rollupModule = require('rollup');
7
+ // const commander = require('commander');
8
+ // const { rollup, watch } = rollupModule;
9
+ // const { program } = commander;
10
+
11
+ import path from 'path';
12
+ import * as url from 'url';
13
+ import loadConfigFile from 'rollup/loadConfigFile';
14
+ import { rollup, watch } from 'rollup';
15
+ import { program } from 'commander';
16
+
17
+ const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
18
+ const ERROR = '\x1b[31m%s\x1b[0m'; //red
19
+ const WARN = '\x1b[33m%s\x1b[0m'; //yellow
20
+ const INFO = '\x1b[36m%s\x1b[0m'; //cyan
21
+ const SUCCESS = '\x1b[32m%s\x1b[0m'; //green
22
+
23
+ program
24
+ .command('build')
25
+ .option('--config', 'path for custom config')
26
+ .option('--watch')
27
+ .option('--prod')
28
+ .description('build library')
29
+ .action((options, command) => {
30
+ process.env.BLUEPRINTUI_BUILD = options.prod || !options.watch ? 'production' : 'development';
31
+ // const configPath = path.resolve(command.args[0]);
32
+ // const baseDir = configPath.replace('blueprint.config.js', '');
33
+ // const dist = resolve(baseDir, config.dist);
34
+ buildRollup(options);
35
+ });
36
+
37
+ program.parse();
38
+
39
+ function buildRollup(args) {
40
+ loadConfigFile(path.resolve(__dirname, './rollup.config.js'), {}).then(
41
+ async ({ options, warnings }) => {
42
+ if (warnings.count) {
43
+ console.log(`${warnings.count} warnings`);
44
+ }
45
+
46
+ warnings.flush();
47
+
48
+ if (!args.watch) {
49
+ const start = Date.now();
50
+ let bundle;
51
+ let buildFailed = false;
52
+ try {
53
+ console.log(INFO, 'Building...');
54
+ bundle = await rollup(options[0]);
55
+ await bundle.write(options[0].output[0]);
56
+ } catch (error) {
57
+ buildFailed = true;
58
+ console.error(ERROR, error);
59
+ }
60
+ if (bundle) {
61
+ const end = Date.now();
62
+ console.log(SUCCESS, `Completed in ${(end - start) / 1000} seconds 🎉`);
63
+ await bundle.close();
64
+ }
65
+ process.exit(buildFailed ? 1 : 0);
66
+ }
67
+
68
+ if (args.watch) {
69
+ const watcher = watch(options[0]);
70
+
71
+ try {
72
+ watcher.on('event', (event) => {
73
+ if (event.result) {
74
+ event.result.watchFiles = null;
75
+ }
76
+
77
+ switch (event.code) {
78
+ case 'START':
79
+ console.log(INFO, 'Building...');
80
+ break;
81
+ case 'ERROR':
82
+ console.error(ERROR, event.error);
83
+ event.result.close();
84
+ break;
85
+ case 'WARN':
86
+ console.error(ERROR, event.error);
87
+ break;
88
+ case 'BUNDLE_END':
89
+ console.log(SUCCESS, `Complete in ${event.duration / 1000} seconds`);
90
+ event.result.close();
91
+ break;
92
+ }
93
+ });
94
+ } catch (error) {
95
+ console.error(error);
96
+ }
97
+ watcher.on('event', ({ result }) => {
98
+ if (result) {
99
+ result.close();
100
+ }
101
+ });
102
+ }
103
+ }
104
+ );
105
+ }
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@blueprintui/cli",
3
+ "version": "0.0.0",
4
+ "description": "",
5
+ "main": "./index.mjs",
6
+ "bin": {
7
+ "bp": "./index.mjs"
8
+ },
9
+ "scripts": {
10
+ "test": "echo \"Error: no test specified\" && exit 1"
11
+ },
12
+ "author": "",
13
+ "license": "MIT",
14
+ "dependencies": {
15
+ "@custom-elements-manifest/analyzer": "^0.6.1",
16
+ "@lit/ts-transformers": "^1.1.1",
17
+ "@rollup/plugin-node-resolve": "^13.3.0",
18
+ "@rollup/plugin-replace": "^4.0.0",
19
+ "@rollup/plugin-typescript": "^8.3.2",
20
+ "@rollup/plugin-virtual": "^2.1.0",
21
+ "@skypack/package-check": "^0.2.2",
22
+ "acorn-import-assertions": "^1.8.0",
23
+ "commander": "^9.2.0",
24
+ "csso": "^5.0.3",
25
+ "fs-extra": "^10.1.0",
26
+ "glob": "^8.0.3",
27
+ "path": "^0.12.7",
28
+ "rollup": "^2.74.1",
29
+ "rollup-plugin-copy": "^3.4.0",
30
+ "rollup-plugin-delete": "^2.0.0",
31
+ "rollup-plugin-import-assert": "^2.1.0",
32
+ "rollup-plugin-minify-html-literals": "^1.2.6",
33
+ "rollup-plugin-shell": "^1.0.3",
34
+ "rollup-plugin-terser": "^7.0.2",
35
+ "tslib": "2.3.1",
36
+ "typescript": "4.6.4"
37
+ }
38
+ }
@@ -0,0 +1,172 @@
1
+ import * as fs from 'fs-extra';
2
+ import * as glob from 'glob';
3
+ import typescript from '@rollup/plugin-typescript';
4
+ import nodeResolve from '@rollup/plugin-node-resolve';
5
+ import replace from '@rollup/plugin-replace';
6
+ import virtual from '@rollup/plugin-virtual';
7
+ import copy from 'rollup-plugin-copy';
8
+ import del from 'rollup-plugin-delete';
9
+ import minifyHTML from 'rollup-plugin-minify-html-literals';
10
+ import execute from 'rollup-plugin-shell';
11
+ import { terser } from 'rollup-plugin-terser';
12
+ import { resolve, extname } from 'path';
13
+ import { importAssertionsPlugin } from 'rollup-plugin-import-assert';
14
+ import { importAssertions } from 'acorn-import-assertions';
15
+ import { idiomaticDecoratorsTransformer, constructorCleanupTransformer } from '@lit/ts-transformers';
16
+ import * as csso from 'csso';
17
+ import { exec as _exec } from 'child_process';
18
+ import { promisify } from 'util';
19
+ import { dirname } from 'path';
20
+ import { fileURLToPath } from 'url';
21
+
22
+ const exec = promisify(_exec);
23
+ const __filename = fileURLToPath(import.meta.url)
24
+ const __dirname = dirname(__filename)
25
+
26
+
27
+ const config = {
28
+ externals: [/^tslib/, /^lit/, /^@lit-labs\/context/, /^@floating-ui\/dom/, /^date-fns/, /^@blueprintui/],
29
+ assets: ['./README.md', './LICENSE', './package.json'],
30
+ baseDir: './src',
31
+ outDir: './dist/lib',
32
+ entryPoints: ['./src/**/index.ts', './src/include/*.ts'],
33
+ tsconfig: './tsconfig.json',
34
+ customElementsManifestConfig: './custom-elements-manifest.config.mjs',
35
+ sourcemap: false,
36
+ };
37
+
38
+ const cwd = process.cwd();
39
+ const project = {
40
+ externals: config.externals,
41
+ packageFile: resolve(cwd, './package.json'),
42
+ assets: config.assets.map(a => resolve(cwd, a)),
43
+ baseDir: resolve(cwd, config.baseDir),
44
+ outDir: resolve(cwd, config.outDir),
45
+ entryPoints: config.entryPoints.map(e => resolve(cwd, e)),
46
+ tsconfig: resolve(cwd, config.tsconfig),
47
+ customElementsManifestConfig: resolve(__dirname, config.customElementsManifestConfig),
48
+ prod: process.env.BLUEPRINTUI_BUILD === 'production',
49
+ sourcemap: config.sourcemap
50
+ }
51
+
52
+ export default [
53
+ {
54
+ external: project.externals,
55
+ input: 'library-entry-points',
56
+ treeshake: false,
57
+ preserveEntrySignatures: 'strict',
58
+ output: {
59
+ format: 'esm',
60
+ dir: project.outDir,
61
+ preserveModules: true,
62
+ sourcemap: project.sourcemap,
63
+ sourcemapExcludeSources: true
64
+ },
65
+ acornInjectPlugins: [importAssertions],
66
+ plugins: [
67
+ // del({ targets: [project.outDir], hook: 'buildStart', runOnce: true }),
68
+ copyAssets(),
69
+ project.prod ? cssOptimize() : [],
70
+ importAssertionsPlugin(),
71
+ createEntrypoints(),
72
+ nodeResolve({ exportConditions: [project.prod ? 'production' : 'development'] }),
73
+ compileTypescript(),
74
+ project.prod ? [] : typeCheck(),
75
+ project.prod ? [] : writeCache(),
76
+ project.prod ? minifyHTML() : [],
77
+ project.prod ? minifyJavaScript() : [],
78
+ project.prod ? inlinePackageVersion() : [],
79
+ project.prod ? postClean(): [],
80
+ // project.prod ? customElementsAnalyzer() : [],
81
+ // project.prod ? packageCheck() : [],
82
+ ],
83
+ },
84
+ ];
85
+
86
+ function copyAssets() {
87
+ return copy({ copyOnce: true, targets: project.assets.map(src => ({ src, dest: config.outDir }))});
88
+ }
89
+
90
+ function createEntrypoints() {
91
+ return virtual({ 'library-entry-points': [...project.entryPoints.flatMap(i => glob.sync(i))].map(entry => `export * from '${entry}';`).join('\n') });
92
+ }
93
+
94
+ function compileTypescript() {
95
+ return typescript({
96
+ tsconfig: project.tsconfig,
97
+ noEmitOnError: project.prod,
98
+ compilerOptions: { sourceMap: project.sourcemap },
99
+ transformers: {
100
+ before: [{ type: 'program', factory: idiomaticDecoratorsTransformer }],
101
+ after: [{ type: 'program', factory: constructorCleanupTransformer }],
102
+ }
103
+ });
104
+ }
105
+
106
+ function typeCheck() {
107
+ return execute({ commands: [`tsc --noEmit --project ${project.tsconfig}`], hook: 'buildEnd' });
108
+ }
109
+
110
+ function minifyJavaScript() {
111
+ return terser({ ecma: 2022, module: true, format: { comments: false }, compress: { passes: 2, unsafe: true } });
112
+ }
113
+
114
+ function inlinePackageVersion() {
115
+ return replace({ preventAssignment: false, values: { PACKAGE_VERSION: fs.readJsonSync(project.packageFile).version } })
116
+ }
117
+
118
+ function postClean() {
119
+ return del({ targets: [`${project.outDir}/**/.tsbuildinfo`, `${project.outDir}/**/_virtual`, `${project.outDir}/**/*.spec.d.ts`, `${project.outDir}/**/*.performance.d.ts`], hook: 'writeBundle' });
120
+ }
121
+
122
+ function packageCheck() {
123
+ return execute({ commands: [`package-check --cwd ${project.outDir}`], sync: true, hook: 'writeBundle' });
124
+ };
125
+
126
+ function customElementsAnalyzer() {
127
+ let copied = false;
128
+ return {
129
+ name: 'custom-elements-analyzer',
130
+ writeBundle: async () => {
131
+ console.log('custom-elements-analyzer');
132
+ if (copied) {
133
+ return;
134
+ } else {
135
+ await exec(`cem analyze --config ${project.customElementsManifestConfig}`);
136
+ const json = await fs.readJson(project.packageFile);
137
+ const packageFile = { ...json, customElements: './custom-elements.json', scripts: undefined, devDependencies: undefined };
138
+ await fs.writeFile(`${project.outDir}/package.json`, JSON.stringify(packageFile, null, 2));
139
+ }
140
+ }
141
+ };
142
+ }
143
+
144
+ function cssOptimize() {
145
+ return {
146
+ load(id) { return id.slice(-4) === '.css' ? this.addWatchFile(resolve(id)) : null },
147
+ transform: async (css, id) => id.slice(-4) === '.css' ? ({ code: csso.minify(css, { comments: false }).css, map: { mappings: '' } }) : null
148
+ };
149
+ };
150
+
151
+ const fileCache = {};
152
+ /**
153
+ * Rollup plugin for local file writes
154
+ * Compares the output of rollup to the current file on disk. If same it will
155
+ * prevent rollup from writting to the file again preventing file watchers from being triggered
156
+ */
157
+ function writeCache() {
158
+ return {
159
+ name: 'esm-cache',
160
+ generateBundle(_options, bundles) {
161
+ for (const [key, bundle] of Object.entries(bundles)) {
162
+ const path = `${project.outDir}/${bundle.fileName}`;
163
+
164
+ if (extname(path) === '.js' && fileCache[path] !== bundle.code) {
165
+ fileCache[path] = bundle.code;
166
+ } else {
167
+ delete bundles[key];
168
+ }
169
+ }
170
+ },
171
+ };
172
+ };