@vanillaes/esmtk 0.16.2 → 0.17.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.
@@ -336,6 +336,78 @@
336
336
  "cwd": "${workspaceFolder}",
337
337
  "args": ["rm", "./test/cp2/test1.txt", "./test/cp2/*.js"],
338
338
  "console": "integratedTerminal",
339
+ },
340
+ {
341
+ "name": "Clean --bundle",
342
+ "type": "node",
343
+ "request": "launch",
344
+ "skipFiles": [
345
+ "<node_internals>/**"
346
+ ],
347
+ "program": "${workspaceFolder}/bin/esmtk.js",
348
+ "cwd": "${workspaceFolder}",
349
+ "args": ["clean", "--bundle"],
350
+ "console": "integratedTerminal",
351
+ },
352
+ {
353
+ "name": "Clean --bundle w/ override",
354
+ "type": "node",
355
+ "request": "launch",
356
+ "skipFiles": [
357
+ "<node_internals>/**"
358
+ ],
359
+ "program": "${workspaceFolder}/bin/esmtk.js",
360
+ "cwd": "${workspaceFolder}",
361
+ "args": ["clean", "--bundle", "**/*.js"],
362
+ "console": "integratedTerminal",
363
+ },
364
+ {
365
+ "name": "Clean --bundle w/ Error",
366
+ "type": "node",
367
+ "request": "launch",
368
+ "skipFiles": [
369
+ "<node_internals>/**"
370
+ ],
371
+ "program": "${workspaceFolder}/bin/esmtk.js",
372
+ "cwd": "${workspaceFolder}",
373
+ "args": ["clean", "--bundle", "**/*.mjs"],
374
+ "console": "integratedTerminal",
375
+ },
376
+ {
377
+ "name": "Clean --minify",
378
+ "type": "node",
379
+ "request": "launch",
380
+ "skipFiles": [
381
+ "<node_internals>/**"
382
+ ],
383
+ "program": "${workspaceFolder}/bin/esmtk.js",
384
+ "cwd": "${workspaceFolder}",
385
+ "args": ["clean", "--minify"],
386
+ "console": "integratedTerminal",
387
+ },
388
+ {
389
+ "name": "Clean --typings",
390
+ "type": "node",
391
+ "request": "launch",
392
+ "skipFiles": [
393
+ "<node_internals>/**"
394
+ ],
395
+ "program": "${workspaceFolder}/bin/esmtk.js",
396
+ "cwd": "${workspaceFolder}",
397
+ "args": ["clean", "--typings"],
398
+ "console": "integratedTerminal",
399
+ },
400
+ {
401
+ "name": "Clean All",
402
+ "type": "node",
403
+ "request": "launch",
404
+ "skipFiles": [
405
+ "<node_internals>/**"
406
+ ],
407
+ "program": "${workspaceFolder}/bin/esmtk.js",
408
+ "cwd": "${workspaceFolder}",
409
+ "args": ["clean", "--bundle", "--minify", "--typings"],
410
+ "console": "integratedTerminal",
339
411
  }
340
412
  ]
341
413
  }
package/README.md CHANGED
@@ -22,7 +22,11 @@ Lint the source code (using StandardJS)
22
22
  ### Usage
23
23
 
24
24
  ```sh
25
+ # lint the sources
25
26
  esmtk lint
27
+
28
+ # lint the sources and attempt to automatally fix the issues
29
+ esmtk --fix lint
26
30
  ```
27
31
 
28
32
  ## Types
@@ -31,7 +35,7 @@ Type check the JSDoc typings (using Typescript)
31
35
 
32
36
  ### Arguments
33
37
 
34
- `esmtk types index.js`
38
+ `esmtk types [entry]`
35
39
 
36
40
  - `[entry]` - the entry-point for the source
37
41
  - `--strict` - enable 'strict mode' type checks
@@ -39,25 +43,15 @@ Type check the JSDoc typings (using Typescript)
39
43
  ### Usage
40
44
 
41
45
  ```sh
46
+ # type check the sources
42
47
  esmtk types index.js
43
- ```
44
-
45
- ## Typings
46
-
47
- Generate Type Declarations (.d.ts) from JSDoc (using Typescript)
48
-
49
- ### Arguments
50
-
51
- `esmtk typings index.js`
52
-
53
- - `[entry]` - the entry-point for the source
54
48
 
55
- ### Usage
56
-
57
- ```sh
58
- esmtk typings index.js
49
+ # type check the sources (with 'strict mode' enabled)
50
+ esmtk types --strict index.js
59
51
  ```
60
52
 
53
+ **Node: Due to Typescript limitations, inline JSDoc typings will be ignored if typings (ie `*.d.ts` files) exist.**
54
+
61
55
  ## Bundle
62
56
 
63
57
  Bundle the source code to an ECMAScript module (using ESBuild)
@@ -73,7 +67,11 @@ Bundle the source code to an ECMAScript module (using ESBuild)
73
67
  ### Usage
74
68
 
75
69
  ```sh
70
+ # bundle ESM source -> ESM bundle
76
71
  esmtk bundle src/sample.js bundle.js
72
+
73
+ # bundle ESM source -> ESM bundle (includes Node-specific bindings)
74
+ esmtk bundle --platform=node src/sample.js bundle.js
77
75
  ```
78
76
 
79
77
  ## Minify
@@ -92,7 +90,14 @@ Bundle and Minify the source code to an ECMAScript module (using ESBuild)
92
90
  ### Usage
93
91
 
94
92
  ```sh
93
+ # bundle ESM source -> minified ESM bundle
95
94
  esmtk minify src/sample.js bundle.min.js
95
+
96
+ # bundle ESM source -> minified ESM bundle (includes Node-specific bindings)
97
+ esmtk minify --platform=node src/sample.js bundle.min.js
98
+
99
+ # bundle ESM source -> minified ESM bundle (output a sourcemap)
100
+ esmtk minify --sourcemap src/sample.js bundle.min.js
96
101
  ```
97
102
 
98
103
  ## CommonJS
@@ -110,9 +115,55 @@ Bundle the source code to a CommonJS module (using ESBuild)
110
115
  ### Usage
111
116
 
112
117
  ```sh
118
+ # bundle ESM source -> CommonJS bundle
113
119
  esmtk commonjs src/sample.js bundle.cjs
120
+
121
+ # bundle ESM source -> CommonJS bundle (includes Node-specific bindings)
122
+ esmtk commonjs --platform=node src/sample.js bundle.cjs
123
+ ```
124
+
125
+ ## Typings
126
+
127
+ Generate Type Declarations (.d.ts) from JSDoc (using Typescript)
128
+
129
+ ### Arguments
130
+
131
+ `esmtk typings [entry]`
132
+
133
+ - `[entry]` - the entry-point for the source
134
+
135
+ ### Usage
136
+
137
+ ```sh
138
+ # generate .d.ts files for all linked source files
139
+ esmtk typings index.js
140
+ ```
141
+
142
+ ## Clean
143
+
144
+ Clean up build artifacts
145
+
146
+ ### Arguments
147
+
148
+ `esmtk clean [root]`
149
+
150
+ - `[root]` - the root directory to perform the cleanup (default: `process.cwd()`)
151
+ - `--bundle` - Clean bundled build artifacts (default: `*.esm.js`)
152
+ - `--minify` - Clean minified build artifacts (default: `*.min.js`)
153
+ - `--typings` - Clean typing artifacts (default: `*.d.ts`)
154
+
155
+ ### Usage
156
+
157
+ ```sh
158
+ # clean all build artifacts
159
+ esmtk clean --bundle --minify --typings
160
+
161
+ # override default extension
162
+ esmtk clean --bundle *.mjs
114
163
  ```
115
164
 
165
+ **Node: The `clean` command automatically ignores the contents of `node_modules/`**
166
+
116
167
  ## Copy
117
168
 
118
169
  Copy is a cross-platform clone of the `cp` command in Linux
@@ -121,17 +172,26 @@ Copy is a cross-platform clone of the `cp` command in Linux
121
172
 
122
173
  `esmtk cp [-r] [source...] [destination]`
123
174
 
124
- - `[source...]` - the source file(s)/glob(s)
175
+ - `[source(s)...]` - the source file(s)/glob(s)
125
176
  - `[destination]` - the destination file/directory
126
177
  - `-r, --recursive` - copy files/directories recursively
127
178
 
128
179
  ### Usage
129
180
 
130
181
  ```sh
182
+ # copy one file
131
183
  esmtk cp file1.txt dest/file1.txt
184
+
185
+ # copy multiple files
132
186
  esmtk cp file1.txt file2.txt file3.txt dest/
187
+
188
+ # copy files that match a glob
133
189
  esmtk cp *.txt dest/
190
+
191
+ # copy files that match multiple globs
134
192
  esmtk cp *.txt *.js *.ts dest/
193
+
194
+ # recursively copy files from one directory to another
135
195
  esmtk cp -r src/ dest/
136
196
  ```
137
197
 
@@ -149,9 +209,18 @@ Remove is a cross-platform clone of the `rm` command in Linux
149
209
  ### Usage
150
210
 
151
211
  ```sh
212
+ # remove one file
152
213
  esmtk rm file1.txt
214
+
215
+ # remove multiple files
153
216
  esmtk rm file1.txt file3.txt file3.txt
217
+
218
+ # remove files that match a glob
154
219
  esmtk rm *.txt
220
+
221
+ # remove files that match miltiple globs
155
222
  esmtk rm *.txt *.js *.ts
223
+
224
+ # recursively remove a
156
225
  esmtk rm -r src/
157
226
  ```
@@ -0,0 +1,32 @@
1
+ import { removeMultipleAsync } from '../../src/rm.js'
2
+ import { fileExists, match } from '../../src/util.js'
3
+
4
+ /**
5
+ * Clean build artifcats using sensible defaults
6
+ * @param {string} root the root directory
7
+ * @param {any} options clean options
8
+ */
9
+ export async function clean (root, options) {
10
+ const exists = await fileExists(root)
11
+ if (!exists) {
12
+ console.error(`clean: ${root} No such file or directory`)
13
+ process.exit(1)
14
+ }
15
+
16
+ if (options?.bundle) {
17
+ await cleanOne(root, options.bundle, options)
18
+ }
19
+
20
+ if (options?.minify) {
21
+ await cleanOne(root, options.minify, options)
22
+ }
23
+
24
+ if (options?.typings) {
25
+ await cleanOne(root, options.typings, options)
26
+ }
27
+ }
28
+
29
+ async function cleanOne (root, glob, options) {
30
+ const files = await match(glob, root, 'node_modules/**')
31
+ await removeMultipleAsync(files, options?.force)
32
+ }
@@ -1,5 +1,5 @@
1
1
  import { copyAsync, copyMultipleAsync, copyRecursiveAsync } from '../../src/cp.js'
2
- import { expandSource } from '../../src/index.js'
2
+ import { expand } from '../../src/index.js'
3
3
 
4
4
  /**
5
5
  * POSIX cp Implemented in Node
@@ -25,14 +25,14 @@ export async function cp (paths, options) {
25
25
  }
26
26
 
27
27
  if (source.includes('*')) {
28
- const sources = await expandSource(source)
28
+ const sources = await expand(source)
29
29
  await copyMultipleAsync(sources, target, options?.force)
30
30
  }
31
31
  }
32
32
 
33
33
  if (paths.length > 2) {
34
34
  let sources = paths.slice(0, -1)
35
- sources = await await Promise.all(sources.map(source => expandSource(source)))
35
+ sources = await await Promise.all(sources.map(source => expand(source)))
36
36
  sources = sources.flat()
37
37
  const target = paths.slice(-1)[0]
38
38
 
@@ -1,4 +1,5 @@
1
1
  export { bundle } from './bundle.js'
2
+ export { clean } from './clean.js'
2
3
  export { commonjs } from './commonjs.js'
3
4
  export { cp } from './cp.js'
4
5
  export { lint } from './lint.js'
@@ -1,5 +1,5 @@
1
1
  import { removeAsync, removeMultipleAsync, removeRecursiveAsync } from '../../src/rm.js'
2
- import { expandSource } from '../../src/util.js'
2
+ import { expand } from '../../src/util.js'
3
3
 
4
4
  /**
5
5
  * POSIX rm Implemented in Node
@@ -20,13 +20,13 @@ export async function rm (paths, options) {
20
20
 
21
21
  if (paths[0].includes('*')) {
22
22
  const glob = paths[0]
23
- const files = await expandSource(glob)
23
+ const files = await expand(glob)
24
24
  await removeMultipleAsync(files, options?.force)
25
25
  }
26
26
  }
27
27
 
28
28
  if (paths.length > 1) {
29
- let files = await await Promise.all(paths.map(path => expandSource(path)))
29
+ let files = await await Promise.all(paths.map(path => expand(path)))
30
30
  files = files.flat()
31
31
 
32
32
  await removeMultipleAsync(files, options?.force)
package/bin/esmtk.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { bundle, cp, commonjs, lint, minify, rm, types, typings } from './commands/index.js'
2
+ import { bundle, clean, cp, commonjs, lint, minify, rm, types, typings } from './commands/index.js'
3
3
  import { Command } from 'commander'
4
4
  import { createRequire } from 'module'
5
5
  const program = new Command()
@@ -51,6 +51,29 @@ program.command('minify <input> <output>')
51
51
  minify(input, output, options)
52
52
  })
53
53
 
54
+ program.command('clean')
55
+ .description('Clean build artificts')
56
+ .argument('[root]', 'The root directory to perform operations from (default cwd)', process.cwd())
57
+ .option('--bundle [bundle]', 'Clean bundled build artifacts (default: *.esm.js)')
58
+ .option('--minify [minify]', 'Clean minified build artifacts (default: *.min.js)')
59
+ .option('--typings [typings]', 'Clean typing artifacts (default: *.d.ts)')
60
+ // .option('-f, --force', 'Do not prompt before overwriting', false)
61
+ .action((root, options) => {
62
+ // set --bundle default
63
+ if (options?.bundle && typeof (options.bundle) === 'boolean') {
64
+ options.bundle = '**/*.esm.js'
65
+ }
66
+ // set --minify default
67
+ if (options?.minify && typeof (options.minify) === 'boolean') {
68
+ options.minify = '**/*.min.js'
69
+ }
70
+ // set --typings default
71
+ if (options?.typings && typeof (options.typings) === 'boolean') {
72
+ options.typings = '**/*.d.ts'
73
+ }
74
+ clean(root, options)
75
+ })
76
+
54
77
  program.command('cp')
55
78
  .usage(`[-r] source target
56
79
 
@@ -63,6 +86,7 @@ program.command('cp')
63
86
  .description('Copy files and directories')
64
87
  .argument('[paths...]')
65
88
  .option('-r, --recursive', 'Copy directories recursively', false)
89
+ // .option('-f, --force', 'Do not prompt before overwriting', false)
66
90
  .action((paths, options) => {
67
91
  cp(paths, options)
68
92
  })
@@ -78,7 +102,7 @@ program.command('rm')
78
102
  `)
79
103
  .description('Remove files or directories')
80
104
  .argument('[paths...]')
81
- .option('-f, --force', 'Do not prompt before overwriting', false)
105
+ // .option('-f, --force', 'Do not prompt before overwriting', false)
82
106
  .option('-r, --recursive', 'Remove directories recursively', false)
83
107
  .action((paths, options) => {
84
108
  rm(paths, options)
package/package.json CHANGED
@@ -1,13 +1,19 @@
1
1
  {
2
2
  "name": "@vanillaes/esmtk",
3
- "version": "0.16.2",
3
+ "version": "0.17.1",
4
4
  "description": "ES Module Toolkit",
5
5
  "keywords": [
6
+ "ecmascript",
6
7
  "esm",
7
8
  "esmodules",
8
- "nodejs",
9
9
  "cli",
10
- "developer-tools"
10
+ "developer-tools",
11
+ "jsdoc",
12
+ "fs",
13
+ "cp",
14
+ "copy",
15
+ "rm",
16
+ "remove"
11
17
  ],
12
18
  "repository": "https://github.com/vanillaes/esmtk",
13
19
  "author": "Evan Plaice <evanplaice@gmail.com> (https://evanplaice.com/)",
@@ -33,7 +39,10 @@
33
39
  "scripts": {
34
40
  "lint": "./bin/esmtk.js lint",
35
41
  "types": "./bin/esmtk.js types src/index.js",
42
+ "bundle": "./bin/esmtk.js bundle --platform=node src/index.js src/index.esm.js",
43
+ "minify": "./bin/esmtk.js minify --platform=node src/index.js src/index.min.js",
36
44
  "typings": "./bin/esmtk.js typings src/index.js",
45
+ "clean": "./bin/esmtk.js clean --bundle --minify --typings",
37
46
  "preversion": "npm run lint && npm run types",
38
47
  "postversion": "git push --follow-tags"
39
48
  },
package/src/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { copyAsync, copyRecursiveAsync } from "./cp.js";
2
2
  export { removeAsync, removeMultipleAsync, removeRecursiveAsync } from "./rm.js";
3
- export { expandSource, fileExists, installed, match, which } from "./util.js";
3
+ export { expand, fileExists, installed, match, which } from "./util.js";
package/src/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  export { copyAsync, copyRecursiveAsync } from './cp.js'
2
2
  export { removeAsync, removeMultipleAsync, removeRecursiveAsync } from './rm.js'
3
- export { expandSource, fileExists, installed, match, which } from './util.js'
3
+ export { expand, fileExists, installed, match, which } from './util.js'
package/src/util.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  /**
2
- * Expand source file/glob into a list of paths
2
+ * Expand file/glob into a list of paths
3
3
  *
4
4
  * @param {*} source the source file/glob
5
5
  * @returns {Promise<string[]>} an array of paths
6
6
  */
7
- export function expandSource(source: any): Promise<string[]>;
7
+ export function expand(source: any): Promise<string[]>;
8
8
  /**
9
9
  * Check if a file/folder exists
10
10
  * @param {string} path the path to the file/folder
@@ -20,9 +20,11 @@ export function installed(pkg: string): Promise<boolean>;
20
20
  /**
21
21
  * Description
22
22
  * @param {string} pattern glob pattern(s) to match
23
+ * @param {string} root root path where the matcher runs from
24
+ * @param {string} ignore glob of pattern(s) to ignore
23
25
  * @returns {Promise<string[]>} an array of paths
24
26
  */
25
- export function match(pattern: string): Promise<string[]>;
27
+ export function match(pattern: string, root?: string, ignore?: string): Promise<string[]>;
26
28
  /**
27
29
  * Check to see if an application is installed globally
28
30
  * @param {string} program the name of the application
package/src/util.js CHANGED
@@ -5,24 +5,24 @@ import { promisify } from 'node:util'
5
5
  const execAsync = promisify(exec)
6
6
 
7
7
  /**
8
- * Expand source file/glob into a list of paths
8
+ * Expand file/glob into a list of paths
9
9
  *
10
10
  * @param {*} source the source file/glob
11
11
  * @returns {Promise<string[]>} an array of paths
12
12
  */
13
- export async function expandSource (source) {
13
+ export async function expand (source) {
14
14
  const isGlob = source.includes('*')
15
15
  if (isGlob) {
16
16
  const paths = await match(source)
17
17
  if (paths.length === 0) {
18
- console.error(`cp: ${source} no matches found`)
18
+ console.error(`${source} no matches found`)
19
19
  process.exit(1)
20
20
  }
21
21
  return paths
22
22
  } else {
23
23
  const exists = await fileExists(source)
24
24
  if (!exists) {
25
- console.error(`cp: ${source} No such file or directory`)
25
+ console.error(`${source} No such file or directory`)
26
26
  process.exit(1)
27
27
  }
28
28
  return [source]
@@ -60,10 +60,13 @@ export async function installed (pkg) {
60
60
  /**
61
61
  * Description
62
62
  * @param {string} pattern glob pattern(s) to match
63
+ * @param {string} root root path where the matcher runs from
64
+ * @param {string} ignore glob of pattern(s) to ignore
63
65
  * @returns {Promise<string[]>} an array of paths
64
66
  */
65
- export async function match (pattern) {
66
- return await Array.fromAsync(glob(pattern))
67
+ export async function match (pattern, root = process.cwd(), ignore = '') {
68
+ const ignores = ignore.includes(',') ? [ignore] : ignore.split(',')
69
+ return await Array.fromAsync(glob(pattern, { cwd: root, exclude: ignores }))
67
70
  }
68
71
 
69
72
  /**