v-transform 2.2.0 → 2.2.2

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2021 神戸小鳥
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2021 神戸小鳥
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json CHANGED
@@ -4,8 +4,13 @@
4
4
  "vt": "src/index.js"
5
5
  },
6
6
  "type": "module",
7
- "version": "2.2.0",
7
+ "version": "2.2.2",
8
8
  "main": "index.js",
9
+ "scripts": {
10
+ "clean": "npx rimraf test",
11
+ "vt": "node src/index.js",
12
+ "transform": "node src/index.js transform"
13
+ },
9
14
  "repository": {
10
15
  "type": "git",
11
16
  "url": "git+https://github.com/VickScarlet/vTransform.git"
@@ -13,14 +18,9 @@
13
18
  "author": "Vick Scarlet <scarlet_vick@outlook.com>",
14
19
  "license": "MIT",
15
20
  "dependencies": {
16
- "commander": "^14.0.2",
17
- "glob": "^13.0.0",
18
- "js-yaml": "^4.1.1",
21
+ "commander": "^15.0.0",
22
+ "glob": "^13.0.6",
23
+ "js-yaml": "^5.2.0",
19
24
  "xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz"
20
- },
21
- "scripts": {
22
- "clean": "npx rimraf test",
23
- "vt": "node src/index.js",
24
- "transform": "node src/index.js transform"
25
25
  }
26
- }
26
+ }
package/src/dump.js CHANGED
@@ -1,66 +1,66 @@
1
- import yaml from 'js-yaml'
2
- import path from 'node:path'
3
- import { writeFile, stat, mkdir } from 'node:fs/promises'
4
-
5
- function jsonify(data, space) {
6
- return JSON.stringify(data, null, space)
7
- }
8
-
9
- function cjsify(data, space) {
10
- return `module.exports = ${jsonify(data, space)}`
11
- }
12
-
13
- function esmify(data, space) {
14
- return `export default ${jsonify(data, space)}`
15
- }
16
-
17
- function yamlify(data, space) {
18
- return yaml.dump(data, {
19
- indent: space || undefined,
20
- })
21
- }
22
-
23
- async function mkdirs(dir) {
24
- try {
25
- await stat(dir)
26
- } catch (e) {
27
- if (e.code !== 'ENOENT') {
28
- throw e
29
- }
30
- await mkdirs(path.dirname(dir))
31
- await mkdir(dir)
32
- }
33
- }
34
-
35
- async function write(sheet, data) {
36
- console.info(`Dump ${sheet}`)
37
- await mkdirs(path.dirname(sheet))
38
- await writeFile(sheet, data)
39
- }
40
-
41
- export async function dump(sheet, data, type, space) {
42
- let ext, ify
43
- switch (type) {
44
- case 'cjs':
45
- ext = '.js'
46
- ify = cjsify
47
- break
48
- case 'js':
49
- case 'mjs':
50
- case 'esm':
51
- ext = '.js'
52
- ify = esmify
53
- break
54
- case 'yaml':
55
- case 'yml':
56
- ext = '.yaml'
57
- ify = yamlify
58
- break
59
- case 'json':
60
- default:
61
- ext = '.json'
62
- ify = jsonify
63
- break
64
- }
65
- return write(`${sheet}${ext}`, ify(data, space))
66
- }
1
+ import yaml from 'js-yaml'
2
+ import path from 'node:path'
3
+ import { writeFile, stat, mkdir } from 'node:fs/promises'
4
+
5
+ function jsonify(data, space) {
6
+ return JSON.stringify(data, null, space)
7
+ }
8
+
9
+ function cjsify(data, space) {
10
+ return `module.exports = ${jsonify(data, space)}`
11
+ }
12
+
13
+ function esmify(data, space) {
14
+ return `export default ${jsonify(data, space)}`
15
+ }
16
+
17
+ function yamlify(data, space) {
18
+ return yaml.dump(data, {
19
+ indent: space || undefined,
20
+ })
21
+ }
22
+
23
+ async function mkdirs(dir) {
24
+ try {
25
+ await stat(dir)
26
+ } catch (e) {
27
+ if (e.code !== 'ENOENT') {
28
+ throw e
29
+ }
30
+ await mkdirs(path.dirname(dir))
31
+ await mkdir(dir)
32
+ }
33
+ }
34
+
35
+ async function write(sheet, data) {
36
+ console.info(`Dump ${sheet}`)
37
+ await mkdirs(path.dirname(sheet))
38
+ await writeFile(sheet, data)
39
+ }
40
+
41
+ export async function dump(sheet, data, type, space) {
42
+ let ext, ify
43
+ switch (type) {
44
+ case 'cjs':
45
+ ext = '.js'
46
+ ify = cjsify
47
+ break
48
+ case 'js':
49
+ case 'mjs':
50
+ case 'esm':
51
+ ext = '.js'
52
+ ify = esmify
53
+ break
54
+ case 'yaml':
55
+ case 'yml':
56
+ ext = '.yaml'
57
+ ify = yamlify
58
+ break
59
+ case 'json':
60
+ default:
61
+ ext = '.json'
62
+ ify = jsonify
63
+ break
64
+ }
65
+ return write(`${sheet}${ext}`, ify(data, space))
66
+ }
package/src/index.js CHANGED
@@ -1,29 +1,29 @@
1
- #!/usr/bin/env node
2
- import { Command } from 'commander'
3
- import { readFile } from 'node:fs/promises'
4
- import { transform } from './transform.js'
5
-
6
- const program = new Command()
7
-
8
- program.name('vt')
9
- program.version(JSON.parse(await readFile('package.json')).version)
10
- program
11
- .command('transform [list...]')
12
- .option(
13
- '-t, --type <type>',
14
- 'type of transform, available: js, esm, cjs, json',
15
- 'json',
16
- )
17
- .option('-s, --space <space>', 'format space number', 0)
18
- .option('-c, --config <config>', 'configure file', null)
19
- .option('-w, --cwd <cwd>', 'current work dir', null)
20
- .option('-o, --output <output>', 'output dir', null)
21
- .option('-d, --dest <dest>', 'dest dir', null)
22
- .option('-a, --addition', 'addition version', false)
23
- .action((list, options) => {
24
- if (!options.dest) options.dest = options.output
25
- options.list = list
26
- transform(options)
27
- })
28
-
29
- program.parse(process.argv)
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander'
3
+ import { readFile } from 'node:fs/promises'
4
+ import { transform } from './transform.js'
5
+
6
+ const program = new Command()
7
+
8
+ program.name('vt')
9
+ program.version(JSON.parse(await readFile('package.json')).version)
10
+ program
11
+ .command('transform [list...]')
12
+ .option(
13
+ '-t, --type <type>',
14
+ 'type of transform, available: js, esm, cjs, json',
15
+ 'json',
16
+ )
17
+ .option('-s, --space <space>', 'format space number', 0)
18
+ .option('-c, --config <config>', 'configure file', null)
19
+ .option('-w, --cwd <cwd>', 'current work dir', null)
20
+ .option('-o, --output <output>', 'output dir', null)
21
+ .option('-d, --dest <dest>', 'dest dir', null)
22
+ .option('-a, --addition', 'addition version', false)
23
+ .action((list, options) => {
24
+ if (!options.dest) options.dest = options.output
25
+ options.list = list
26
+ transform(options)
27
+ })
28
+
29
+ program.parse(process.argv)
package/src/loader.js CHANGED
@@ -1,72 +1,72 @@
1
- import { glob } from 'glob'
2
- import yaml from 'js-yaml'
3
- import path from 'node:path'
4
- import { readFile } from 'node:fs/promises'
5
-
6
- export async function load({ type, space, config, dest, list, cwd, addition }) {
7
- const version = new Date().toISOString()
8
- type = type || 'json'
9
- cwd = cwd || process.cwd()
10
- space = Number(space) || 0
11
- dest = dest || cwd
12
- const def = { cwd, type, space, dest, addition }
13
- const m = (...l) => globit(Object.assign({}, ...l))
14
- const cfgs = []
15
-
16
- if (list?.length) cfgs.unshift(await m(def, { glob: list }))
17
-
18
- if (config) {
19
- const cfgData = await loadConfigData(config, def, m)
20
- cfgs.push(...cfgData)
21
- }
22
-
23
- for (const cfg of cfgs) {
24
- if (cfg.addition) cfg.addition = { version, timestamp: version }
25
- }
26
-
27
- return cfgs
28
- }
29
-
30
- async function loadConfigData(config, def, m) {
31
- const c = await loadConfig(config)
32
- const dir = path.dirname(config)
33
- const cdef = {}
34
- if (c.cwd) cdef.cwd = path.resolve(dir, c.cwd)
35
- if (c.type) cdef.type = c.type
36
- if (typeof c.space == 'number') cdef.space = c.space
37
- if (c.dest) cdef.dest = path.resolve(dir, c.dest)
38
- const cfgs = []
39
-
40
- for (const cfg of c.configurations) {
41
- if (cfg.cwd) cfg.cwd = path.resolve(dir, cfg.cwd)
42
- if (cfg.dest) cfg.dest = path.resolve(dir, cfg.dest)
43
- cfgs.push(await m(def, cdef, cfg))
44
- }
45
-
46
- return cfgs
47
- }
48
-
49
- async function loadConfig(config) {
50
- switch (path.extname(config)) {
51
- case '.json':
52
- case '.yaml':
53
- case '.yml':
54
- return yaml.load(await readFile(config))
55
- case '.js':
56
- case '.mjs':
57
- return (await import(config)).default
58
- default:
59
- throw new Error(`Unknown config file type: ${config}`)
60
- }
61
- }
62
-
63
- async function globit(options) {
64
- const { glob: gs, cwd } = options
65
- const files = []
66
- const g = p => glob(p, { cwd })
67
- if (Array.isArray(gs)) for (const p of gs) files.push(...(await g(p)))
68
- else if (typeof gs == 'string') files.push(...(await g(gs)))
69
- else throw new Error(`Unknown glob type: ${gs}`)
70
-
71
- return { ...options, files }
72
- }
1
+ import { glob } from 'glob'
2
+ import yaml from 'js-yaml'
3
+ import path from 'node:path'
4
+ import { readFile } from 'node:fs/promises'
5
+
6
+ export async function load({ type, space, config, dest, list, cwd, addition }) {
7
+ const version = new Date().toISOString()
8
+ type = type || 'json'
9
+ cwd = cwd || process.cwd()
10
+ space = Number(space) || 0
11
+ dest = dest || cwd
12
+ const def = { cwd, type, space, dest, addition }
13
+ const m = (...l) => globit(Object.assign({}, ...l))
14
+ const cfgs = []
15
+
16
+ if (list?.length) cfgs.unshift(await m(def, { glob: list }))
17
+
18
+ if (config) {
19
+ const cfgData = await loadConfigData(config, def, m)
20
+ cfgs.push(...cfgData)
21
+ }
22
+
23
+ for (const cfg of cfgs) {
24
+ if (cfg.addition) cfg.addition = { version, timestamp: version }
25
+ }
26
+
27
+ return cfgs
28
+ }
29
+
30
+ async function loadConfigData(config, def, m) {
31
+ const c = await loadConfig(config)
32
+ const dir = path.dirname(config)
33
+ const cdef = {}
34
+ if (c.cwd) cdef.cwd = path.resolve(dir, c.cwd)
35
+ if (c.type) cdef.type = c.type
36
+ if (typeof c.space == 'number') cdef.space = c.space
37
+ if (c.dest) cdef.dest = path.resolve(dir, c.dest)
38
+ const cfgs = []
39
+
40
+ for (const cfg of c.configurations) {
41
+ if (cfg.cwd) cfg.cwd = path.resolve(dir, cfg.cwd)
42
+ if (cfg.dest) cfg.dest = path.resolve(dir, cfg.dest)
43
+ cfgs.push(await m(def, cdef, cfg))
44
+ }
45
+
46
+ return cfgs
47
+ }
48
+
49
+ async function loadConfig(config) {
50
+ switch (path.extname(config)) {
51
+ case '.json':
52
+ case '.yaml':
53
+ case '.yml':
54
+ return yaml.load(await readFile(config))
55
+ case '.js':
56
+ case '.mjs':
57
+ return (await import(config)).default
58
+ default:
59
+ throw new Error(`Unknown config file type: ${config}`)
60
+ }
61
+ }
62
+
63
+ async function globit(options) {
64
+ const { glob: gs, cwd } = options
65
+ const files = []
66
+ const g = p => glob(p, { cwd })
67
+ if (Array.isArray(gs)) for (const p of gs) files.push(...(await g(p)))
68
+ else if (typeof gs == 'string') files.push(...(await g(gs)))
69
+ else throw new Error(`Unknown glob type: ${gs}`)
70
+
71
+ return { ...options, files }
72
+ }