@vanillaes/esmtk 0.17.1 → 0.19.0
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/.vscode/launch.json +25 -1
- package/README.md +9 -4
- package/bin/commands/clean.js +4 -0
- package/bin/commands/cp.js +0 -1
- package/bin/commands/index.js +1 -0
- package/bin/commands/init.js +133 -0
- package/bin/esmtk.js +12 -4
- package/package.json +2 -2
package/.vscode/launch.json
CHANGED
|
@@ -13,6 +13,18 @@
|
|
|
13
13
|
"args": ["--version"],
|
|
14
14
|
"console": "integratedTerminal",
|
|
15
15
|
},
|
|
16
|
+
{
|
|
17
|
+
"name": "Init",
|
|
18
|
+
"type": "node",
|
|
19
|
+
"request": "launch",
|
|
20
|
+
"skipFiles": [
|
|
21
|
+
"<node_internals>/**"
|
|
22
|
+
],
|
|
23
|
+
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
24
|
+
"cwd": "${workspaceFolder}",
|
|
25
|
+
"args": ["init"],
|
|
26
|
+
"console": "integratedTerminal",
|
|
27
|
+
},
|
|
16
28
|
{
|
|
17
29
|
"name": "Lint",
|
|
18
30
|
"type": "node",
|
|
@@ -408,6 +420,18 @@
|
|
|
408
420
|
"cwd": "${workspaceFolder}",
|
|
409
421
|
"args": ["clean", "--bundle", "--minify", "--typings"],
|
|
410
422
|
"console": "integratedTerminal",
|
|
411
|
-
}
|
|
423
|
+
},
|
|
424
|
+
{
|
|
425
|
+
"name": "Clean --custom",
|
|
426
|
+
"type": "node",
|
|
427
|
+
"request": "launch",
|
|
428
|
+
"skipFiles": [
|
|
429
|
+
"<node_internals>/**"
|
|
430
|
+
],
|
|
431
|
+
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
432
|
+
"cwd": "${workspaceFolder}",
|
|
433
|
+
"args": ["clean", "--custom", "**/*.min.js"],
|
|
434
|
+
"console": "integratedTerminal",
|
|
435
|
+
},
|
|
412
436
|
]
|
|
413
437
|
}
|
package/README.md
CHANGED
|
@@ -4,7 +4,8 @@ ESMTK, essential tools for ECMAScript module development
|
|
|
4
4
|
|
|
5
5
|
<div align="center">
|
|
6
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/@vanillaes/esmtk"><img src="https://badgen.net/npm/v/@vanillaes/esmtk" alt="NPM
|
|
7
|
+
<a href="https://www.npmjs.com/package/@vanillaes/esmtk"><img src="https://badgen.net/npm/v/@vanillaes/esmtk?icon=npm" alt="NPM Version"></a>
|
|
8
|
+
<a href="https://www.npmjs.com/package/@vanillaes/esmtk"><img src="https://badgen.net/npm/dm/@vanillaes/esmtk?icon=npm" alt="NPM Downloads"></a>
|
|
8
9
|
<a href="https://github.com/vanillaes/esmtk/actions"><img src="https://github.com/vanillaes/esmtk/workflows/Latest/badge.svg" alt="Latest Status"></a>
|
|
9
10
|
<a href="https://github.com/vanillaes/esmtk/actions"><img src="https://github.com/vanillaes/esmtk/workflows/Release/badge.svg" alt="Release Status"></a>
|
|
10
11
|
</div>
|
|
@@ -148,9 +149,10 @@ Clean up build artifacts
|
|
|
148
149
|
`esmtk clean [root]`
|
|
149
150
|
|
|
150
151
|
- `[root]` - the root directory to perform the cleanup (default: `process.cwd()`)
|
|
151
|
-
- `--bundle` - Clean bundled build artifacts (default:
|
|
152
|
-
- `--minify` - Clean minified build artifacts (default:
|
|
153
|
-
- `--typings` - Clean typing artifacts (default:
|
|
152
|
+
- `--bundle` - Clean bundled build artifacts (default: `**/*.esm.js`)
|
|
153
|
+
- `--minify` - Clean minified build artifacts (default: `**/*.min.js`)
|
|
154
|
+
- `--typings` - Clean typing artifacts (default: `**/*.d.ts`)
|
|
155
|
+
- `--custom` - Clean based on a user-defined pattern
|
|
154
156
|
|
|
155
157
|
### Usage
|
|
156
158
|
|
|
@@ -160,6 +162,9 @@ esmtk clean --bundle --minify --typings
|
|
|
160
162
|
|
|
161
163
|
# override default extension
|
|
162
164
|
esmtk clean --bundle *.mjs
|
|
165
|
+
|
|
166
|
+
# define your own pattern
|
|
167
|
+
esmtk clean --custom *.scss.css
|
|
163
168
|
```
|
|
164
169
|
|
|
165
170
|
**Node: The `clean` command automatically ignores the contents of `node_modules/`**
|
package/bin/commands/clean.js
CHANGED
|
@@ -24,6 +24,10 @@ export async function clean (root, options) {
|
|
|
24
24
|
if (options?.typings) {
|
|
25
25
|
await cleanOne(root, options.typings, options)
|
|
26
26
|
}
|
|
27
|
+
|
|
28
|
+
if (options?.custom) {
|
|
29
|
+
await cleanOne(root, options.custom, options)
|
|
30
|
+
}
|
|
27
31
|
}
|
|
28
32
|
|
|
29
33
|
async function cleanOne (root, glob, options) {
|
package/bin/commands/cp.js
CHANGED
package/bin/commands/index.js
CHANGED
|
@@ -2,6 +2,7 @@ export { bundle } from './bundle.js'
|
|
|
2
2
|
export { clean } from './clean.js'
|
|
3
3
|
export { commonjs } from './commonjs.js'
|
|
4
4
|
export { cp } from './cp.js'
|
|
5
|
+
export { init } from './init.js'
|
|
5
6
|
export { lint } from './lint.js'
|
|
6
7
|
export { minify } from './minify.js'
|
|
7
8
|
export { rm } from './rm.js'
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { fileExists, which } from '../../src/index.js'
|
|
2
|
+
import { exec } from 'node:child_process'
|
|
3
|
+
import { readFile, writeFile } from 'node:fs/promises'
|
|
4
|
+
import { basename, join, sep } from 'node:path'
|
|
5
|
+
import { stdin, stdout } from 'node:process'
|
|
6
|
+
import { createInterface } from 'node:readline/promises'
|
|
7
|
+
import { promisify } from 'node:util'
|
|
8
|
+
|
|
9
|
+
const execAsync = promisify(exec)
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Create a package.json file for ECMAScript Development
|
|
13
|
+
*/
|
|
14
|
+
export async function init () {
|
|
15
|
+
const npmExists = await which('npm')
|
|
16
|
+
if (!npmExists) {
|
|
17
|
+
console.error('npm not found')
|
|
18
|
+
console.error('is node installed?')
|
|
19
|
+
process.exit(1)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const gitExists = await which('git')
|
|
23
|
+
if (!gitExists) {
|
|
24
|
+
console.error('git not found')
|
|
25
|
+
console.error('is git installed?')
|
|
26
|
+
process.exit(1)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// defaults
|
|
30
|
+
const DIR = process.cwd()
|
|
31
|
+
const DIRNAME = basename(process.cwd())
|
|
32
|
+
const REPOSITORY = await getGitRepository()
|
|
33
|
+
const USERNAME = gitExists ? await fetchGitUser() : ''
|
|
34
|
+
const EMAIL = gitExists ? await fetchGitEmail() : ''
|
|
35
|
+
|
|
36
|
+
const program = createInterface({ input: stdin, output: stdout })
|
|
37
|
+
|
|
38
|
+
console.log('This utility will walk you through creating a package.json file.')
|
|
39
|
+
console.log('It only covers the most common items, and tries to guess sensible defaults.')
|
|
40
|
+
console.log()
|
|
41
|
+
console.log('Press ^C at any time to quit.')
|
|
42
|
+
console.log()
|
|
43
|
+
|
|
44
|
+
const pkg = {}
|
|
45
|
+
pkg.name = await ask(program, 'package name', DIRNAME)
|
|
46
|
+
pkg.version = await ask(program, 'version', '0.0.0')
|
|
47
|
+
pkg.description = await ask(program, 'description')
|
|
48
|
+
let keywords = await ask(program, 'keywords')
|
|
49
|
+
if (keywords) {
|
|
50
|
+
keywords = keywords.split(' ')
|
|
51
|
+
pkg.keywords = keywords
|
|
52
|
+
}
|
|
53
|
+
pkg.repository = await ask(program, 'git repository', REPOSITORY)
|
|
54
|
+
const user = await ask(program, 'author', USERNAME)
|
|
55
|
+
if (user !== '') {
|
|
56
|
+
pkg.author = user
|
|
57
|
+
const email = await ask(program, 'email', EMAIL)
|
|
58
|
+
if (email !== '') {
|
|
59
|
+
pkg.author += ` <${EMAIL}>`
|
|
60
|
+
}
|
|
61
|
+
const website = await ask(program, 'website')
|
|
62
|
+
if (website) {
|
|
63
|
+
pkg.author += ` (${website})`
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
pkg.license = await ask(program, 'license', 'ISC')
|
|
67
|
+
pkg.type = 'module'
|
|
68
|
+
const entry = await ask(program, 'entry point', 'index.js')
|
|
69
|
+
if (entry) {
|
|
70
|
+
pkg.exports = {}
|
|
71
|
+
pkg.exports['.'] = 'entry'
|
|
72
|
+
}
|
|
73
|
+
const scripts = await ask(program, 'include ESMTK scripts?', 'yes')
|
|
74
|
+
if (scripts.toLowerCase() === 'yes') {
|
|
75
|
+
pkg.scripts = {}
|
|
76
|
+
pkg.scripts.test = 'esmtk test'
|
|
77
|
+
pkg.scripts.lint = 'esmtk lint'
|
|
78
|
+
pkg.scripts.types = `esmtk types ${entry}`
|
|
79
|
+
} else {
|
|
80
|
+
pkg.scripts = {}
|
|
81
|
+
pkg.scripts.test = await ask(program, 'test command')
|
|
82
|
+
}
|
|
83
|
+
const pkgString = JSON.stringify(pkg, null, 2)
|
|
84
|
+
console.log(`About to write to ${DIR}${sep}package.json:`)
|
|
85
|
+
console.log(pkgString)
|
|
86
|
+
|
|
87
|
+
const ok = await ask(program, 'is this OK', 'yes')
|
|
88
|
+
if (ok.toLowerCase() === 'yes') {
|
|
89
|
+
await writeFile('package.test.json', pkgString)
|
|
90
|
+
} else {
|
|
91
|
+
console.log('Aborted.')
|
|
92
|
+
}
|
|
93
|
+
program.close()
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async function ask (program, prompt, defaultValue) {
|
|
97
|
+
const suffix = defaultValue ? `(${defaultValue}) ` : ''
|
|
98
|
+
const answer = await program.question(`${prompt}: ${suffix}`)
|
|
99
|
+
return answer || defaultValue
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async function fetchGitUser () {
|
|
103
|
+
const { stdout, stderr } = await execAsync('git config --get user.name')
|
|
104
|
+
if (stderr) {
|
|
105
|
+
console.error(`exec error: ${stderr}`)
|
|
106
|
+
process.exit(1)
|
|
107
|
+
}
|
|
108
|
+
console.log(`${stdout}`.trim())
|
|
109
|
+
return `${stdout}`.trim()
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async function fetchGitEmail () {
|
|
113
|
+
const { stdout, stderr } = await execAsync('git config --get user.email')
|
|
114
|
+
if (stderr) {
|
|
115
|
+
console.error(`exec error: ${stderr}`)
|
|
116
|
+
process.exit(1)
|
|
117
|
+
}
|
|
118
|
+
console.log(`${stdout}`.trim())
|
|
119
|
+
return `${stdout}`.trim()
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async function getGitRepository () {
|
|
123
|
+
const config = join(process.cwd(), '.git', 'config')
|
|
124
|
+
const exists = await fileExists(config)
|
|
125
|
+
if (!exists) {
|
|
126
|
+
return
|
|
127
|
+
}
|
|
128
|
+
const contents = await readFile(config, 'utf-8')
|
|
129
|
+
const match = contents.match(/^\turl\s=\shttps:\/\/.*$/gm)
|
|
130
|
+
if (match) {
|
|
131
|
+
return match[0].replace('\turl = ', '')
|
|
132
|
+
}
|
|
133
|
+
}
|
package/bin/esmtk.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { bundle, clean, cp, commonjs, lint, minify, rm, types, typings } from './commands/index.js'
|
|
2
|
+
import { bundle, clean, cp, commonjs, init, 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()
|
|
@@ -8,6 +8,12 @@ const pkg = require('../package.json')
|
|
|
8
8
|
|
|
9
9
|
program.version(pkg.version, '-v, --version')
|
|
10
10
|
|
|
11
|
+
program.command('init')
|
|
12
|
+
.description('Create a package.json file for ECMAScript module development')
|
|
13
|
+
.action(() => {
|
|
14
|
+
init()
|
|
15
|
+
})
|
|
16
|
+
|
|
11
17
|
program.command('lint')
|
|
12
18
|
.description('Lint the source using StandardJS')
|
|
13
19
|
.option('--fix', 'Automatically fix problems')
|
|
@@ -54,9 +60,10 @@ program.command('minify <input> <output>')
|
|
|
54
60
|
program.command('clean')
|
|
55
61
|
.description('Clean build artificts')
|
|
56
62
|
.argument('[root]', 'The root directory to perform operations from (default cwd)', process.cwd())
|
|
57
|
-
.option('--bundle [bundle]', 'Clean bundled build artifacts (default:
|
|
58
|
-
.option('--minify [minify]', 'Clean minified build artifacts (default:
|
|
59
|
-
.option('--typings [typings]', 'Clean typing artifacts (default:
|
|
63
|
+
.option('--bundle [bundle]', 'Clean bundled build artifacts (default: **/*.esm.js)')
|
|
64
|
+
.option('--minify [minify]', 'Clean minified build artifacts (default: **/*.min.js)')
|
|
65
|
+
.option('--typings [typings]', 'Clean typing artifacts (default: **/*.d.ts)')
|
|
66
|
+
.option('--custom <custom>', 'Clean based on a user-defined pattern')
|
|
60
67
|
// .option('-f, --force', 'Do not prompt before overwriting', false)
|
|
61
68
|
.action((root, options) => {
|
|
62
69
|
// set --bundle default
|
|
@@ -71,6 +78,7 @@ program.command('clean')
|
|
|
71
78
|
if (options?.typings && typeof (options.typings) === 'boolean') {
|
|
72
79
|
options.typings = '**/*.d.ts'
|
|
73
80
|
}
|
|
81
|
+
|
|
74
82
|
clean(root, options)
|
|
75
83
|
})
|
|
76
84
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vanillaes/esmtk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "ES Module Toolkit",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ecmascript",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"bundle": "./bin/esmtk.js bundle --platform=node src/index.js src/index.esm.js",
|
|
43
43
|
"minify": "./bin/esmtk.js minify --platform=node src/index.js src/index.min.js",
|
|
44
44
|
"typings": "./bin/esmtk.js typings src/index.js",
|
|
45
|
-
"clean": "./bin/esmtk.js clean --
|
|
45
|
+
"clean": "./bin/esmtk.js clean --typings",
|
|
46
46
|
"preversion": "npm run lint && npm run types",
|
|
47
47
|
"postversion": "git push --follow-tags"
|
|
48
48
|
},
|