@blueprintui/cli 0.0.0 → 0.0.1

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,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,15 +1,15 @@
1
1
  {
2
2
  "name": "@blueprintui/cli",
3
- "version": "0.0.0",
3
+ "version": "0.0.1",
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
15
  "@custom-elements-manifest/analyzer": "^0.6.1",
@@ -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,12 +21,16 @@ 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',
@@ -33,6 +38,7 @@ const config = {
33
38
  tsconfig: './tsconfig.json',
34
39
  customElementsManifestConfig: './custom-elements-manifest.config.mjs',
35
40
  sourcemap: false,
41
+ ...userConfig.default
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(): [],
80
- // project.prod ? customElementsAnalyzer() : [],
81
- // project.prod ? packageCheck() : [],
86
+ project.prod ? customElementsAnalyzer() : [],
87
+ project.prod ? packageCheck() : [],
82
88
  ],
83
89
  },
84
90
  ];