malinajs 0.6.43
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/CHANGELOG.md +58 -0
- package/LICENSE +21 -0
- package/compile.js +6115 -0
- package/malina-esbuild.js +121 -0
- package/malina-rollup.js +44 -0
- package/malina.js +6094 -0
- package/package.json +43 -0
- package/plugins/sass.js +26 -0
- package/readme.md +58 -0
- package/runtime.js +954 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
const { build } = require('esbuild');
|
|
2
|
+
const { derver } = require('derver');
|
|
3
|
+
const malina = require('malinajs');
|
|
4
|
+
const fsp = require('fs/promises');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
|
|
8
|
+
process.argv.includes('-w') ? process.env.WATCH = 1 : null;
|
|
9
|
+
|
|
10
|
+
// Configs
|
|
11
|
+
|
|
12
|
+
const esbuildConfigPath = path.join(process.cwd(),'esbuild.config.js');
|
|
13
|
+
const derverConfigPath = path.join(process.cwd(),'derver.config.js');
|
|
14
|
+
const malinaConfigPath = path.join(process.cwd(),'malina.config.js');
|
|
15
|
+
|
|
16
|
+
const esbuildConfig = fs.existsSync(esbuildConfigPath) ? require(esbuildConfigPath) : {};
|
|
17
|
+
const derverConfig = fs.existsSync(derverConfigPath) ? require(derverConfigPath) : {};
|
|
18
|
+
const malinaConfig = fs.existsSync(malinaConfigPath) ? require(malinaConfigPath) : {};
|
|
19
|
+
|
|
20
|
+
// Executable
|
|
21
|
+
|
|
22
|
+
if(!module.parent){
|
|
23
|
+
|
|
24
|
+
if(process.env.WATCH){
|
|
25
|
+
esbuild({
|
|
26
|
+
minify: false,
|
|
27
|
+
incremental: true
|
|
28
|
+
}).then( bundle =>{
|
|
29
|
+
derver({
|
|
30
|
+
dir: 'public',
|
|
31
|
+
watch: ['public','src'],
|
|
32
|
+
onwatch: async (lr,item)=>{
|
|
33
|
+
if(item === 'src'){
|
|
34
|
+
lr.prevent();
|
|
35
|
+
try{
|
|
36
|
+
await bundle.rebuild();
|
|
37
|
+
}catch(err){
|
|
38
|
+
console.log(err.message);
|
|
39
|
+
lr.error(err.toString(),'Build error');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
...derverConfig
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
}else{
|
|
47
|
+
esbuild();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Module
|
|
53
|
+
|
|
54
|
+
module.exports = {
|
|
55
|
+
malinaPlugin,
|
|
56
|
+
esbuild
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function malinaPlugin(options={}){
|
|
60
|
+
|
|
61
|
+
const cssModules = new Map();
|
|
62
|
+
|
|
63
|
+
options = {
|
|
64
|
+
...malinaConfig,
|
|
65
|
+
...options
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if(options.displayVersion !== false) console.log('! Malina.js', malina.version);
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
name: 'malina-plugin',
|
|
72
|
+
setup(build) {
|
|
73
|
+
build.onLoad(
|
|
74
|
+
{ filter: /\.(xht|ma|html)$/ },
|
|
75
|
+
async (args) => {
|
|
76
|
+
|
|
77
|
+
let source = await fsp.readFile(args.path, 'utf8');
|
|
78
|
+
|
|
79
|
+
let ctx = await malina.compile(source,{
|
|
80
|
+
name: args.path.match(/([^/\\]+)\.\w+$/)[1],
|
|
81
|
+
...options
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
let code = ctx.result;
|
|
85
|
+
|
|
86
|
+
if(!options.css && ctx.css.result){
|
|
87
|
+
const cssPath = args.path.replace(/\.\w+$/, ".malina.css").replace(/\\/g, "/");
|
|
88
|
+
cssModules.set(cssPath,ctx.css.result);
|
|
89
|
+
code += `\nimport "${cssPath}";`
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return { contents: code }
|
|
93
|
+
}
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
build.onResolve({ filter: /\.malina\.css$/ }, ({ path }) => {
|
|
97
|
+
return { path, namespace: 'malinacss' }
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
build.onLoad({ filter: /\.malina\.css$/, namespace: 'malinacss' }, ({ path }) => {
|
|
101
|
+
const css = cssModules.get(path);
|
|
102
|
+
return css ? { contents: css, loader: "css" } : null;
|
|
103
|
+
})
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async function esbuild(options={}){
|
|
109
|
+
|
|
110
|
+
options = {
|
|
111
|
+
entryPoints: ['src/main.js'],
|
|
112
|
+
outfile: 'public/bundle.js',
|
|
113
|
+
minify: true,
|
|
114
|
+
bundle: true,
|
|
115
|
+
plugins: [malinaPlugin()],
|
|
116
|
+
...esbuildConfig,
|
|
117
|
+
...options
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
return build(options);
|
|
121
|
+
}
|
package/malina-rollup.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
|
|
2
|
+
const malina = require('malinajs');
|
|
3
|
+
|
|
4
|
+
module.exports = malinaRollup;
|
|
5
|
+
|
|
6
|
+
function malinaRollup(option = {}) {
|
|
7
|
+
if(option.displayVersion !== false) console.log('! Malina.js', malina.version);
|
|
8
|
+
if(!option.extension) option.extension = ['html', 'ma', 'xht'];
|
|
9
|
+
let content_cache = {};
|
|
10
|
+
|
|
11
|
+
return {
|
|
12
|
+
name: 'malina',
|
|
13
|
+
async transform(code, id) {
|
|
14
|
+
if(!option.extension.some(ext => id.endsWith('.' + ext))) return null;
|
|
15
|
+
let result;
|
|
16
|
+
|
|
17
|
+
let opts = Object.assign({
|
|
18
|
+
path: id,
|
|
19
|
+
name: id.match(/([^/\\]+)\.\w+$/)[1]
|
|
20
|
+
}, option);
|
|
21
|
+
try {
|
|
22
|
+
let ctx = await malina.compile(code, opts);
|
|
23
|
+
result = ctx.result;
|
|
24
|
+
if(ctx.css.result) {
|
|
25
|
+
let name = id.replace(/[^\w.\-]/g, '') + '.css';
|
|
26
|
+
content_cache[name] = ctx.css.result;
|
|
27
|
+
result += `\nimport "${name}";\n`;
|
|
28
|
+
}
|
|
29
|
+
} catch (e) {
|
|
30
|
+
if(e.details) console.log(e.details);
|
|
31
|
+
throw e;
|
|
32
|
+
}
|
|
33
|
+
return {code: result};
|
|
34
|
+
},
|
|
35
|
+
async resolveId(name, importer) {
|
|
36
|
+
if(content_cache[name]) return name;
|
|
37
|
+
if(name == 'malinajs') return await this.resolve('malinajs/runtime.js', importer, {skipSelf: true});
|
|
38
|
+
return null;
|
|
39
|
+
},
|
|
40
|
+
load(id) {
|
|
41
|
+
return content_cache[id] || null;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|