@vanillaes/esmtk 0.7.3 → 0.9.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 +12 -0
- package/README.md +16 -0
- package/bin/commands/bundle.js +1 -1
- package/bin/commands/commonjs.js +1 -1
- package/bin/commands/index.js +1 -0
- package/bin/commands/minify.js +1 -1
- package/bin/commands/types.js +1 -1
- package/bin/commands/typings.js +29 -0
- package/bin/esmtk.js +7 -1
- package/package.json +14 -4
- package/src/cp.d.ts +14 -0
- package/src/cp.js +2 -10
- package/src/index.d.ts +3 -0
- package/src/index.js +1 -0
- package/src/rm.d.ts +12 -0
- package/src/rm.js +2 -10
- package/src/util.d.ts +18 -0
- package/src/util.js +17 -2
package/.vscode/launch.json
CHANGED
|
@@ -25,6 +25,18 @@
|
|
|
25
25
|
"args": ["types", "./test/index.js"],
|
|
26
26
|
"console": "integratedTerminal",
|
|
27
27
|
},
|
|
28
|
+
{
|
|
29
|
+
"name": "Typings",
|
|
30
|
+
"type": "node",
|
|
31
|
+
"request": "launch",
|
|
32
|
+
"skipFiles": [
|
|
33
|
+
"<node_internals>/**"
|
|
34
|
+
],
|
|
35
|
+
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
36
|
+
"cwd": "${workspaceFolder}",
|
|
37
|
+
"args": ["typings", "./test/index.js"],
|
|
38
|
+
"console": "integratedTerminal",
|
|
39
|
+
},
|
|
28
40
|
{
|
|
29
41
|
"name": "CopyFileToFile",
|
|
30
42
|
"type": "node",
|
package/README.md
CHANGED
|
@@ -41,6 +41,22 @@ Type check the JSDoc typings (using Typescript)
|
|
|
41
41
|
esmtk types index.js
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
+
## Typings
|
|
45
|
+
|
|
46
|
+
Generate Type Declarations (.d.ts) from JSDoc (using Typescript)
|
|
47
|
+
|
|
48
|
+
### Arguments
|
|
49
|
+
|
|
50
|
+
`esmtk typings index.js`
|
|
51
|
+
|
|
52
|
+
- `[entry]` - the entry-point for the source
|
|
53
|
+
|
|
54
|
+
### Usage
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
esmtk typings index.js
|
|
58
|
+
```
|
|
59
|
+
|
|
44
60
|
## Bundle
|
|
45
61
|
|
|
46
62
|
Bundle the source code to an ECMAScript module (using ESBuild)
|
package/bin/commands/bundle.js
CHANGED
package/bin/commands/commonjs.js
CHANGED
package/bin/commands/index.js
CHANGED
package/bin/commands/minify.js
CHANGED
package/bin/commands/types.js
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { installed, which } from '../../src/index.js'
|
|
2
|
+
import { spawn } from 'child_process'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Generate Typescript typings from JSDoc
|
|
6
|
+
* @param {string} entry the entry point
|
|
7
|
+
*/
|
|
8
|
+
export async function typings (entry) {
|
|
9
|
+
const npmExists = await which('npm')
|
|
10
|
+
if (!npmExists) {
|
|
11
|
+
console.error('npm not found')
|
|
12
|
+
console.error('is node installed?')
|
|
13
|
+
process.exit(1)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const esbuildExists = await installed('typescript')
|
|
17
|
+
if (!esbuildExists) {
|
|
18
|
+
console.error('typescript not found')
|
|
19
|
+
console.error('typescript can be installed with `npm i -g typescript`')
|
|
20
|
+
process.exit(1)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
spawn('tsc', [entry, '-t', 'esnext', '--allowJS', '--checkJS', '--skipLibCheck', '--declaration', '--emitDeclarationOnly', '--noEmitOnError'], {
|
|
24
|
+
cwd: process.cwd(),
|
|
25
|
+
stdio: ['pipe', process.stdout, process.stderr]
|
|
26
|
+
}).on('error', err => {
|
|
27
|
+
console.error(err)
|
|
28
|
+
})
|
|
29
|
+
}
|
package/bin/esmtk.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { bundle, cp, commonjs, lint, minify, rm, types } from './commands/index.js'
|
|
2
|
+
import { bundle, 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()
|
|
@@ -22,6 +22,12 @@ program.command('types <entry>')
|
|
|
22
22
|
types(entry)
|
|
23
23
|
})
|
|
24
24
|
|
|
25
|
+
program.command('typings <entry>')
|
|
26
|
+
.description('Generate typings from JSDoc using Typescript')
|
|
27
|
+
.action((entry) => {
|
|
28
|
+
typings(entry)
|
|
29
|
+
})
|
|
30
|
+
|
|
25
31
|
program.command('bundle <input> <output>')
|
|
26
32
|
.description('Bundle the source using ESBuild')
|
|
27
33
|
.action((input, output) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vanillaes/esmtk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "ES Module Toolkit",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"esm",
|
|
@@ -14,9 +14,18 @@
|
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"type": "module",
|
|
16
16
|
"exports": {
|
|
17
|
-
".":
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./src/index.d.ts",
|
|
19
|
+
"default": "./src/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./cp": {
|
|
22
|
+
"types": "./src/cp.d.ts",
|
|
23
|
+
"default": "./src/cp.js"
|
|
24
|
+
},
|
|
25
|
+
"./rm": {
|
|
26
|
+
"types": "./src/rm.d.ts",
|
|
27
|
+
"default": "./src/rm.js"
|
|
28
|
+
}
|
|
20
29
|
},
|
|
21
30
|
"bin": {
|
|
22
31
|
"esmtk": "bin/esmtk.js"
|
|
@@ -24,6 +33,7 @@
|
|
|
24
33
|
"scripts": {
|
|
25
34
|
"lint": "./bin/esmtk.js lint",
|
|
26
35
|
"types": "./bin/esmtk.js types src/index.js",
|
|
36
|
+
"typings": "./bin/esmtk.js typings src/index.js",
|
|
27
37
|
"preversion": "npm run lint && npm run types",
|
|
28
38
|
"postversion": "git push --follow-tags"
|
|
29
39
|
},
|
package/src/cp.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copy a single file asynchronously
|
|
3
|
+
* @param {string} source The source file
|
|
4
|
+
* @param {string} target The target file
|
|
5
|
+
* @param {boolean} force If the file already exists, overwrite it (default false)
|
|
6
|
+
*/
|
|
7
|
+
export function copyAsync(source: string, target: string, force?: boolean): Promise<void>;
|
|
8
|
+
/**
|
|
9
|
+
* Recursively copy a directory asynchronously
|
|
10
|
+
* @param {string} source The source directory
|
|
11
|
+
* @param {string} target The target directory
|
|
12
|
+
* @param {boolean} force If the file already exists, overwrite it (default false)
|
|
13
|
+
*/
|
|
14
|
+
export function copyRecursiveAsync(source: string, target: string, force?: boolean): Promise<void>;
|
package/src/cp.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { fileExists } from './index.js'
|
|
1
2
|
import { basename, dirname } from 'node:path'
|
|
2
|
-
import {
|
|
3
|
+
import { cp, stat } from 'node:fs/promises'
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Copy a single file asynchronously
|
|
@@ -86,12 +87,3 @@ export async function copyRecursiveAsync (source, target, force = false) {
|
|
|
86
87
|
console.error(`cp": error ${err.message}`)
|
|
87
88
|
}
|
|
88
89
|
}
|
|
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
|
-
}
|
package/src/index.d.ts
ADDED
package/src/index.js
CHANGED
package/src/rm.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remove a file asynchronously
|
|
3
|
+
* @param {string} path The file to delete
|
|
4
|
+
* @param {boolean} force Ignore exceptions if the file doesn't exist (default false)
|
|
5
|
+
*/
|
|
6
|
+
export function removeAsync(path: string, force?: boolean): Promise<void>;
|
|
7
|
+
/**
|
|
8
|
+
* Recursively remove a file|directory asynchronously
|
|
9
|
+
* @param {string} path The file|directory to remove
|
|
10
|
+
* @param {boolean} force Ignore exceptions if the file|directory doesn't exist (default false)
|
|
11
|
+
*/
|
|
12
|
+
export function removeRecursiveAsync(path: string, force?: boolean): Promise<void>;
|
package/src/rm.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { fileExists } from './index.js'
|
|
2
|
+
import { rm, stat } from 'node:fs/promises'
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Remove a file asynchronously
|
|
@@ -47,12 +48,3 @@ export async function removeRecursiveAsync (path, force = false) {
|
|
|
47
48
|
console.error(`rm": error ${err.message}`)
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
|
-
|
|
51
|
-
async function fileExists (file) {
|
|
52
|
-
try {
|
|
53
|
-
await access(file, constants.F_OK)
|
|
54
|
-
return true
|
|
55
|
-
} catch (error) {
|
|
56
|
-
return false
|
|
57
|
-
}
|
|
58
|
-
}
|
package/src/util.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if a file/folder exists
|
|
3
|
+
* @param {string} path the path to the file/folder
|
|
4
|
+
* @returns {Promise<boolean>} trie if the file/folder exists, false otherwise
|
|
5
|
+
*/
|
|
6
|
+
export function fileExists(path: string): Promise<boolean>;
|
|
7
|
+
/**
|
|
8
|
+
* Check to see if a NPM package is installed globally
|
|
9
|
+
* @param {string} pkg the name of the package
|
|
10
|
+
* @returns {Promise<boolean>} true if the package is installed, false otherwise
|
|
11
|
+
*/
|
|
12
|
+
export function installed(pkg: string): Promise<boolean>;
|
|
13
|
+
/**
|
|
14
|
+
* Check to see if an application is installed globally
|
|
15
|
+
* @param {string} program the name of the application
|
|
16
|
+
* @returns {Promise<boolean>} true if the application is installed, false otherwise
|
|
17
|
+
*/
|
|
18
|
+
export function which(program: string): Promise<boolean>;
|
package/src/util.js
CHANGED
|
@@ -1,12 +1,27 @@
|
|
|
1
1
|
import { exec } from 'child_process'
|
|
2
|
+
import { access, constants } from 'node:fs/promises'
|
|
2
3
|
import { promisify } from 'node:util'
|
|
3
4
|
|
|
4
5
|
const execAsync = promisify(exec)
|
|
5
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Check if a file/folder exists
|
|
9
|
+
* @param {string} path the path to the file/folder
|
|
10
|
+
* @returns {Promise<boolean>} trie if the file/folder exists, false otherwise
|
|
11
|
+
*/
|
|
12
|
+
export async function fileExists (path) {
|
|
13
|
+
try {
|
|
14
|
+
await access(path, constants.F_OK)
|
|
15
|
+
return true
|
|
16
|
+
} catch (error) {
|
|
17
|
+
return false
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
6
21
|
/**
|
|
7
22
|
* Check to see if a NPM package is installed globally
|
|
8
23
|
* @param {string} pkg the name of the package
|
|
9
|
-
* @returns {boolean} true if the package is installed, false otherwise
|
|
24
|
+
* @returns {Promise<boolean>} true if the package is installed, false otherwise
|
|
10
25
|
*/
|
|
11
26
|
export async function installed (pkg) {
|
|
12
27
|
try {
|
|
@@ -20,7 +35,7 @@ export async function installed (pkg) {
|
|
|
20
35
|
/**
|
|
21
36
|
* Check to see if an application is installed globally
|
|
22
37
|
* @param {string} program the name of the application
|
|
23
|
-
* @returns {boolean} true if the application is installed, false otherwise
|
|
38
|
+
* @returns {Promise<boolean>} true if the application is installed, false otherwise
|
|
24
39
|
*/
|
|
25
40
|
export async function which (program) {
|
|
26
41
|
try {
|