jostraca 0.7.4 → 0.7.6
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/dist/cmp/Content.d.ts +1 -1
- package/dist/cmp/Content.js.map +1 -1
- package/dist/cmp/Copy.d.ts +1 -1
- package/dist/cmp/Copy.js +1 -1
- package/dist/cmp/Copy.js.map +1 -1
- package/dist/cmp/File.d.ts +1 -1
- package/dist/cmp/File.js +2 -2
- package/dist/cmp/File.js.map +1 -1
- package/dist/cmp/Folder.d.ts +1 -1
- package/dist/cmp/Folder.js +1 -1
- package/dist/cmp/Folder.js.map +1 -1
- package/dist/cmp/Fragment.d.ts +1 -1
- package/dist/cmp/Fragment.js.map +1 -1
- package/dist/cmp/Inject.d.ts +1 -1
- package/dist/cmp/Inject.js +1 -1
- package/dist/cmp/Inject.js.map +1 -1
- package/dist/cmp/Project.d.ts +1 -1
- package/dist/cmp/Project.js +1 -1
- package/dist/cmp/Project.js.map +1 -1
- package/dist/jostraca.d.ts +1 -1
- package/dist/jostraca.js +11 -10
- package/dist/jostraca.js.map +1 -1
- package/dist/op/CopyOp.js +39 -18
- package/dist/op/CopyOp.js.map +1 -1
- package/dist/op/FileOp.d.ts +1 -1
- package/dist/op/FileOp.js +26 -11
- package/dist/op/FileOp.js.map +1 -1
- package/dist/op/FragmentOp.d.ts +1 -1
- package/dist/op/FragmentOp.js +12 -2
- package/dist/op/FragmentOp.js.map +1 -1
- package/dist/op/InjectOp.d.ts +1 -1
- package/dist/op/InjectOp.js +2 -2
- package/dist/op/InjectOp.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +26 -0
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -0
- package/dist/utility.d.ts +7 -26
- package/dist/utility.js +60 -26
- package/dist/utility.js.map +1 -1
- package/package.json +2 -2
- package/src/cmp/Content.ts +1 -2
- package/src/cmp/Copy.ts +2 -2
- package/src/cmp/File.ts +3 -3
- package/src/cmp/Folder.ts +2 -2
- package/src/cmp/Fragment.ts +1 -2
- package/src/cmp/Inject.ts +2 -2
- package/src/cmp/Project.ts +2 -2
- package/src/jostraca.ts +13 -12
- package/src/op/CopyOp.ts +45 -18
- package/src/op/FileOp.ts +32 -11
- package/src/op/FragmentOp.ts +10 -2
- package/src/op/InjectOp.ts +2 -2
- package/src/types.ts +47 -0
- package/src/utility.ts +82 -65
- package/gen/readme.js~ +0 -1
package/src/op/InjectOp.ts
CHANGED
|
@@ -13,7 +13,7 @@ const InjectOp = {
|
|
|
13
13
|
},
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
after(node: Node,
|
|
16
|
+
after(node: Node, ctx$: any, buildctx: any) {
|
|
17
17
|
const { fs, info, current } = buildctx
|
|
18
18
|
const cfile = current.file
|
|
19
19
|
let content = cfile.content.join('')
|
|
@@ -22,7 +22,7 @@ const InjectOp = {
|
|
|
22
22
|
|
|
23
23
|
if (info && null == exclude) {
|
|
24
24
|
exclude = info.exclude.includes(rpath)
|
|
25
|
-
if (!exclude) {
|
|
25
|
+
if (!exclude && true === ctx$.opts.exclude) {
|
|
26
26
|
const stat = fs.statSync(cfile.filepath, { throwIfNoEntry: false })
|
|
27
27
|
if (stat) {
|
|
28
28
|
let timedelta = stat.mtimeMs - info.last
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/* Copyright (c) 2024 Richard Rodger, MIT License */
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
type JostracaOptions = {
|
|
5
|
+
folder?: string // Base output folder for generated files. Default: `.`.
|
|
6
|
+
meta?: any // Provide meta data to the generation process. Default: `{}`
|
|
7
|
+
exclude?: boolean // Exclude modified output files. Default: `false`.
|
|
8
|
+
fs?: any // File system API (used for testing). Default: `node:fs`
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
type Node = {
|
|
13
|
+
kind: string
|
|
14
|
+
children?: Node[]
|
|
15
|
+
meta: any
|
|
16
|
+
|
|
17
|
+
name?: string
|
|
18
|
+
path: string[]
|
|
19
|
+
from?: string
|
|
20
|
+
content?: any[]
|
|
21
|
+
folder?: string
|
|
22
|
+
after?: any
|
|
23
|
+
exclude?: boolean | string | string[]
|
|
24
|
+
indent?: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
type OpStep = (node: Node, ctx$: any, buildctx: any) => void
|
|
29
|
+
|
|
30
|
+
type OpDef = {
|
|
31
|
+
before: OpStep,
|
|
32
|
+
after: OpStep,
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
type Component = (props: any, children?: any) => void
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
export type {
|
|
41
|
+
JostracaOptions,
|
|
42
|
+
Node,
|
|
43
|
+
OpStep,
|
|
44
|
+
OpDef,
|
|
45
|
+
Component,
|
|
46
|
+
}
|
|
47
|
+
|
package/src/utility.ts
CHANGED
|
@@ -1,83 +1,103 @@
|
|
|
1
1
|
/* Copyright (c) 2024 Richard Rodger, MIT License */
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
// Iterate over arrays and objects (opinionated mutation!).
|
|
5
|
+
function each(
|
|
6
|
+
subject?: any[] | Object, // Iterate over subject.
|
|
7
|
+
flags?: { // Optional, flags to control output.
|
|
8
|
+
mark?: boolean, // Mark items (key$ or index$), default: true,
|
|
9
|
+
oval?: boolean, // Convert non-object values into synthetic objects, default: true
|
|
10
|
+
sort?: boolean | string, // Sort items, optionally by named prop, default: false
|
|
11
|
+
call?: boolean, // Call items, if they are functions, default: false
|
|
12
|
+
} | ((...a: any[]) => any),
|
|
13
|
+
apply?: (...a: any[]) => any) // Optional Function to apply to each item.
|
|
14
|
+
{
|
|
15
|
+
const isArray = Array.isArray(subject)
|
|
16
|
+
|
|
17
|
+
const hasFlags = null != flags && 'function' !== typeof flags
|
|
18
|
+
apply = (hasFlags ? apply : flags) as ((...a: any[]) => any)
|
|
19
|
+
|
|
20
|
+
flags = (hasFlags ? flags : {}) as { mark: boolean, sort: boolean }
|
|
21
|
+
flags.mark = null != flags.mark ? flags.mark : true
|
|
22
|
+
flags.oval = null != flags.oval ? flags.oval : true
|
|
23
|
+
flags.sort = null != flags.sort ? flags.sort : false
|
|
24
|
+
flags.call = null != flags.call ? flags.call : false
|
|
25
|
+
|
|
26
|
+
let out: any[] = []
|
|
27
|
+
|
|
28
|
+
if (isArray) {
|
|
29
|
+
for (let fn of subject) {
|
|
30
|
+
out.push(flags.call && 'function' === typeof fn ? fn() : fn)
|
|
31
|
+
}
|
|
15
32
|
|
|
16
|
-
|
|
17
|
-
path: string[]
|
|
18
|
-
from?: string
|
|
19
|
-
content?: any[]
|
|
20
|
-
folder?: string
|
|
21
|
-
after?: any
|
|
22
|
-
exclude?: boolean
|
|
23
|
-
indent?: string
|
|
24
|
-
}
|
|
33
|
+
out = true === flags.sort && 1 < out.length ? out.sort() : out
|
|
25
34
|
|
|
35
|
+
out = flags.oval ? out.map((n: any) =>
|
|
36
|
+
(null != n && 'object' === typeof n) ? n : { val$: n }) : out
|
|
26
37
|
|
|
27
|
-
|
|
38
|
+
out = 'string' === typeof flags.sort ?
|
|
39
|
+
out.sort((a: any, b: any) =>
|
|
40
|
+
(a?.[flags.sort as string] < b?.[flags.sort as string] ? -1 :
|
|
41
|
+
a?.[flags.sort as string] > b?.[flags.sort as string] ? 1 : 0)) : out
|
|
28
42
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
43
|
+
out = flags.mark ? out
|
|
44
|
+
.map((n: any, i: number, _: any) =>
|
|
45
|
+
(_ = typeof n, (null != n && 'object' === _ ? (n.index$ = i) : null), n)) : out
|
|
33
46
|
|
|
47
|
+
if ('function' === typeof apply) {
|
|
48
|
+
out = out.map((n: any, ...args: any[]) =>
|
|
49
|
+
apply(n, ...args))
|
|
50
|
+
}
|
|
34
51
|
|
|
35
|
-
|
|
52
|
+
return out
|
|
53
|
+
}
|
|
36
54
|
|
|
55
|
+
const isObject = null != subject && 'object' === typeof subject
|
|
37
56
|
|
|
57
|
+
if (!isObject) {
|
|
58
|
+
return out
|
|
59
|
+
}
|
|
38
60
|
|
|
61
|
+
let entries: any = Object.entries(subject as any)
|
|
39
62
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
let out = []
|
|
43
|
-
if (Array.isArray(subject)) {
|
|
44
|
-
for (let fn of subject) {
|
|
45
|
-
out.push('function' === typeof fn ? fn() : fn)
|
|
46
|
-
}
|
|
47
|
-
return out.sort()
|
|
48
|
-
}
|
|
49
|
-
else if (null == subject || 'object' !== typeof subject) {
|
|
50
|
-
return []
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
else if (Array.isArray(subject)) {
|
|
54
|
-
return subject.map(apply)
|
|
63
|
+
if (flags.call) {
|
|
64
|
+
entries = entries.map((n: any[]) => ((n[1] = 'function' === typeof n[1] ? n[1]() : n[1]), n))
|
|
55
65
|
}
|
|
56
66
|
|
|
57
|
-
if (
|
|
58
|
-
|
|
67
|
+
if (flags.oval) {
|
|
68
|
+
out = entries.map((n: any[], _: any) =>
|
|
69
|
+
(_ = typeof n[1],
|
|
70
|
+
(null != n[1] && 'object' === _) ? n[1] :
|
|
71
|
+
(n[1] = { key$: n[0], val$: n[1] }), n))
|
|
59
72
|
}
|
|
60
73
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
(
|
|
64
|
-
(n[1]
|
|
74
|
+
if (flags.mark) {
|
|
75
|
+
entries.map((n: any[], _: any) =>
|
|
76
|
+
(_ = typeof n[1],
|
|
77
|
+
(null != n[1] && 'object' === _) ? (n[1].key$ = n[0]) : n[1], n))
|
|
78
|
+
}
|
|
65
79
|
|
|
66
|
-
if (1 < entries.length) {
|
|
67
|
-
if (
|
|
80
|
+
if (1 < entries.length && flags.sort) {
|
|
81
|
+
if (null != entries[0][1] && 'object' === typeof entries[0][1]) {
|
|
82
|
+
let sprop = 'string' === flags.sort ? flags.sort : 'key$'
|
|
68
83
|
entries.sort((a: any, b: any) =>
|
|
69
|
-
a[1]
|
|
84
|
+
a[1]?.[sprop] < b[1]?.[sprop] ? -1 : b[1]?.[sprop] < a[1]?.[sprop] ? 1 : 0)
|
|
70
85
|
}
|
|
71
|
-
else
|
|
86
|
+
else {
|
|
72
87
|
entries.sort((a: any, b: any) =>
|
|
73
|
-
a[1]
|
|
88
|
+
a[1] < b[1] ? -1 : b[1] < a[1] ? 1 : 0)
|
|
74
89
|
}
|
|
75
90
|
}
|
|
76
91
|
|
|
77
|
-
|
|
92
|
+
if ('function' === typeof apply) {
|
|
93
|
+
out = entries.map((n: any[], ...args: any[]) =>
|
|
94
|
+
apply(n[1], n[0], ...args))
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
out = entries.map((n: any[]) => n[1])
|
|
98
|
+
}
|
|
78
99
|
|
|
79
|
-
return
|
|
80
|
-
apply(n[1], n[0], ...args))
|
|
100
|
+
return out
|
|
81
101
|
}
|
|
82
102
|
|
|
83
103
|
|
|
@@ -220,8 +240,13 @@ function getx(root: any, path: string | string[]): any {
|
|
|
220
240
|
out = each(node)
|
|
221
241
|
.filter((child: any) => undefined != getx(child, ftokens))
|
|
222
242
|
|
|
223
|
-
if (null
|
|
224
|
-
|
|
243
|
+
if (null != node && 'object' === typeof node) {
|
|
244
|
+
if (Array.isArray(node)) {
|
|
245
|
+
out = out.map((n: any) => (delete n.index$, n))
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
out = out.reduce((a: any, n: any) => (a[n.key$] = n, delete n.key$, a), {})
|
|
249
|
+
}
|
|
225
250
|
}
|
|
226
251
|
|
|
227
252
|
node = out
|
|
@@ -626,14 +651,6 @@ const BINARY_EXT = [
|
|
|
626
651
|
|
|
627
652
|
|
|
628
653
|
|
|
629
|
-
export type {
|
|
630
|
-
JostracaOptions,
|
|
631
|
-
Node,
|
|
632
|
-
OpStep,
|
|
633
|
-
OpDef,
|
|
634
|
-
Component,
|
|
635
|
-
}
|
|
636
|
-
|
|
637
654
|
|
|
638
655
|
export {
|
|
639
656
|
each,
|
package/gen/readme.js~
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|