jostraca 0.16.2 → 0.18.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/src/jostraca.ts CHANGED
@@ -11,7 +11,7 @@ import { AsyncLocalStorage } from 'node:async_hooks'
11
11
 
12
12
  import { util as JsonicUtil } from 'jsonic'
13
13
 
14
- import { Gubu } from 'gubu'
14
+ import { Gubu, Skip } from 'gubu'
15
15
 
16
16
  import { memfs as MemFs } from 'memfs'
17
17
 
@@ -90,41 +90,22 @@ const DEFAULT_LOGGER = {
90
90
 
91
91
 
92
92
  const OptionsShape = Gubu({
93
- folder: '.', // Base output folder for generated files. Default: `.`.
93
+ folder: Skip(String), // Base output folder for generated files. Default: `.`.
94
94
  meta: {} as any, // Provide meta data to the generation process. Default: `{}`
95
95
 
96
- fs: (() => undefined) as any, // File system API. Default: `node:fs`.
96
+ fs: Skip(Function) as any, // File system API. Default: `node:fs`.
97
97
  now: undefined as any, // Provide current time.
98
98
 
99
99
  log: DEFAULT_LOGGER as any, // Logging interface.
100
- debug: 'info', // Generate additional debugging information.
100
+ debug: Skip('info'), // Generate additional debugging information.
101
101
 
102
102
  // TOOD: needs rethink
103
103
  exclude: false, // Exclude modified output files. Default: `false`.
104
104
 
105
- // TODO: change to existing:{txt,bin}
106
- existing: {
107
- txt: {
108
- write: true, // Overwrite existing files (unless present=true).
109
- preserve: false, // Keep a backup copy (.old.) of overwritten files.
110
- present: false, // Present the new file using .new. name annotation.
111
- diff: false, // Annotated 2-way diff of new generate and existing file.
112
- merge: false, // Annotated 3-way merge of new generate and existing file.
113
- },
114
- bin: {
115
- write: true, // Overwrite existing files (unless present=true).
116
- preserve: false, // Keep a backup copy (.old.) of overwritten files.
117
- present: false, // Present the new file using .new. name annotation.
118
- // No diff of binary files
119
- // No merge of binary files
120
- }
121
- },
122
-
123
- processing: {
124
- duplicate: true,
125
- },
105
+ // Validated in separate shape to allow overriding.
106
+ existing: { txt: {}, bin: {} },
126
107
 
127
- model: {},
108
+ model: Skip({}) as any,
128
109
  build: true,
129
110
  mem: false,
130
111
  vol: {},
@@ -134,14 +115,42 @@ const OptionsShape = Gubu({
134
115
  Copy: {
135
116
  ignore: [] as any[]
136
117
  }
118
+ },
119
+
120
+ control: {
121
+ duplicate: true,
122
+ version: false,
123
+ },
124
+
125
+ }, { name: 'Jostraca Options' })
126
+
127
+
128
+ const ExistingShape = Gubu({
129
+ txt: {
130
+ write: true, // Overwrite existing files (unless present=true).
131
+ preserve: false, // Keep a backup copy (.old.) of overwritten files.
132
+ present: false, // Present the new file using .new. name annotation.
133
+ diff: false, // Annotated 2-way diff of new generate and existing file.
134
+ merge: false, // Annotated 3-way merge of new generate and existing file.
135
+ },
136
+ bin: {
137
+ write: true, // Overwrite existing files (unless present=true).
138
+ preserve: false, // Keep a backup copy (.old.) of overwritten files.
139
+ present: false, // Present the new file using .new. name annotation.
140
+ // No diff of binary files
141
+ // No merge of binary files
137
142
  }
138
- })
143
+
144
+ }, { name: 'Jostraca Options (`existing` property)' })
145
+
146
+
139
147
 
140
148
  type JostracaOptions = ReturnType<typeof OptionsShape>
149
+ type ExistingOptions = ReturnType<typeof ExistingShape>
141
150
 
142
151
  type Existing = {
143
- txt: JostracaOptions["existing"]["txt"]
144
- bin: JostracaOptions["existing"]["bin"]
152
+ txt: ExistingOptions["txt"]
153
+ bin: ExistingOptions["bin"]
145
154
  }
146
155
 
147
156
 
@@ -161,27 +170,32 @@ function Jostraca(gopts_in?: JostracaOptions | {}) {
161
170
  const vol = deep({}, gopts.vol, opts.vol)
162
171
  const memfs = useMemFS ? MemFs(vol) : undefined
163
172
 
164
- const fs = opts.fs() || gopts.fs() || memfs?.fs || Fs
173
+ const fs = (opts.fs || gopts.fs || (() => memfs?.fs) || (() => Fs))()
165
174
  const now = opts.now || gopts.now || Date.now
166
175
 
167
176
  const meta = {
168
177
  ...(gopts?.meta || {}),
169
178
  ...(opts.meta || {}),
170
179
  }
180
+
171
181
  const folder = opts.folder || gopts?.folder || '.'
182
+
172
183
  const log: Log = opts.log || gopts?.log || DEFAULT_LOGGER
173
- const debug: boolean = !!(null == opts.debug ? gopts?.debug : opts.debug)
184
+ // const debug: boolean = !!(null == opts.debug ? gopts?.debug : opts.debug)
185
+ const debug = opts.debug || gopts.debug
174
186
 
175
- const existing = {
176
- txt: deep(gopts.existing.txt, opts.existing.txt),
177
- bin: deep(gopts.existing.bin, opts.existing.bin),
178
- }
187
+ const existing = ExistingShape({
188
+ // FIX: this does not work as generate opts get defaults from OptionsShape
189
+ txt: deep({}, gopts.existing.txt, opts.existing.txt),
190
+ bin: deep({}, gopts.existing.bin, opts.existing.bin),
191
+ })
179
192
 
180
- const processing = opts.processing
193
+ const control = opts.control
181
194
 
182
195
  const doBuild: boolean = null == gopts?.build ? false !== opts.build : false !== gopts?.build
183
196
 
184
- const model = deep({}, gopts.model, opts.model)
197
+ // const model = deep({}, gopts.model, opts.model)
198
+ const model = opts.model || gopts.model || {}
185
199
 
186
200
  // Component defaults.
187
201
  opts.cmp = deep({
@@ -213,7 +227,7 @@ function Jostraca(gopts_in?: JostracaOptions | {}) {
213
227
  const buildctx = new BuildContext(
214
228
  folder,
215
229
  existing,
216
- processing,
230
+ control,
217
231
  ctx$.fs,
218
232
  ctx$.now,
219
233
  )
@@ -222,8 +236,6 @@ function Jostraca(gopts_in?: JostracaOptions | {}) {
222
236
  await build(ctx$, buildctx)
223
237
  }
224
238
 
225
- // console.log('END')
226
- // console.dir(buildctx, { depth: null })
227
239
  const res: JostracaResult = {
228
240
  when: buildctx.when,
229
241
  files: buildctx.fh.files
@@ -320,7 +332,6 @@ function cmp(component: Function): Component {
320
332
  props.ctx$ = ctx$
321
333
 
322
334
  let parent = ctx$.node
323
- // console.log('BBB', component, props, parent?.filter?.({ props }))
324
335
 
325
336
  if (parent?.filter && !parent.filter({ props, children, component })) {
326
337
  return undefined
package/src/util/basic.ts CHANGED
@@ -438,7 +438,16 @@ function template(
438
438
 
439
439
  // Get replacement from model path.
440
440
  if (null != ref) {
441
- insert = '__JOSTRACA_REPLACE__' === ref ? '' + insertRE : getx(model, ref)
441
+ const qm = ref.match(/^"(.+)"$/)
442
+ if (qm) {
443
+ insert = qm[1]
444
+ }
445
+ else if ('__JOSTRACA_REPLACE__' === ref) {
446
+ insert = '' + insertRE
447
+ }
448
+ else {
449
+ insert = getx(model, ref)
450
+ }
442
451
  skip = mg.J_O.length + mg.J_C.length
443
452
  }
444
453