mikser-io 6.0.4 → 6.0.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/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "mikser-io",
3
- "version": "6.0.4",
3
+ "version": "6.0.6",
4
4
  "description": "<p align=\"center\"> <img src=\"mikser-lockup-stacked.svg\" alt=\"mikser\" width=\"198\" /> </p>",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
- "test": "node --no-warnings app.js --working-folder test"
7
+ "test": "node --no-warnings app.js --debug --working-folder test"
8
8
  },
9
9
  "bin": {
10
10
  "mikser": "app.js"
@@ -17,18 +17,19 @@
17
17
  "author": "",
18
18
  "license": "ISC",
19
19
  "dependencies": {
20
+ "@budibase/handlebars-helpers": "^0.14.2",
20
21
  "await-semaphore": "^0.1.3",
21
22
  "axios": "^1.16.0",
22
23
  "chokidar": "^5.0.0",
23
24
  "cli-progress": "^3.12.0",
24
25
  "commander": "^14.0.3",
26
+ "dayjs": "^1.11.20",
25
27
  "deepdash": "^5.3.9",
26
28
  "escape-string-regexp": "^5.0.0",
27
29
  "execa": "^9.6.1",
28
30
  "front-matter": "^4.0.2",
29
31
  "globby": "^16.2.0",
30
32
  "handlebars": "^4.7.9",
31
- "handlebars-helpers": "^0.10.0",
32
33
  "hasha": "^7.0.0",
33
34
  "is-url": "^1.2.4",
34
35
  "knex": "^3.2.10",
@@ -52,6 +53,7 @@
52
53
  },
53
54
  "devDependencies": {
54
55
  "fluent-ffmpeg": "^2.1.3",
56
+ "mikser-io-render-markdown": "^2.0.0",
55
57
  "sharp": "^0.34.5"
56
58
  },
57
59
  "directories": {
@@ -20,6 +20,8 @@ export default ({
20
20
  onSync,
21
21
  matchEntity,
22
22
  changeExtension,
23
+ findEntity,
24
+ findEntities,
23
25
  constants: { ACTION, OPERATION, TASKS },
24
26
  }) => {
25
27
  const collection = 'layouts'
@@ -206,20 +208,27 @@ export default ({
206
208
  break
207
209
  }
208
210
  }
209
- if (!entity.layout && runtime.config.layouts?.autoLayouts && entity.name) {
210
- const nameChunks = entity.name.split('.')
211
- if (nameChunks?.length) {
212
- for (let index = 0; index < nameChunks.length; index++) {
213
- const autoLayout = [
214
- path.basename(entity.name).split('.').slice(index).join('.'),
215
- path.basename(entity.id)
216
- ]
217
- .find(layout => layouts[layout])
218
- if (autoLayout) {
219
- entity.layout = layouts[autoLayout]
220
- break
221
- }
222
- }
211
+ if (!entity.layout && runtime.config.layouts?.autoLayouts && entity.id) {
212
+ const lookupBase = entity.id.replace(`/${entity.collection}/`,'')
213
+ const dir = path.dirname(lookupBase)
214
+ const base = path.basename(lookupBase)
215
+ const chunks = base.split('.')
216
+ const candidates = []
217
+
218
+ // Peel trailing chunks within the entity's directory only.
219
+ // "nginx.conf" (dir=".") -> ["nginx.conf", "nginx"]
220
+ // "styles/post.css" (dir="styles") -> ["styles/post.css", "styles/post"]
221
+ for (let i = chunks.length; i > 0; i--) {
222
+ const head = chunks.slice(0, i).join('.')
223
+ candidates.push(dir && dir !== '.' ? path.join(dir, head) : head)
224
+ }
225
+
226
+ const autoLayout = candidates.find(name => layouts[name])
227
+ if (autoLayout) {
228
+ entity.layout = layouts[autoLayout]
229
+ logger.debug('Auto layout matched %s -> %s for %s', entity.name, autoLayout, entity.id)
230
+ } else {
231
+ logger.trace('Auto layout no match for %s tried: %s', entity.id, candidates.join(', '))
223
232
  }
224
233
  }
225
234
  } else {
@@ -250,6 +259,7 @@ export default ({
250
259
  })
251
260
 
252
261
  onBeforeRender(async (signal) => {
262
+ const logger = useLogger()
253
263
  const tasks = []
254
264
  const entities = Array.from(getSitemapEntities())
255
265
  .filter(entity => entity.layout)
@@ -268,7 +278,7 @@ export default ({
268
278
  try {
269
279
  var { load, plugins = [] } = await import(`${path.join(runtime.options.layoutsFolder, entity.layout.name)}.js?stamp=${Date.now()}`)
270
280
  if (load) {
271
- data = await load(entity, signal)
281
+ data = await load({ entity, findEntity, findEntities, runtime, signal })
272
282
  }
273
283
  } catch (err) {
274
284
  if (err.code != 'ERR_MODULE_NOT_FOUND') throw err
@@ -1,5 +1,6 @@
1
1
  import handlebars from 'handlebars'
2
- import helpers from 'handlebars-helpers'
2
+ import helpers from '@budibase/handlebars-helpers'
3
+ import dayjs from 'dayjs'
3
4
  import { readFile } from 'fs/promises'
4
5
 
5
6
  export function load({ config, runtime, context }) {
@@ -8,8 +9,6 @@ export function load({ config, runtime, context }) {
8
9
  'collection',
9
10
  'object',
10
11
  'comparison',
11
- 'date',
12
- 'markdown',
13
12
  'match',
14
13
  'math',
15
14
  'number',
@@ -23,6 +22,12 @@ export function load({ config, runtime, context }) {
23
22
  handlebars.registerPartial(partial, partialLayout)
24
23
  }
25
24
  }
25
+ handlebars.registerHelper('date', (date, format) => {
26
+ if (!date) return ''
27
+ if (typeof format !== 'string') format = 'YYYY-MM-DD'
28
+ return dayjs(date).format(format)
29
+ })
30
+
26
31
  handlebars.registerHelper('url', function(obj, options) {
27
32
  // Called as {{url}} with no args — obj is the Handlebars options object,
28
33
  // so read url from the current context (this)
package/src/plugins.js CHANGED
@@ -3,17 +3,25 @@ import { onLoad } from './lifecycle.js'
3
3
  import runtime from './runtime.js'
4
4
  import path from 'node:path'
5
5
  import fs from 'fs'
6
+ import { createRequire } from 'node:module'
6
7
 
7
8
  import * as core from '../index.js'
8
9
 
9
10
  export async function loadPlugin(pluginName) {
10
11
  const logger = useLogger()
11
12
 
13
+ const require = createRequire(path.join(runtime.options.workingFolder, 'package.json'))
14
+ let nodeModulesResolved
15
+ try {
16
+ nodeModulesResolved = require.resolve(`mikser-io-${pluginName}`)
17
+ } catch { }
18
+
12
19
  const resolveLocations = [
13
20
  path.join(path.dirname(import.meta.url), 'plugins', `${pluginName}.js`),
14
21
  path.join(runtime.options.workingFolder, 'plugins', `${pluginName}.js`),
15
22
  path.join(runtime.options.workingFolder, 'node_modules', `mikser-io-${pluginName}`, 'index.js'),
16
- ]
23
+ nodeModulesResolved,
24
+ ].filter(Boolean)
17
25
  for (let index = 0; index < resolveLocations.length; index++) {
18
26
  const resolveLocation = resolveLocations[index]
19
27
  if (fs.existsSync(resolveLocation.replace('file:', ''))) {
package/src/render.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { readFileSync } from 'node:fs'
2
+ import { createRequire } from 'node:module'
2
3
  import path from 'node:path'
3
4
  import _ from 'lodash'
4
5
 
@@ -22,11 +23,18 @@ export default async ({ entity, options, config, context, state, logger, port })
22
23
  }
23
24
 
24
25
  async function loadPlugin(pluginName) {
26
+ const require = createRequire(path.join(options.workingFolder, 'package.json'))
27
+ let nodeModulesResolved
28
+ try {
29
+ nodeModulesResolved = require.resolve(`mikser-io-${pluginName}`)
30
+ } catch { }
31
+
25
32
  const resolveLocations = [
26
33
  path.join(options.workingFolder, 'node_modules', `mikser-io-${pluginName}/index.js`),
34
+ nodeModulesResolved,
27
35
  path.join(options.workingFolder, 'plugins', `${pluginName}.js`),
28
36
  path.join(path.dirname(import.meta.url), 'plugins', 'render', `${pluginName.replace('render-', '')}.js`)
29
- ]
37
+ ].filter(Boolean)
30
38
  for (let resolveLocation of resolveLocations) {
31
39
  try {
32
40
  return await import(resolveLocation)