@shgysk8zer0/importmap 1.0.5 → 1.0.7

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/CHANGELOG.md CHANGED
@@ -6,6 +6,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [v1.0.7] - 2023-06-25
10
+
11
+ ### Fixed
12
+ - Fix `bin` path/extension
13
+
14
+ ## [v1.0.6] - 2023-06-25
15
+
16
+ ### Added
17
+ - Add CLI `importmap-utils -i importmap.json -o importmap.yml`
18
+
9
19
  ## [v1.0.5] - 2023-06-24
10
20
 
11
21
  ### Fixed
package/README.md CHANGED
@@ -70,3 +70,31 @@ Which results in:
70
70
  ```html
71
71
  <script type="importmap" integrity="sha384-...">{"imports": {}, "scope": {}}</script>
72
72
  ```
73
+
74
+ ## CLI
75
+
76
+ Create / update local importmap JSON or YAML files.
77
+
78
+ ```
79
+ Usage: importmap-utils [options]
80
+
81
+ CLI utility for updating importmap files
82
+
83
+ Options:
84
+ -V, --version output the version number
85
+ -i, --input [input] local JSON or YAML importmap file
86
+ -e, --encoding [encoding] encoding (default: "utf8")
87
+ -f, --format [format] output format
88
+ -o, --output <output> output file
89
+ -h, --help display help for command
90
+ ```
91
+
92
+ ### CLI Example
93
+
94
+ ```bash
95
+ importmap-utils -o importmap.json
96
+
97
+ # Or...
98
+
99
+ importmap-utils -i importmap.json -o importmap.yml -f yaml
100
+ ```
package/cli.mjs ADDED
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env node
2
+ /* eslint-env node */
3
+
4
+ import { readJSONFile, writeJSONFile } from '@shgysk8zer0/npm-utils/json';
5
+ import { readYAMLFile, writeYAMLFile } from '@shgysk8zer0/npm-utils/yaml';
6
+ import { program } from 'commander';
7
+ import { extname } from 'node:path';
8
+ import { importmap } from './index.js';
9
+
10
+ function guessFileType(file) {
11
+ const ext = extname(file).toLowerCase();
12
+
13
+ switch(ext) {
14
+ case '.yml':
15
+ case '.yaml':
16
+ return 'yaml';
17
+
18
+ case '.json':
19
+ return 'json';
20
+
21
+ default:
22
+ throw new TypeError(`"${ext}" is not a supported file extension for file ${file}.`);
23
+ }
24
+ }
25
+
26
+ async function parse(file, { encoding, signal } = {}) {
27
+ switch(guessFileType(file)) {
28
+ case 'yaml':
29
+ return readYAMLFile(file, { encoding, signal });
30
+
31
+ case 'json':
32
+ return readJSONFile(file, { encoding, signal });
33
+
34
+ }
35
+ }
36
+
37
+ async function init() {
38
+ const { version: VERSION } = await readJSONFile(new URL('./package.json', import.meta.url).pathname);
39
+
40
+ program
41
+ .name('importmap-utils')
42
+ .version(VERSION)
43
+ .description('CLI utility for updating importmap files')
44
+ .option('-i, --input [input]', 'local JSON or YAML importmap file')
45
+ .option('-e, --encoding [encoding]', 'encoding', 'utf8')
46
+ .option('-f, --format [format]', 'output format') // Migrate opt
47
+ .option('-o, --output <output>', 'output file')
48
+ .parse(process.argv);
49
+
50
+ return {
51
+ args: program.args,
52
+ opts: program.opts(),
53
+ };
54
+ }
55
+
56
+ init().then(async ({ opts: { input, encoding, format, output }}) => {
57
+ console.log({ input, encoding, format, output });
58
+ const mod = typeof input === 'string'
59
+ ? await parse(input, { encoding }).then(({ imports, scope = {}, ...rest }) => ({
60
+ ...rest,
61
+ imports: { ...imports, ...importmap.imports },
62
+ scope: { ...scope, ...importmap.scope },
63
+ }))
64
+ : importmap;
65
+
66
+ console.log(mod);
67
+
68
+ switch(format ?? guessFileType(output)) {
69
+ case 'json':
70
+ await writeJSONFile(output, mod, { encoding });
71
+ break;
72
+
73
+ case 'yaml':
74
+ await writeYAMLFile(output, mod, { encoding });
75
+ break;
76
+ }
77
+ });
package/importmap.yml ADDED
@@ -0,0 +1,19 @@
1
+ ---
2
+ nonce: ef17a9fa-7016-48e1-b387-bc869bc6b30d
3
+ imports:
4
+ '@shgysk8zer0/kazoo/': https://unpkg.com/@shgysk8zer0/kazoo@0.0.16/
5
+ '@shgysk8zer0/konami': https://unpkg.com/@shgysk8zer0/konami@1.0.10/konami.js
6
+ '@shgysk8zer0/polyfills': https://unpkg.com/@shgysk8zer0/polyfills@0.1.2/all.min.js
7
+ '@shgysk8zer0/polyfills/': https://unpkg.com/@shgysk8zer0/polyfills@0.1.2/
8
+ '@shgysk8zer0/jswaggersheets/': https://unpkg.com/@shgysk8zer0/jswaggersheets@0.1.2/
9
+ '@shgysk8zer0/http-status': https://unpkg.com/@shgysk8zer0/http-status@1.0.2/http-status.js
10
+ '@shgysk8zer0/components/': https://unpkg.com/@shgysk8zer0/components@0.0.9/
11
+ '@kernvalley/components/': https://unpkg.com/@kernvalley/components@1.0.1/
12
+ '@webcomponents/custom-elements': >-
13
+ https://unpkg.com/@webcomponents/custom-elements@1.6.0/custom-elements.min.js
14
+ leaflet: https://unpkg.com/leaflet@1.9.4/dist/leaflet-src.esm.js
15
+ firebase/: https://www.gstatic.com/firebasejs/9.22.2/
16
+ urlpattern-polyfill: https://unpkg.com/urlpattern-polyfill@9.0.0/index.js
17
+ highlight.js: https://unpkg.com/@highlightjs/cdn-assets@11.8.0/es/highlight.min.js
18
+ highlight.js/: https://unpkg.com/@highlightjs/cdn-assets@undefined/
19
+ scope: {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shgysk8zer0/importmap",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "engines": {
5
5
  "node": ">=18.0.0"
6
6
  },
@@ -12,6 +12,9 @@
12
12
  "import": "./index.js",
13
13
  "require": "./index.cjs"
14
14
  },
15
+ "bin": {
16
+ "importmap-utils": "./cli.mjs"
17
+ },
15
18
  "scripts": {
16
19
  "test": "npm run lint:js && npm run build",
17
20
  "preversion": "npm test",
@@ -38,5 +41,9 @@
38
41
  "homepage": "https://github.com/shgysk8zer0/importmap#readme",
39
42
  "devDependencies": {
40
43
  "@shgysk8zer0/js-utils": "^1.0.0"
44
+ },
45
+ "dependencies": {
46
+ "@shgysk8zer0/npm-utils": "^1.0.5",
47
+ "commander": "^11.0.0"
41
48
  }
42
49
  }