@blueprintui/cli 0.0.0 → 0.0.3

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 ADDED
@@ -0,0 +1 @@
1
+ 16.15.0
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Crylan Software LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # BlueprintUI CLI (alpha)
2
+
3
+ [![npm version](https://badge.fury.io/js/@blueprintui%2Fcli.svg)](https://badge.fury.io/js/@blueprintui%2Fcli)
4
+
5
+ ## Opinionated CLI for creating Web Component Libraries
6
+
7
+ Blueprint CLI provides an out-of-the-box tool kit for compiling and creating
8
+ Web Component libraries. This project is still an experimental work in progress.
9
+
10
+ | Command | Description |
11
+ | ------------ | ----------------------------- |
12
+ | build | Build library for production |
13
+
14
+ | Options | Description |
15
+ | -------------- | ------------------------------------------ |
16
+ | --config | Path for `blueprint.config.js` file |
17
+ | --watch | Runs build in watch mode for development |
@@ -0,0 +1,114 @@
1
+ import path from 'path';
2
+
3
+ // temp workaround due to package "string-to-template-literal" not shipping valid esm module
4
+
5
+ // string-to-template-literal
6
+ var illegalChars = new Map();
7
+ illegalChars.set('\\', '\\\\');
8
+ illegalChars.set('`', '\\`');
9
+ illegalChars.set('$', '\\$');
10
+ function convert(s) {
11
+ if (!s) {
12
+ return '``';
13
+ }
14
+ var res = '';
15
+ for (var i = 0; i < s.length; i++) {
16
+ var c = s.charAt(i);
17
+ res += illegalChars.get(c) || c;
18
+ }
19
+ return "`" + res + "`";
20
+ }
21
+
22
+ // rollup-plugin-import-assert
23
+ function getObjects(obj, key, val) {
24
+ let objects = [];
25
+ for (let prop in obj) {
26
+ if (!obj.hasOwnProperty(prop)) {
27
+ continue;
28
+ }
29
+ if (typeof obj[prop] == 'object') {
30
+ objects = objects.concat(getObjects(obj[prop], key, val));
31
+ }
32
+ else if (prop == key && obj[prop] == val || prop == key && val == '') { //
33
+ objects.push(obj);
34
+ }
35
+ else if (obj[prop] == val && key == '') {
36
+ if (objects.lastIndexOf(obj) == -1) {
37
+ objects.push(obj);
38
+ }
39
+ }
40
+ }
41
+ return objects;
42
+ }
43
+ const assertionMap = new Map();
44
+ const filePattern = /\.(js|ts|jsx|tsx)$/;
45
+ const getImportPath = (id, source) => path.resolve(path.dirname(id), source);
46
+ export function importAssertionsPlugin() {
47
+ return {
48
+ name: 'rollup-plugin-import-assert',
49
+ transform(data, id) {
50
+ let code = data;
51
+ /** If the file is a JS-like file, continue */
52
+ if (filePattern.exec(id)) {
53
+ /** Get the AST data, must be using acorn-import-assertions for this to work */
54
+ const ast = this.parse(data);
55
+ /** @ts-ignore this does exist apparently */
56
+ const { body } = ast;
57
+ const importDeclarations = getObjects(body, 'type', 'ImportDeclaration');
58
+ const importExpressions = getObjects(body, 'type', 'ImportExpression');
59
+ importDeclarations.forEach(node => {
60
+ if (node.assertions) {
61
+ const [assertion] = node.assertions;
62
+ const assert = { type: assertion.value.value };
63
+ const importPath = getImportPath(id, node.source.value);
64
+ assertionMap.set(importPath, assert);
65
+ }
66
+ });
67
+ importExpressions.forEach(node => {
68
+ // Skip dynamic imports with expressions
69
+ // @example: import(`./foo/${bar}.js`); // NOK
70
+ // @example: import(`./foo/bar.js`); // OK
71
+ if (node.source.type === "TemplateLiteral" && node.source.quasis.length > 1) {
72
+ return;
73
+ }
74
+ // @example: `import(foo);` NOK
75
+ if (!node.source.value)
76
+ return;
77
+ const source = node.source.value || node.source.quasis[0].value.raw;
78
+ const importPath = getImportPath(id, source);
79
+ // TODO: We can still make this better
80
+ if (node.hasOwnProperty('arguments') && getObjects(node, 'name', 'assert')) {
81
+ const assert = { type: node.arguments[0].properties[0]?.value?.properties[0].value.value };
82
+ assertionMap.set(importPath, assert);
83
+ const matches = code.match(/import\(.*\)/gi);
84
+ const replacements = matches.map(match => match.replace(/\{(\s?)assert:(\s?)\{.*\}/gi, ''));
85
+ if (matches) {
86
+ matches.forEach((match, index) => code = code.replace(match, replacements[index]));
87
+ code.match(/import\(.*(\s?),(\s?)\)/gi).forEach(match => {
88
+ code = code.replace(match, match.replace(',', ''));
89
+ });
90
+ }
91
+ }
92
+ });
93
+ }
94
+ const assertion = assertionMap.get(id);
95
+ /** If an import assertion exists for the file, parse it differently */
96
+ if (assertion) {
97
+ const { type } = assertion;
98
+ let code = data;
99
+ if (type === 'css') {
100
+ /** Parse files asserted as CSS to use constructible stylesheets */
101
+ code = `const sheet = new CSSStyleSheet();sheet.replaceSync(${convert(data)});export default sheet;`;
102
+ }
103
+ else if (type === 'json') {
104
+ /** Parse files asserted as JSON as a JS object */
105
+ code = `export default ${data}`;
106
+ }
107
+ /** Return the new data and map it back to the original source file */
108
+ return { code, mappings: id };
109
+ }
110
+ /** If none of the above exists, just continue as normal */
111
+ return { code };
112
+ }
113
+ };
114
+ }
package/index.mjs CHANGED
@@ -1,13 +1,5 @@
1
1
  #!/usr/bin/env node
2
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
3
  import path from 'path';
12
4
  import * as url from 'url';
13
5
  import loadConfigFile from 'rollup/loadConfigFile';
@@ -26,18 +18,16 @@ program
26
18
  .option('--watch')
27
19
  .option('--prod')
28
20
  .description('build library')
29
- .action((options, command) => {
21
+ .action(async (options, command) => {
30
22
  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);
23
+ process.env.BLUEPRINTUI_CONFIG = command.args[0] ? path.resolve(command.args[0]) : path.resolve(process.cwd(), './rollup.config.js');
34
24
  buildRollup(options);
35
25
  });
36
26
 
37
27
  program.parse();
38
28
 
39
29
  function buildRollup(args) {
40
- loadConfigFile(path.resolve(__dirname, './rollup.config.js'), {}).then(
30
+ loadConfigFile(path.resolve(__dirname, './rollup.config.mjs'), {}).then(
41
31
  async ({ options, warnings }) => {
42
32
  if (warnings.count) {
43
33
  console.log(`${warnings.count} warnings`);
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@blueprintui/cli",
3
- "version": "0.0.0",
3
+ "version": "0.0.3",
4
4
  "description": "",
5
5
  "main": "./index.mjs",
6
6
  "bin": {
7
7
  "bp": "./index.mjs"
8
8
  },
9
9
  "scripts": {
10
- "test": "echo \"Error: no test specified\" && exit 1"
10
+ "publish": "npm publish --access public"
11
11
  },
12
- "author": "",
12
+ "author": "Cory Rylan",
13
13
  "license": "MIT",
14
14
  "dependencies": {
15
- "@custom-elements-manifest/analyzer": "^0.6.1",
15
+ "@custom-elements-manifest/analyzer": "^0.6.2",
16
16
  "@lit/ts-transformers": "^1.1.1",
17
17
  "@rollup/plugin-node-resolve": "^13.3.0",
18
18
  "@rollup/plugin-replace": "^4.0.0",
@@ -1,5 +1,5 @@
1
- import * as fs from 'fs-extra';
2
- import * as glob from 'glob';
1
+ import fs from 'fs-extra';
2
+ import glob from 'glob';
3
3
  import typescript from '@rollup/plugin-typescript';
4
4
  import nodeResolve from '@rollup/plugin-node-resolve';
5
5
  import replace from '@rollup/plugin-replace';
@@ -10,7 +10,8 @@ import minifyHTML from 'rollup-plugin-minify-html-literals';
10
10
  import execute from 'rollup-plugin-shell';
11
11
  import { terser } from 'rollup-plugin-terser';
12
12
  import { resolve, extname } from 'path';
13
- import { importAssertionsPlugin } from 'rollup-plugin-import-assert';
13
+ import { importAssertionsPlugin } from './import-assert.mjs';
14
+ // import { importAssertionsPlugin } from 'rollup-plugin-import-assert';
14
15
  import { importAssertions } from 'acorn-import-assertions';
15
16
  import { idiomaticDecoratorsTransformer, constructorCleanupTransformer } from '@lit/ts-transformers';
16
17
  import * as csso from 'csso';
@@ -20,19 +21,24 @@ import { dirname } from 'path';
20
21
  import { fileURLToPath } from 'url';
21
22
 
22
23
  const exec = promisify(_exec);
23
- const __filename = fileURLToPath(import.meta.url)
24
- const __dirname = dirname(__filename)
24
+ const __filename = fileURLToPath(import.meta.url);
25
+ const __dirname = dirname(__filename);
25
26
 
27
+ let userConfig = { };
28
+ if (process.env.BLUEPRINTUI_CONFIG) {
29
+ userConfig = await import(process.env.BLUEPRINTUI_CONFIG);
30
+ }
26
31
 
27
32
  const config = {
28
- externals: [/^tslib/, /^lit/, /^@lit-labs\/context/, /^@floating-ui\/dom/, /^date-fns/, /^@blueprintui/],
33
+ externals: [],
29
34
  assets: ['./README.md', './LICENSE', './package.json'],
30
35
  baseDir: './src',
31
36
  outDir: './dist/lib',
32
37
  entryPoints: ['./src/**/index.ts', './src/include/*.ts'],
33
- tsconfig: './tsconfig.json',
38
+ tsconfig: './tsconfig.lib.json',
34
39
  customElementsManifestConfig: './custom-elements-manifest.config.mjs',
35
40
  sourcemap: false,
41
+ ...userConfig.default.library
36
42
  };
37
43
 
38
44
  const cwd = process.cwd();
@@ -73,12 +79,12 @@ export default [
73
79
  compileTypescript(),
74
80
  project.prod ? [] : typeCheck(),
75
81
  project.prod ? [] : writeCache(),
76
- project.prod ? minifyHTML() : [],
82
+ project.prod ? minifyHTML.default() : [],
77
83
  project.prod ? minifyJavaScript() : [],
78
84
  project.prod ? inlinePackageVersion() : [],
79
85
  project.prod ? postClean(): [],
86
+ project.prod ? packageCheck() : [],
80
87
  // project.prod ? customElementsAnalyzer() : [],
81
- // project.prod ? packageCheck() : [],
82
88
  ],
83
89
  },
84
90
  ];
@@ -116,7 +122,7 @@ function inlinePackageVersion() {
116
122
  }
117
123
 
118
124
  function postClean() {
119
- return del({ targets: [`${project.outDir}/**/.tsbuildinfo`, `${project.outDir}/**/_virtual`, `${project.outDir}/**/*.spec.d.ts`, `${project.outDir}/**/*.performance.d.ts`], hook: 'writeBundle' });
125
+ return del({ targets: [`${project.outDir}/**/.tsbuildinfo`, `${project.outDir}/**/_virtual`], hook: 'writeBundle' });
120
126
  }
121
127
 
122
128
  function packageCheck() {
@@ -128,7 +134,6 @@ function customElementsAnalyzer() {
128
134
  return {
129
135
  name: 'custom-elements-analyzer',
130
136
  writeBundle: async () => {
131
- console.log('custom-elements-analyzer');
132
137
  if (copied) {
133
138
  return;
134
139
  } else {