malinajs 0.7.17 → 0.8.0-a1

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.
Files changed (4) hide show
  1. package/malina-rollup.js +29 -9
  2. package/malina.js +22246 -2646
  3. package/malina.mjs +26752 -0
  4. package/package.json +12 -25
package/malina-rollup.js CHANGED
@@ -1,9 +1,7 @@
1
1
 
2
- const malina = require('malinajs');
2
+ import * as malina from 'malinajs/malina.mjs';
3
3
 
4
- module.exports = malinaRollup;
5
-
6
- function malinaRollup(option = {}) {
4
+ export default function malinaRollup(option = {}) {
7
5
  if(option.displayVersion !== false) console.log('! Malina.js', malina.version);
8
6
  if(!option.extension) option.extension = ['html', 'ma', 'xht'];
9
7
  let content_cache = {};
@@ -13,11 +11,11 @@ function malinaRollup(option = {}) {
13
11
  async transform(code, id) {
14
12
  if(!option.extension.some(ext => id.endsWith('.' + ext))) return null;
15
13
  let result;
16
-
17
- let opts = Object.assign({
14
+ let opts = await loadConfig(id, {
15
+ ...option,
18
16
  path: id,
19
17
  name: id.match(/([^/\\]+)\.\w+$/)[1]
20
- }, option);
18
+ });
21
19
  try {
22
20
  let ctx = await malina.compile(code, opts);
23
21
  result = ctx.result;
@@ -34,11 +32,33 @@ function malinaRollup(option = {}) {
34
32
  },
35
33
  async resolveId(name, importer) {
36
34
  if(content_cache[name]) return name;
37
- if(name == 'malinajs') return await this.resolve('malinajs/runtime.js', importer, {skipSelf: true});
38
35
  return null;
39
36
  },
40
37
  load(id) {
41
38
  return content_cache[id] || null;
42
39
  }
43
40
  };
44
- }
41
+ }
42
+
43
+
44
+ async function loadConfig(filename, option) {
45
+ const fs = await import('fs');
46
+ let localConfig, parts = filename.split(/[/\\]/);
47
+ for(let i = parts.length - 1; i > 1; i--) {
48
+ let local = parts.slice(0, i).join('/') + '/malina.config.js';
49
+ if(fs.existsSync(local)) {
50
+ localConfig = local;
51
+ break;
52
+ }
53
+ }
54
+
55
+ if(localConfig) {
56
+ const confFn = (await import(localConfig)).default;
57
+ if(typeof (confFn) == 'function') option = await confFn(option, filename);
58
+ else option = confFn;
59
+ }
60
+ if(!option.path) option.path = filename;
61
+ if(!option.name) option.name = option.path.match(/([^/\\]+)\.\w+$/)[1];
62
+
63
+ return option;
64
+ }