@vanillaes/esmtk 0.18.0 → 0.19.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.
@@ -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",
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 Releases"></a>
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>
@@ -3,7 +3,6 @@ import { expand } from '../../src/index.js'
3
3
 
4
4
  /**
5
5
  * POSIX cp Implemented in Node
6
- *
7
6
  * @param {string[]} paths Variadic of source/destination paths
8
7
  * @param {any} options 'cp' options
9
8
  */
@@ -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.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')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vanillaes/esmtk",
3
- "version": "0.18.0",
3
+ "version": "0.19.1",
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 --bundle --minify --typings",
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
  },