mikser-io 6.0.4 → 6.0.5

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.5",
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": {
@@ -207,19 +207,25 @@ export default ({
207
207
  }
208
208
  }
209
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
- }
210
+ const dir = path.dirname(entity.name)
211
+ const base = path.basename(entity.name)
212
+ const chunks = base.split('.')
213
+ const candidates = []
214
+
215
+ // Peel trailing chunks within the entity's directory only.
216
+ // "nginx.conf" (dir=".") -> ["nginx.conf", "nginx"]
217
+ // "styles/post.css" (dir="styles") -> ["styles/post.css", "styles/post"]
218
+ for (let i = chunks.length; i > 0; i--) {
219
+ const head = chunks.slice(0, i).join('.')
220
+ candidates.push(dir && dir !== '.' ? path.join(dir, head) : head)
221
+ }
222
+
223
+ const autoLayout = candidates.find(name => layouts[name])
224
+ if (autoLayout) {
225
+ entity.layout = layouts[autoLayout]
226
+ logger.debug('Auto layout matched %s -> %s for %s', entity.name, autoLayout, entity.id)
227
+ } else {
228
+ logger.trace('Auto layout no match for %s tried: %s', entity.id, candidates.join(', '))
223
229
  }
224
230
  }
225
231
  } else {
@@ -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)