jostraca 0.5.0 → 0.7.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/dist/cmp/Content.d.ts +2 -0
- package/dist/cmp/Content.js +12 -0
- package/dist/cmp/Content.js.map +1 -0
- package/dist/cmp/Copy.d.ts +1 -1
- package/dist/cmp/Copy.js +6 -19
- package/dist/cmp/Copy.js.map +1 -1
- package/dist/cmp/File.d.ts +2 -0
- package/dist/cmp/File.js +13 -0
- package/dist/cmp/File.js.map +1 -0
- package/dist/cmp/Folder.d.ts +2 -0
- package/dist/cmp/Folder.js +12 -0
- package/dist/cmp/Folder.js.map +1 -0
- package/dist/cmp/Project.d.ts +2 -0
- package/dist/cmp/Project.js +13 -0
- package/dist/cmp/Project.js.map +1 -0
- package/dist/jostraca.d.ts +8 -40
- package/dist/jostraca.js +98 -290
- package/dist/jostraca.js.map +1 -1
- package/dist/op/ContentOp.d.ts +6 -0
- package/dist/op/ContentOp.js +12 -0
- package/dist/op/ContentOp.js.map +1 -0
- package/dist/op/CopyOp.d.ts +1 -1
- package/dist/op/CopyOp.js +115 -14
- package/dist/op/CopyOp.js.map +1 -1
- package/dist/op/FileOp.d.ts +6 -0
- package/dist/op/FileOp.js +43 -0
- package/dist/op/FileOp.js.map +1 -0
- package/dist/op/FolderOp.d.ts +6 -0
- package/dist/op/FolderOp.js +23 -0
- package/dist/op/FolderOp.js.map +1 -0
- package/dist/op/NoneOp.d.ts +6 -0
- package/dist/op/NoneOp.js +9 -0
- package/dist/op/NoneOp.js.map +1 -0
- package/dist/op/ProjectOp.d.ts +6 -0
- package/dist/op/ProjectOp.js +24 -0
- package/dist/op/ProjectOp.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utility.d.ts +45 -0
- package/dist/utility.js +486 -0
- package/dist/utility.js.map +1 -0
- package/package.json +4 -4
- package/src/cmp/Content.ts +19 -0
- package/src/cmp/Copy.ts +9 -22
- package/src/cmp/File.ts +21 -0
- package/src/cmp/Folder.ts +21 -0
- package/src/cmp/Project.ts +22 -0
- package/src/jostraca.ts +115 -385
- package/src/op/ContentOp.ts +18 -0
- package/src/op/CopyOp.ts +144 -16
- package/src/op/FileOp.ts +58 -0
- package/src/op/FolderOp.ts +31 -0
- package/src/op/NoneOp.ts +14 -0
- package/src/op/ProjectOp.ts +33 -0
- package/src/utility.ts +582 -0
- package/src/op/CopyOp.ts~ +0 -12
package/src/op/CopyOp.ts
CHANGED
|
@@ -5,15 +5,25 @@ import type { Node } from '../jostraca'
|
|
|
5
5
|
|
|
6
6
|
import { getx } from '../jostraca'
|
|
7
7
|
|
|
8
|
+
import { BINARY_EXT } from '../utility'
|
|
9
|
+
|
|
10
|
+
import { FileOp } from './FileOp'
|
|
11
|
+
|
|
8
12
|
|
|
9
13
|
const CopyOp = {
|
|
10
14
|
|
|
11
15
|
before(node: Node, ctx$: any, buildctx: any) {
|
|
12
|
-
const
|
|
13
|
-
|
|
16
|
+
const fs = buildctx.fs
|
|
17
|
+
|
|
18
|
+
// TODO: do these need null checks here?
|
|
19
|
+
const name = node.name as string
|
|
20
|
+
const from = node.from as string
|
|
21
|
+
|
|
22
|
+
const fromStat = fs.statSync(from)
|
|
14
23
|
|
|
15
|
-
|
|
16
|
-
|
|
24
|
+
if (fromStat.isFile()) {
|
|
25
|
+
FileOp.before(node, ctx$, buildctx)
|
|
26
|
+
const topath = buildctx.current.file.path
|
|
17
27
|
const state = {
|
|
18
28
|
fileCount: 0,
|
|
19
29
|
folderCount: 0,
|
|
@@ -21,18 +31,66 @@ const CopyOp = {
|
|
|
21
31
|
ctx$,
|
|
22
32
|
buildctx,
|
|
23
33
|
}
|
|
24
|
-
|
|
25
|
-
|
|
34
|
+
const spec = { name, frompath: from, topath }
|
|
35
|
+
|
|
36
|
+
let content = processTemplate(state, fs.readFileSync(from).toString(), spec)
|
|
37
|
+
|
|
38
|
+
buildctx.current.file.content.push(content)
|
|
39
|
+
node.after = node.after || {}
|
|
40
|
+
node.after.kind = 'file'
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
else if (fromStat.isDirectory()) {
|
|
44
|
+
if (null != from && '' != from) {
|
|
45
|
+
node.after = node.after || {}
|
|
46
|
+
node.after.kind = 'copy'
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
else {
|
|
51
|
+
throw new Error('Unable to process file: ' + from)
|
|
26
52
|
}
|
|
27
53
|
},
|
|
28
54
|
|
|
29
|
-
|
|
55
|
+
|
|
56
|
+
after(node: Node, ctx$: any, buildctx: any) {
|
|
57
|
+
const info = buildctx.info
|
|
58
|
+
const kind = node.after.kind
|
|
59
|
+
|
|
60
|
+
const frompath = node.from as string
|
|
61
|
+
const topath = buildctx.current.folder.path.join('/')
|
|
62
|
+
|
|
63
|
+
let exclude = node.exclude
|
|
64
|
+
if (info && true === exclude) {
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if ('file' === kind) {
|
|
69
|
+
FileOp.after(node, ctx$, buildctx)
|
|
70
|
+
}
|
|
71
|
+
else if ('copy' === kind) {
|
|
72
|
+
const state = {
|
|
73
|
+
fileCount: 0,
|
|
74
|
+
folderCount: 0,
|
|
75
|
+
tmCount: 0,
|
|
76
|
+
ctx$,
|
|
77
|
+
buildctx,
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// TODO: node.path is wrong
|
|
81
|
+
// change prop.name to prop.to and account for subfolders
|
|
82
|
+
|
|
83
|
+
walk(state, node.path, frompath, topath)
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
throw new Error('Unknown kind=' + kind + ' for file: ' + frompath)
|
|
87
|
+
}
|
|
30
88
|
},
|
|
31
89
|
|
|
32
90
|
}
|
|
33
91
|
|
|
34
92
|
|
|
35
|
-
function walk(state: any, from: string, to: string) {
|
|
93
|
+
function walk(state: any, nodepath: string[], from: string, to: string) {
|
|
36
94
|
const buildctx = state.buildctx
|
|
37
95
|
const fs = buildctx.fs
|
|
38
96
|
const entries = fs.readdirSync(from)
|
|
@@ -44,29 +102,99 @@ function walk(state: any, from: string, to: string) {
|
|
|
44
102
|
|
|
45
103
|
if (stat.isDirectory()) {
|
|
46
104
|
state.folderCount++
|
|
47
|
-
walk(state, frompath, topath)
|
|
105
|
+
walk(state, nodepath.concat(name), frompath, topath)
|
|
48
106
|
}
|
|
49
107
|
else if (isTemplate(name)) {
|
|
108
|
+
if (excludeFile(state, nodepath, name, topath)) { continue }
|
|
50
109
|
const src = fs.readFileSync(frompath, 'utf8')
|
|
51
110
|
const out = genTemplate(state, src, { name, frompath, topath })
|
|
52
|
-
|
|
53
|
-
fs.mkdirSync(Path.dirname(topath), { recursive: true })
|
|
54
|
-
fs.writeFileSync(topath, out, 'utf8')
|
|
111
|
+
writeFileSync(buildctx, topath, out)
|
|
55
112
|
state.fileCount++
|
|
56
113
|
state.tmCount++
|
|
57
114
|
}
|
|
58
115
|
else {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
fs.copyFileSync(frompath, topath)
|
|
116
|
+
if (excludeFile(state, nodepath, name, topath)) { continue }
|
|
117
|
+
copyFileSync(buildctx, frompath, topath)
|
|
62
118
|
state.fileCount++
|
|
63
119
|
}
|
|
64
120
|
}
|
|
65
121
|
}
|
|
66
122
|
|
|
67
123
|
|
|
124
|
+
function excludeFile(state: any, nodepath: string[], name: string, topath: string) {
|
|
125
|
+
const { fs, info } = state.buildctx
|
|
126
|
+
let exclude = false
|
|
127
|
+
|
|
128
|
+
// NOT Path.sep - needs to be canonical
|
|
129
|
+
const rpath = nodepath.concat(name).join('/')
|
|
130
|
+
|
|
131
|
+
if (info) {
|
|
132
|
+
exclude = info.exclude.includes(rpath)
|
|
133
|
+
let stat, timedelta
|
|
134
|
+
if (!exclude) {
|
|
135
|
+
stat = fs.statSync(topath, { throwIfNoEntry: false })
|
|
136
|
+
if (stat) {
|
|
137
|
+
timedelta = stat.mtimeMs - info.last
|
|
138
|
+
if (stat && (timedelta > 0 && timedelta < stat.mtimeMs)) {
|
|
139
|
+
exclude = true
|
|
140
|
+
console.log('COPYOP-STAT', rpath, timedelta, exclude, stat?.mtimeMs, info.last)
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// if ('sdk.js' === name) {
|
|
146
|
+
// console.log('COPYSTAT', rpath, frompath,
|
|
147
|
+
// timedelta,
|
|
148
|
+
// info.exclude.includes(rpath),
|
|
149
|
+
// stat?.mtimeMs - info.last,
|
|
150
|
+
// stat?.mtimeMs, info.last, exclude)
|
|
151
|
+
// }
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (exclude && info && !info.exclude.includes(rpath)) {
|
|
155
|
+
// NOT Path.sep - has to be canonical
|
|
156
|
+
info.exclude.push(rpath)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// console.log('COPY-EXCLUDE', rpath, exclude)
|
|
160
|
+
return exclude
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
function writeFileSync(buildctx: any, path: string, content: string) {
|
|
165
|
+
// console.log('WF', path)
|
|
166
|
+
const fs = buildctx.fs
|
|
167
|
+
// TODO: check excludes
|
|
168
|
+
fs.mkdirSync(Path.dirname(path), { recursive: true })
|
|
169
|
+
fs.writeFileSync(path, content, 'utf8', { flush: true })
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
function copyFileSync(buildctx: any, frompath: string, topath: string) {
|
|
174
|
+
const fs = buildctx.fs
|
|
175
|
+
|
|
176
|
+
const isBinary = BINARY_EXT.includes(Path.extname(frompath))
|
|
177
|
+
|
|
178
|
+
// TODO: check excludes
|
|
179
|
+
fs.mkdirSync(Path.dirname(topath), { recursive: true })
|
|
180
|
+
const contents = fs.readFileSync(frompath, isBinary ? undefined : 'utf8')
|
|
181
|
+
fs.writeFileSync(topath, contents, { flush: true })
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
function processTemplate(
|
|
186
|
+
state: any,
|
|
187
|
+
src: any,
|
|
188
|
+
spec: { name: string, frompath: string, topath: string }) {
|
|
189
|
+
if (isTemplate(spec.name)) {
|
|
190
|
+
return genTemplate(state, src, spec)
|
|
191
|
+
}
|
|
192
|
+
return src
|
|
193
|
+
}
|
|
194
|
+
|
|
68
195
|
function isTemplate(name: string) {
|
|
69
|
-
|
|
196
|
+
// TODO: need a better way; alsp should be configurable
|
|
197
|
+
return !name.match(/\.(gif|jpe?g|png|ico|bmp|tiff)$/i)
|
|
70
198
|
}
|
|
71
199
|
|
|
72
200
|
// NOTE: $$foo.bar$$ format used as explicit start and end markers mean regex can be used
|
package/src/op/FileOp.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
|
|
2
|
+
import Path from 'node:path'
|
|
3
|
+
|
|
4
|
+
import type { Node } from '../jostraca'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const FileOp = {
|
|
8
|
+
|
|
9
|
+
before(node: Node, _ctx$: any, buildctx: any) {
|
|
10
|
+
const cfile: any = buildctx.current.file = node
|
|
11
|
+
cfile.filepath = buildctx.current.folder.path.join('/') + '/' + node.name
|
|
12
|
+
cfile.content = []
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
after(node: Node, _ctx$: any, buildctx: any) {
|
|
17
|
+
// console.log('FB-INFO', buildctx.info)
|
|
18
|
+
|
|
19
|
+
const { fs, info, current } = buildctx
|
|
20
|
+
const cfile = current.file
|
|
21
|
+
const content = cfile.content.join('')
|
|
22
|
+
const rpath = cfile.path.join('/') // NOT Path.sep - needs to be canonical
|
|
23
|
+
let exclude = node.exclude
|
|
24
|
+
|
|
25
|
+
// console.log('FILE-a exclude', rpath, exclude, !!info)
|
|
26
|
+
|
|
27
|
+
if (info && null == exclude) {
|
|
28
|
+
exclude = info.exclude.includes(rpath)
|
|
29
|
+
if (!exclude) {
|
|
30
|
+
const stat = fs.statSync(cfile.filepath, { throwIfNoEntry: false })
|
|
31
|
+
if (stat) {
|
|
32
|
+
let timedelta = stat.mtimeMs - info.last
|
|
33
|
+
if ((timedelta > 0 && timedelta < stat.mtimeMs)) {
|
|
34
|
+
exclude = true
|
|
35
|
+
console.log('FILEOP-STAT', rpath, timedelta, exclude, stat?.mtimeMs, info.last)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// console.log('FILE-a write', rpath, exclude) // , content.substring(0, 111))
|
|
42
|
+
|
|
43
|
+
if (!exclude) {
|
|
44
|
+
fs.writeFileSync(cfile.filepath, content, { flush: true })
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
if (!info.exclude.includes(rpath)) {
|
|
48
|
+
info.exclude.push(rpath)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
export {
|
|
57
|
+
FileOp
|
|
58
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
|
|
2
|
+
import Path from 'node:path'
|
|
3
|
+
|
|
4
|
+
import type { Node } from '../jostraca'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const FolderOp = {
|
|
8
|
+
|
|
9
|
+
before(node: Node, _ctx$: any, buildctx: any) {
|
|
10
|
+
const cfolder = buildctx.current.folder = (buildctx.current.folder || {})
|
|
11
|
+
|
|
12
|
+
cfolder.node = node
|
|
13
|
+
cfolder.path = (cfolder.path || [buildctx.current.folder.parent])
|
|
14
|
+
cfolder.path.push(node.name)
|
|
15
|
+
|
|
16
|
+
let fullpath = cfolder.path.join(Path.sep)
|
|
17
|
+
buildctx.fs.mkdirSync(fullpath, { recursive: true })
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
after(_node: Node, _ctx$: any, buildctx: any) {
|
|
22
|
+
const cfolder = buildctx.current.folder
|
|
23
|
+
cfolder.path.length = cfolder.path.length - 1
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
export {
|
|
30
|
+
FolderOp
|
|
31
|
+
}
|
package/src/op/NoneOp.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
|
|
2
|
+
import Path from 'node:path'
|
|
3
|
+
|
|
4
|
+
import type { Node } from '../jostraca'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const ProjectOp = {
|
|
8
|
+
|
|
9
|
+
before(node: Node, ctx$: any, buildctx: any) {
|
|
10
|
+
// console.log('PROJECT-B', node.folder, ctx$.folder)
|
|
11
|
+
|
|
12
|
+
node.folder = null == node.folder || '' === node.folder ? '.' : node.folder
|
|
13
|
+
node.folder = Path.isAbsolute(node.folder) ? node.folder : Path.join(ctx$.folder, node.folder)
|
|
14
|
+
|
|
15
|
+
// console.log('PROJECT-B folder', node.folder)
|
|
16
|
+
|
|
17
|
+
buildctx.current.project = { node }
|
|
18
|
+
buildctx.current.folder = {
|
|
19
|
+
node,
|
|
20
|
+
path: node.folder.split(Path.sep),
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
buildctx.fs.mkdirSync(node.folder, { recursive: true })
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
after(_node: Node, _ctx$: any, _buildctx: any) { },
|
|
27
|
+
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
export {
|
|
32
|
+
ProjectOp
|
|
33
|
+
}
|