@vanillaes/esmtk 0.6.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.
@@ -0,0 +1,44 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "name": "CopyFileToFile",
9
+ "type": "node",
10
+ "request": "launch",
11
+ "skipFiles": [
12
+ "<node_internals>/**"
13
+ ],
14
+ "program": "${workspaceFolder}/bin/esmtk.js",
15
+ "cwd": "${workspaceFolder}",
16
+ "args": ["cp", "./test/cp/test1.txt", "./test/cp2/test1.txt"],
17
+ "console": "integratedTerminal",
18
+ },
19
+ {
20
+ "name": "CopyFileToFolder",
21
+ "type": "node",
22
+ "request": "launch",
23
+ "skipFiles": [
24
+ "<node_internals>/**"
25
+ ],
26
+ "program": "${workspaceFolder}/bin/esmtk.js",
27
+ "cwd": "${workspaceFolder}",
28
+ "args": ["cp", "./test/cp/test1.txt", "./test/cp2"],
29
+ "console": "integratedTerminal",
30
+ },
31
+ {
32
+ "name": "CopyFolderRecursively",
33
+ "type": "node",
34
+ "request": "launch",
35
+ "skipFiles": [
36
+ "<node_internals>/**"
37
+ ],
38
+ "program": "${workspaceFolder}/bin/esmtk.js",
39
+ "cwd": "${workspaceFolder}",
40
+ "args": ["cp", "-r", "./test/cp/", "./test/cp2"],
41
+ "console": "integratedTerminal",
42
+ }
43
+ ]
44
+ }
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright 2020 Evan Plaice
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,96 @@
1
+ <h1 align="center">ES Module Toolkit</h1>
2
+
3
+ ESMTK, essential tools and libs for ES module development
4
+
5
+ <div align="center">
6
+ <a href="https://github.com/vanillaes/esmtk/releases"><img src="https://badgen.net/github/tag/vanillaes/esmtk" alt="GitHub Release"></a>
7
+ <a href="https://www.npmjs.com/package/esmtk"><img src="https://badgen.net/npm/v/esmtk" alt="NPM Releases"></a>
8
+ <a href="https://github.com/vanillaes/esmtk/actions"><img src="https://github.com/vanillaes/esmtk/workflows/Latest/badge.svg" alt="Latest Status"></a>
9
+ <a href="https://github.com/vanillaes/esmtk/actions"><img src="https://github.com/vanillaes/esmtk/workflows/Release/badge.svg" alt="Release Status"></a>
10
+ </div>
11
+
12
+ ## Lint
13
+
14
+ Lint uses StandardJS to lint the source
15
+
16
+ ### Arguments
17
+
18
+ `esmtk lint [--fix]`
19
+
20
+ - `--fix` - automatically fix problems
21
+
22
+ ### Usage
23
+
24
+ ```sh
25
+ esmtk lint
26
+ ```
27
+
28
+ ## Bundle
29
+
30
+ Bundle uses ESBuild to compile an ES module (and its deps) into a bundle
31
+
32
+ ### Arguments
33
+
34
+ `esmtk bundle [input] [output]`
35
+
36
+ - `[input]` - the input source file path
37
+ - `[output]` - the output bundle file path
38
+
39
+ ### Usage
40
+
41
+ ```sh
42
+ esmtk bundle src/sample.js bundle.js
43
+ ```
44
+
45
+ ## Minify
46
+
47
+ Minify uses ESBuild to compile an ES module (and its deps) into a minified bundle
48
+
49
+ ### Arguments
50
+
51
+ `esmtk minify [input] [output]`
52
+
53
+ - `[input]` - the input source file path
54
+ - `[output]` - the output bundle file path
55
+
56
+ ### Usage
57
+
58
+ ```sh
59
+ esmtk minify src/sample.js bundle.min.js
60
+ ```
61
+
62
+ ## CommonJS
63
+
64
+ CommonJS uses ESBuild to compile an ES module (and its deps) into a CommonJS bundle
65
+
66
+ ### Arguments
67
+
68
+ `esmtk commonjs [input] [output]`
69
+
70
+ - `[input]` - the input source file path
71
+ - `[output]` - the output bundle file path
72
+
73
+ ### Usage
74
+
75
+ ```sh
76
+ esmtk commonjs src/sample.js bundle.cjs
77
+ ```
78
+
79
+ ## Copy
80
+
81
+ Copy us a cross-platform clone of the `cp` command in Linux
82
+
83
+ ### Arguments
84
+
85
+ `esmtk cp -rf [source] [destination]`
86
+
87
+ - `[source]` - the source file/glob
88
+ - `[destination]` - the destination file/directory
89
+ - `-r, --recursive` - copy files/directories recursively
90
+ - `-f --force` - force overwrite existing files
91
+
92
+ ### Usage
93
+
94
+ ```sh
95
+ esmtk cp src/* dest/
96
+ ```
@@ -0,0 +1,13 @@
1
+ import { spawn } from 'child_process'
2
+ import { join } from 'path'
3
+
4
+ const BIN_PATH = join(process.cwd(), 'node_modules', '.bin', 'esbuild')
5
+
6
+ export async function bundle (input, output) {
7
+ spawn(BIN_PATH, ['--format=esm', '--bundle', input, `--outfile=${output}`], {
8
+ cwd: process.cwd(),
9
+ stdio: ['pipe', process.stdout, process.stderr]
10
+ }).on('error', err => {
11
+ console.error(err)
12
+ })
13
+ }
@@ -0,0 +1,13 @@
1
+ import { spawn } from 'child_process'
2
+ import { join } from 'path'
3
+
4
+ const BIN_PATH = join(process.cwd(), 'node_modules', '.bin', 'esbuild')
5
+
6
+ export async function commonjs (input, output) {
7
+ spawn(BIN_PATH, ['--format=cjs', '--bundle', input, `--outfile=${output}`], {
8
+ cwd: process.cwd(),
9
+ stdio: ['pipe', process.stdout, process.stderr]
10
+ }).on('error', err => {
11
+ console.error(err)
12
+ })
13
+ }
@@ -0,0 +1,97 @@
1
+ import { basename, dirname } from 'node:path'
2
+ import { access, constants, cp as nodeCp, stat } from 'node:fs/promises'
3
+
4
+ export async function cp (source, target, options) {
5
+ if (!options.recursive) {
6
+ await copyAsync(source, target, options.force)
7
+ }
8
+
9
+ if (options.recursive) {
10
+ await copyRecursiveAsync(source, target, options.force)
11
+ }
12
+ }
13
+
14
+ // copy a single file
15
+ async function copyAsync (source, target, force = false) {
16
+ const sExists = await fileExists(source)
17
+ if (!sExists) {
18
+ console.error(`cp: source ${source} does not exist`)
19
+ process.exit(1)
20
+ }
21
+ const sStats = await stat(source)
22
+ if (sStats.isSymbolicLink()) {
23
+ console.error(`cp: source ${source} is a sybolic link`)
24
+ process.exit(1)
25
+ }
26
+
27
+ const tDir = dirname(target)
28
+ const tDirExists = await fileExists(tDir)
29
+ if (!tDirExists) {
30
+ console.error(`cp: target directory ${tDir} does not exist`)
31
+ process.exit(1)
32
+ }
33
+
34
+ const tExists = await fileExists(target)
35
+ if (tExists) {
36
+ const tStats = await stat(target)
37
+ if (tStats.isSymbolicLink()) {
38
+ console.error(`cp: target ${target} is a sybolic link`)
39
+ process.exit(1)
40
+ }
41
+ if (tStats.isDirectory()) {
42
+ const sourceFile = basename(source)
43
+ target = target.endsWith('/') ? target.slice(0, -1) : target
44
+ target = `${target}/${sourceFile}`
45
+ }
46
+ }
47
+
48
+ try {
49
+ await nodeCp(source, target, { force })
50
+ } catch (err) {
51
+ console.error(`cp: error ${err.message}`)
52
+ }
53
+ }
54
+
55
+ // copy a directory recursively
56
+ async function copyRecursiveAsync (source, target, force = false) {
57
+ const sExists = await fileExists(source)
58
+ if (!sExists) {
59
+ console.error(`cp: source ${source} does not exist`)
60
+ process.exit(1)
61
+ }
62
+ const sStats = await stat(source)
63
+ if (sStats.isSymbolicLink()) {
64
+ console.error(`cp: source ${source} is a sybolic link`)
65
+ process.exit(1)
66
+ }
67
+
68
+ const tExists = await fileExists(target)
69
+ if (!tExists) {
70
+ console.error(`cp: target directory ${target} does not exist`)
71
+ process.exit(1)
72
+ }
73
+ const tStats = await stat(target)
74
+ if (tStats.isSymbolicLink()) {
75
+ console.error(`cp: target ${target} is a sybolic link`)
76
+ process.exit(1)
77
+ }
78
+ if (!tStats.isDirectory()) {
79
+ console.error(`cp: target ${target} is not a directory`)
80
+ process.exit(1)
81
+ }
82
+
83
+ try {
84
+ await nodeCp(source, target, { force, recursive: true })
85
+ } catch (err) {
86
+ console.error(`cp": error ${err.message}`)
87
+ }
88
+ }
89
+
90
+ async function fileExists (file) {
91
+ try {
92
+ await access(file, constants.F_OK)
93
+ return true
94
+ } catch (error) {
95
+ return false
96
+ }
97
+ }
@@ -0,0 +1,5 @@
1
+ export { bundle } from './bundle.js'
2
+ export { commonjs } from './commonjs.js'
3
+ export { cp } from './cp.js'
4
+ export { lint } from './lint.js'
5
+ export { minify } from './minify.js'
@@ -0,0 +1,13 @@
1
+ import { spawn } from 'child_process'
2
+ import { join } from 'path'
3
+
4
+ const BIN_PATH = join(process.cwd(), 'node_modules', '.bin', 'standard')
5
+
6
+ export async function lint (flags) {
7
+ spawn(BIN_PATH, flags, {
8
+ cwd: process.cwd(),
9
+ stdio: ['pipe', process.stdout, process.stderr]
10
+ }).on('error', err => {
11
+ console.error(err)
12
+ })
13
+ }
@@ -0,0 +1,13 @@
1
+ import { spawn } from 'child_process'
2
+ import { join } from 'path'
3
+
4
+ const BIN_PATH = join(process.cwd(), 'node_modules', '.bin', 'esbuild')
5
+
6
+ export async function minify (input, output) {
7
+ spawn(BIN_PATH, ['--format=esm', '--minify', '--bundle', input, `--outfile=${output}`], {
8
+ cwd: process.cwd(),
9
+ stdio: ['pipe', process.stdout, process.stderr]
10
+ }).on('error', err => {
11
+ console.error(err)
12
+ })
13
+ }
package/bin/esmtk.js ADDED
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env node
2
+ import { bundle, cp, commonjs, lint, minify } from './commands/index.js'
3
+ import { Command } from 'commander'
4
+ import { createRequire } from 'module'
5
+ const program = new Command()
6
+ const require = createRequire(import.meta.url)
7
+ const pkg = require('../package.json')
8
+
9
+ program.version(pkg.version, '-v, --version')
10
+
11
+ program.command('lint')
12
+ .description('Lint the source using StandardJS')
13
+ .option('--fix', 'Automatically fix problems')
14
+ .action(options => {
15
+ const flags = options.fix ? ['--fix'] : []
16
+ lint(flags)
17
+ })
18
+
19
+ program.command('bundle <input> <output>')
20
+ .description('Bundle the source using ESBuild')
21
+ .action((input, output) => {
22
+ bundle(input, output)
23
+ })
24
+
25
+ program.command('commonjs <input> <output>')
26
+ .description('Transpile the source to CommonJS using ESBuild')
27
+ .action((input, output) => {
28
+ commonjs(input, output)
29
+ })
30
+
31
+ program.command('minify <input> <output>')
32
+ .description('Minify the source using ESBuild')
33
+ .action((input, output) => {
34
+ minify(input, output)
35
+ })
36
+
37
+ program.command('cp <source> <target>')
38
+ .usage('[-rf] source target')
39
+ .description('Copy files from the source to the target')
40
+ .option('-f, --force', 'do not prompt before overwriting')
41
+ .option('-r, --recursive', 'copy directories recursively')
42
+ .action((source, target, options) => {
43
+ cp(source, target, options)
44
+ })
45
+
46
+ program.parse(process.argv)
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@vanillaes/esmtk",
3
+ "version": "0.6.3",
4
+ "description": "ES Module Toolkit",
5
+ "keywords": [
6
+ "esm",
7
+ "esmodules",
8
+ "nodejs",
9
+ "cli",
10
+ "developer-tools"
11
+ ],
12
+ "repository": "https://github.com/vanillaes/esmtk",
13
+ "author": "Evan Plaice <evanplaice@gmail.com> (https://evanplaice.com/)",
14
+ "license": "MIT",
15
+ "type": "module",
16
+ "bin": {
17
+ "esmtk": "bin/esmtk.js"
18
+ },
19
+ "scripts": {
20
+ "lint": "./bin/esmtk.js lint",
21
+ "preversion": "npm run lint",
22
+ "postversion": "git push --follow-tags"
23
+ },
24
+ "dependencies": {
25
+ "commander": "^14.0.3",
26
+ "esbuild": "^0.13.13",
27
+ "glob": "^13.0.6",
28
+ "standard": "^17.1.2"
29
+ },
30
+ "engines": {
31
+ "node": ">=17"
32
+ }
33
+ }