@dimina/compiler 1.0.2 → 1.0.4
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/README.md +20 -5
- package/dist/bin/index.cjs +5 -4
- package/dist/bin/index.js +5 -4
- package/dist/core/view-compiler.cjs +37 -5
- package/dist/core/view-compiler.js +37 -5
- package/dist/index.cjs +4 -4
- package/dist/index.js +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -69,6 +69,7 @@ Usage: dmcc build [选项]
|
|
|
69
69
|
-c, --work-path <path> 编译文件所在目录(默认为当前目录)
|
|
70
70
|
-s, --target-path <path> 编译产物存放路径(默认为当前目录)
|
|
71
71
|
-w, --watch 启用改动监听(实时编译)
|
|
72
|
+
--no-app-id-dir 产物根目录不包含appId,默认为 false
|
|
72
73
|
-h, --help 显示帮助信息
|
|
73
74
|
```
|
|
74
75
|
|
|
@@ -86,6 +87,9 @@ dmcc build -w
|
|
|
86
87
|
|
|
87
88
|
# 完整示例:编译指定目录,输出到指定目录,并启用监听
|
|
88
89
|
dmcc build -c ./src -s ./dist -w
|
|
90
|
+
|
|
91
|
+
# 产物根目录不包含appId
|
|
92
|
+
dmcc build --no-app-id-dir
|
|
89
93
|
```
|
|
90
94
|
|
|
91
95
|
### 编译流程说明
|
|
@@ -101,14 +105,25 @@ app.json, index.json -> config.json (配置文件)
|
|
|
101
105
|
|
|
102
106
|
### 编译产物目录结构
|
|
103
107
|
|
|
104
|
-
|
|
108
|
+
编译后,默认会在目标目录生成以小程序 id 命名的文件夹,项目结构如下:
|
|
109
|
+
|
|
110
|
+
```txt
|
|
111
|
+
dist/
|
|
112
|
+
├─ {appId}/ # 小程序 ID 目录(使用 --no-app-id-dir 参数可以去除此目录层级)
|
|
113
|
+
├─ logic.js # 小程序逻辑代码
|
|
114
|
+
├─ view.js # 小程序视图代码
|
|
115
|
+
├─ style.css # 小程序样式
|
|
116
|
+
└─ config.json # 小程序配置
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
如果使用 `--no-app-id-dir` 参数,产物将直接输出到目标目录,而不会创建以 appId 命名的子目录:
|
|
105
120
|
|
|
106
121
|
```txt
|
|
107
122
|
dist/
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
123
|
+
├─ logic.js # 小程序逻辑代码
|
|
124
|
+
├─ view.js # 小程序视图代码
|
|
125
|
+
├─ style.css # 小程序样式
|
|
126
|
+
└─ config.json # 小程序配置
|
|
112
127
|
```
|
|
113
128
|
|
|
114
129
|
### 常见问题
|
package/dist/bin/index.cjs
CHANGED
|
@@ -5,14 +5,15 @@ const path = require("node:path");
|
|
|
5
5
|
const commander = require("commander");
|
|
6
6
|
const chokidar = require("chokidar");
|
|
7
7
|
const index = require("../index.cjs");
|
|
8
|
-
const version = "1.0.
|
|
8
|
+
const version = "1.0.4";
|
|
9
9
|
const pack = {
|
|
10
10
|
version
|
|
11
11
|
};
|
|
12
|
-
commander.program.command("build").option("-c, --work-path <path>", "编译工作目录").option("-s, --target-path <path>", "编译产物存放路径").option("-w, --watch", "启用监听文件改动").action(async (options) => {
|
|
12
|
+
commander.program.command("build").option("-c, --work-path <path>", "编译工作目录").option("-s, --target-path <path>", "编译产物存放路径").option("-w, --watch", "启用监听文件改动").option("--no-app-id-dir", "产物根目录不包含appId").action(async (options) => {
|
|
13
13
|
const workPath = options.workPath ? path.resolve(options.workPath) : process.cwd();
|
|
14
14
|
const targetPath = options.targetPath ? path.resolve(options.targetPath) : process.cwd();
|
|
15
|
-
|
|
15
|
+
const useAppIdDir = options.appIdDir !== false;
|
|
16
|
+
await index(targetPath, workPath, useAppIdDir);
|
|
16
17
|
const watch = options.watch;
|
|
17
18
|
if (watch) {
|
|
18
19
|
chokidar.watch(workPath, {
|
|
@@ -23,7 +24,7 @@ commander.program.command("build").option("-c, --work-path <path>", "编译工
|
|
|
23
24
|
}).on("all", async (event, path2) => {
|
|
24
25
|
if (event === "change") {
|
|
25
26
|
console.log(`${path2} 改动,重新编译`);
|
|
26
|
-
await index(targetPath, workPath);
|
|
27
|
+
await index(targetPath, workPath, useAppIdDir);
|
|
27
28
|
}
|
|
28
29
|
});
|
|
29
30
|
}
|
package/dist/bin/index.js
CHANGED
|
@@ -4,14 +4,15 @@ import path from "node:path";
|
|
|
4
4
|
import { program } from "commander";
|
|
5
5
|
import chokidar from "chokidar";
|
|
6
6
|
import build from "../index.js";
|
|
7
|
-
const version = "1.0.
|
|
7
|
+
const version = "1.0.4";
|
|
8
8
|
const pack = {
|
|
9
9
|
version
|
|
10
10
|
};
|
|
11
|
-
program.command("build").option("-c, --work-path <path>", "编译工作目录").option("-s, --target-path <path>", "编译产物存放路径").option("-w, --watch", "启用监听文件改动").action(async (options) => {
|
|
11
|
+
program.command("build").option("-c, --work-path <path>", "编译工作目录").option("-s, --target-path <path>", "编译产物存放路径").option("-w, --watch", "启用监听文件改动").option("--no-app-id-dir", "产物根目录不包含appId").action(async (options) => {
|
|
12
12
|
const workPath = options.workPath ? path.resolve(options.workPath) : process.cwd();
|
|
13
13
|
const targetPath = options.targetPath ? path.resolve(options.targetPath) : process.cwd();
|
|
14
|
-
|
|
14
|
+
const useAppIdDir = options.appIdDir !== false;
|
|
15
|
+
await build(targetPath, workPath, useAppIdDir);
|
|
15
16
|
const watch = options.watch;
|
|
16
17
|
if (watch) {
|
|
17
18
|
chokidar.watch(workPath, {
|
|
@@ -22,7 +23,7 @@ program.command("build").option("-c, --work-path <path>", "编译工作目录").
|
|
|
22
23
|
}).on("all", async (event, path2) => {
|
|
23
24
|
if (event === "change") {
|
|
24
25
|
console.log(`${path2} 改动,重新编译`);
|
|
25
|
-
await build(targetPath, workPath);
|
|
26
|
+
await build(targetPath, workPath, useAppIdDir);
|
|
26
27
|
}
|
|
27
28
|
});
|
|
28
29
|
}
|
|
@@ -474,10 +474,23 @@ function getProps(attrs, tag) {
|
|
|
474
474
|
value: parseBraceExp(value)
|
|
475
475
|
});
|
|
476
476
|
} else if (name === "value" && (tag === "input" || tag === "textarea") || (name === "x" || name === "y") && tag === "movable-view") {
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
477
|
+
const parsedValue = parseBraceExp(value);
|
|
478
|
+
const conditionExp = generateVModelTemplate(parsedValue);
|
|
479
|
+
if (conditionExp) {
|
|
480
|
+
attrsList.push({
|
|
481
|
+
name: `:${name}`,
|
|
482
|
+
value: parsedValue
|
|
483
|
+
});
|
|
484
|
+
attrsList.push({
|
|
485
|
+
name: `update:${name}`,
|
|
486
|
+
value: conditionExp
|
|
487
|
+
});
|
|
488
|
+
} else {
|
|
489
|
+
attrsList.push({
|
|
490
|
+
name: `v-model:${name}`,
|
|
491
|
+
value: parsedValue
|
|
492
|
+
});
|
|
493
|
+
}
|
|
481
494
|
} else if (name.startsWith("data-")) {
|
|
482
495
|
if (isWrappedByBraces(value)) {
|
|
483
496
|
attrsList.push({
|
|
@@ -523,6 +536,24 @@ function getProps(attrs, tag) {
|
|
|
523
536
|
});
|
|
524
537
|
return propsRes;
|
|
525
538
|
}
|
|
539
|
+
function generateVModelTemplate(expression) {
|
|
540
|
+
let var1, var2, updateExpression;
|
|
541
|
+
if (expression.includes("&&")) {
|
|
542
|
+
[var1, var2] = expression.split("&&").map((v) => v.trim());
|
|
543
|
+
updateExpression = `${var1} ? (${var2} = $event) : (${var1} = $event)`;
|
|
544
|
+
} else if (expression.includes("||")) {
|
|
545
|
+
[var1, var2] = expression.split("||").map((v) => v.trim());
|
|
546
|
+
updateExpression = `${var1} ? (${var1} = $event) : (${var2} = $event)`;
|
|
547
|
+
} else if (expression.includes("?")) {
|
|
548
|
+
const parts = expression.split(/[?:]/).map((v) => v.trim());
|
|
549
|
+
var1 = parts[0];
|
|
550
|
+
var2 = parts[2];
|
|
551
|
+
updateExpression = `${var1} ? (${var1} = $event) : (${var2} = $event)`;
|
|
552
|
+
} else {
|
|
553
|
+
return false;
|
|
554
|
+
}
|
|
555
|
+
return updateExpression;
|
|
556
|
+
}
|
|
526
557
|
function parseKeyExpression(exp, itemName = "item") {
|
|
527
558
|
exp = exp.trim();
|
|
528
559
|
if (!exp.includes("{{")) {
|
|
@@ -646,6 +677,7 @@ const viewCompiler = {
|
|
|
646
677
|
parseClassRules,
|
|
647
678
|
parseBraceExp,
|
|
648
679
|
parseKeyExpression,
|
|
649
|
-
compileML
|
|
680
|
+
compileML,
|
|
681
|
+
generateVModelTemplate
|
|
650
682
|
};
|
|
651
683
|
module.exports = viewCompiler;
|
|
@@ -455,10 +455,23 @@ function getProps(attrs, tag) {
|
|
|
455
455
|
value: parseBraceExp(value)
|
|
456
456
|
});
|
|
457
457
|
} else if (name === "value" && (tag === "input" || tag === "textarea") || (name === "x" || name === "y") && tag === "movable-view") {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
458
|
+
const parsedValue = parseBraceExp(value);
|
|
459
|
+
const conditionExp = generateVModelTemplate(parsedValue);
|
|
460
|
+
if (conditionExp) {
|
|
461
|
+
attrsList.push({
|
|
462
|
+
name: `:${name}`,
|
|
463
|
+
value: parsedValue
|
|
464
|
+
});
|
|
465
|
+
attrsList.push({
|
|
466
|
+
name: `update:${name}`,
|
|
467
|
+
value: conditionExp
|
|
468
|
+
});
|
|
469
|
+
} else {
|
|
470
|
+
attrsList.push({
|
|
471
|
+
name: `v-model:${name}`,
|
|
472
|
+
value: parsedValue
|
|
473
|
+
});
|
|
474
|
+
}
|
|
462
475
|
} else if (name.startsWith("data-")) {
|
|
463
476
|
if (isWrappedByBraces(value)) {
|
|
464
477
|
attrsList.push({
|
|
@@ -504,6 +517,24 @@ function getProps(attrs, tag) {
|
|
|
504
517
|
});
|
|
505
518
|
return propsRes;
|
|
506
519
|
}
|
|
520
|
+
function generateVModelTemplate(expression) {
|
|
521
|
+
let var1, var2, updateExpression;
|
|
522
|
+
if (expression.includes("&&")) {
|
|
523
|
+
[var1, var2] = expression.split("&&").map((v) => v.trim());
|
|
524
|
+
updateExpression = `${var1} ? (${var2} = $event) : (${var1} = $event)`;
|
|
525
|
+
} else if (expression.includes("||")) {
|
|
526
|
+
[var1, var2] = expression.split("||").map((v) => v.trim());
|
|
527
|
+
updateExpression = `${var1} ? (${var1} = $event) : (${var2} = $event)`;
|
|
528
|
+
} else if (expression.includes("?")) {
|
|
529
|
+
const parts = expression.split(/[?:]/).map((v) => v.trim());
|
|
530
|
+
var1 = parts[0];
|
|
531
|
+
var2 = parts[2];
|
|
532
|
+
updateExpression = `${var1} ? (${var1} = $event) : (${var2} = $event)`;
|
|
533
|
+
} else {
|
|
534
|
+
return false;
|
|
535
|
+
}
|
|
536
|
+
return updateExpression;
|
|
537
|
+
}
|
|
507
538
|
function parseKeyExpression(exp, itemName = "item") {
|
|
508
539
|
exp = exp.trim();
|
|
509
540
|
if (!exp.includes("{{")) {
|
|
@@ -627,7 +658,8 @@ const viewCompiler = {
|
|
|
627
658
|
parseClassRules,
|
|
628
659
|
parseBraceExp,
|
|
629
660
|
parseKeyExpression,
|
|
630
|
-
compileML
|
|
661
|
+
compileML,
|
|
662
|
+
generateVModelTemplate
|
|
631
663
|
};
|
|
632
664
|
export {
|
|
633
665
|
viewCompiler as default
|
package/dist/index.cjs
CHANGED
|
@@ -39,10 +39,10 @@ function createDist() {
|
|
|
39
39
|
}
|
|
40
40
|
shelljs.mkdir("-p", `${distPath}`);
|
|
41
41
|
}
|
|
42
|
-
function publishToDist(dist) {
|
|
42
|
+
function publishToDist(dist, useAppIdDir = true) {
|
|
43
43
|
const distPath = env.getTargetPath();
|
|
44
44
|
const appId = env.getAppId();
|
|
45
|
-
const absolutePath = `${path.resolve(process.cwd(), dist)}/${appId}`;
|
|
45
|
+
const absolutePath = useAppIdDir ? `${path.resolve(process.cwd(), dist)}/${appId}` : `${path.resolve(process.cwd(), dist)}`;
|
|
46
46
|
shelljs.rm("-rf", absolutePath);
|
|
47
47
|
shelljs.mkdir("-p", absolutePath);
|
|
48
48
|
shelljs.cp("-r", `${distPath}/*`, absolutePath);
|
|
@@ -113,7 +113,7 @@ class WorkerPool {
|
|
|
113
113
|
}
|
|
114
114
|
const workerPool = new WorkerPool();
|
|
115
115
|
let isPrinted = false;
|
|
116
|
-
async function build(targetPath, workPath) {
|
|
116
|
+
async function build(targetPath, workPath, useAppIdDir = true) {
|
|
117
117
|
if (!isPrinted) {
|
|
118
118
|
artCode$1();
|
|
119
119
|
isPrinted = true;
|
|
@@ -183,7 +183,7 @@ async function build(targetPath, workPath) {
|
|
|
183
183
|
{
|
|
184
184
|
title: "输出编译产物",
|
|
185
185
|
task: () => {
|
|
186
|
-
publishToDist(targetPath);
|
|
186
|
+
publishToDist(targetPath, useAppIdDir);
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
],
|
package/dist/index.js
CHANGED
|
@@ -37,10 +37,10 @@ function createDist() {
|
|
|
37
37
|
}
|
|
38
38
|
shelljs.mkdir("-p", `${distPath}`);
|
|
39
39
|
}
|
|
40
|
-
function publishToDist(dist) {
|
|
40
|
+
function publishToDist(dist, useAppIdDir = true) {
|
|
41
41
|
const distPath = getTargetPath();
|
|
42
42
|
const appId = getAppId();
|
|
43
|
-
const absolutePath = `${path.resolve(process.cwd(), dist)}/${appId}`;
|
|
43
|
+
const absolutePath = useAppIdDir ? `${path.resolve(process.cwd(), dist)}/${appId}` : `${path.resolve(process.cwd(), dist)}`;
|
|
44
44
|
shelljs.rm("-rf", absolutePath);
|
|
45
45
|
shelljs.mkdir("-p", absolutePath);
|
|
46
46
|
shelljs.cp("-r", `${distPath}/*`, absolutePath);
|
|
@@ -111,7 +111,7 @@ class WorkerPool {
|
|
|
111
111
|
}
|
|
112
112
|
const workerPool = new WorkerPool();
|
|
113
113
|
let isPrinted = false;
|
|
114
|
-
async function build(targetPath, workPath) {
|
|
114
|
+
async function build(targetPath, workPath, useAppIdDir = true) {
|
|
115
115
|
if (!isPrinted) {
|
|
116
116
|
artCode$1();
|
|
117
117
|
isPrinted = true;
|
|
@@ -181,7 +181,7 @@ async function build(targetPath, workPath) {
|
|
|
181
181
|
{
|
|
182
182
|
title: "输出编译产物",
|
|
183
183
|
task: () => {
|
|
184
|
-
publishToDist(targetPath);
|
|
184
|
+
publishToDist(targetPath, useAppIdDir);
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
187
|
],
|