@luonghaminhvy/vite-plugin-songma 0.5.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/LICENSE +21 -0
- package/index.js +58 -0
- package/package.json +31 -0
- package/test_plugin.js +32 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Luong Ha Minh Vy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/index.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
let transpile;
|
|
2
|
+
try {
|
|
3
|
+
transpile = require('@luonghaminhvy/songma').transpile;
|
|
4
|
+
} catch (_) {
|
|
5
|
+
transpile = require('../songma').transpile;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Vite Plugin cho ngôn ngữ lập trình SongMa (.sm / .smx)
|
|
10
|
+
* @param {object} options
|
|
11
|
+
* @returns {import('vite').Plugin}
|
|
12
|
+
*/
|
|
13
|
+
function songmaPlugin(options = {}) {
|
|
14
|
+
const songmaFilter = /\.(sm|smx)(\?.*)?$/;
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
name: 'vite-plugin-songma',
|
|
18
|
+
enforce: 'pre',
|
|
19
|
+
|
|
20
|
+
config() {
|
|
21
|
+
return {
|
|
22
|
+
esbuild: {
|
|
23
|
+
include: /\.(tsx?|jsx?|[jt]s|sm|smx)$/,
|
|
24
|
+
loader: 'tsx',
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
transform(src, id) {
|
|
30
|
+
if (!songmaFilter.test(id)) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const cleanId = id.split('?')[0];
|
|
35
|
+
const isTs = options.isTs || true;
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
const compiledCode = transpile(src, {
|
|
39
|
+
filename: cleanId,
|
|
40
|
+
isTs,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
code: compiledCode,
|
|
45
|
+
map: null,
|
|
46
|
+
};
|
|
47
|
+
} catch (err) {
|
|
48
|
+
this.error(`[vite-plugin-songma] Lỗi biên dịch tệp ${cleanId}:\n${err.message}`);
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
module.exports = {
|
|
56
|
+
songmaPlugin,
|
|
57
|
+
default: songmaPlugin,
|
|
58
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@luonghaminhvy/vite-plugin-songma",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "Vite plugin to transpile and bundle SongMa (.smjs / .smts / .smjx / .smtx) files in React, Vue, Svelte and Vanilla projects",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"vite-plugin",
|
|
8
|
+
"songma",
|
|
9
|
+
"vietlang",
|
|
10
|
+
"transpiler",
|
|
11
|
+
"vietnamese",
|
|
12
|
+
"react",
|
|
13
|
+
"jsx"
|
|
14
|
+
],
|
|
15
|
+
"author": "Luong Ha Minh Vy",
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/LuongHaMinhVy/SongMa.git"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://github.com/LuongHaMinhVy/SongMa",
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"vite": "^4.0.0 || ^5.0.0 || ^6.0.0"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@luonghaminhvy/songma": "0.5.0"
|
|
30
|
+
}
|
|
31
|
+
}
|
package/test_plugin.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const assert = require('assert');
|
|
2
|
+
const { songmaPlugin } = require('./index');
|
|
3
|
+
|
|
4
|
+
console.log('--- 1. Kiểm tra khởi tạo Vite Plugin ---');
|
|
5
|
+
const plugin = songmaPlugin();
|
|
6
|
+
assert.strictEqual(plugin.name, 'vite-plugin-songma');
|
|
7
|
+
assert.strictEqual(typeof plugin.transform, 'function');
|
|
8
|
+
console.log('✓ Khởi tạo plugin thành công.');
|
|
9
|
+
|
|
10
|
+
console.log('--- 2. Kiểm tra transform() với tệp .smjs ---');
|
|
11
|
+
const sampleSongMa = `
|
|
12
|
+
biến tieu_de = "Xin chào từ Vite!";
|
|
13
|
+
hàm tinh_toan(x, y) {
|
|
14
|
+
trả x * y;
|
|
15
|
+
}
|
|
16
|
+
in(tieu_de + " => " + tinh_toan(5, 6));
|
|
17
|
+
`;
|
|
18
|
+
|
|
19
|
+
const result = plugin.transform(sampleSongMa, 'nguon/math.sm');
|
|
20
|
+
assert(result, 'Cần trả về object kết quả');
|
|
21
|
+
assert(result.code.includes('let tieu_de = "Xin chào từ Vite!";'), 'Cần chứa mã JS đã biên dịch');
|
|
22
|
+
assert(result.code.includes('function tinh_toan'), 'Cần chứa hàm JS');
|
|
23
|
+
console.log('✓ transform(.sm) thành công.');
|
|
24
|
+
|
|
25
|
+
console.log('--- 3. Kiểm tra transform() bỏ qua tệp không phải SongMa ---');
|
|
26
|
+
const jsResult = plugin.transform('const a = 1;', 'main.js');
|
|
27
|
+
assert.strictEqual(jsResult, null, 'Cần bỏ qua tệp .js');
|
|
28
|
+
console.log('✓ Bỏ qua tệp không thuộc SongMa thành công.');
|
|
29
|
+
|
|
30
|
+
console.log('\n========================================');
|
|
31
|
+
console.log('TẤT CẢ TEST CỦA GIAI ĐOẠN 2 ĐỀU THÀNH CÔNG!');
|
|
32
|
+
console.log('========================================');
|