@weapp-core/init 3.0.3 → 3.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/dist/index.cjs +115 -112
- package/dist/index.js +114 -111
- package/package.json +3 -3
- package/templates/default/package.json +1 -1
- package/templates/tailwindcss/package.json +2 -2
- package/templates/tailwindcss/project.config.json +2 -1
- package/templates/tailwindcss/project.private.config.json +1 -1
- package/templates/tailwindcss/src/components/HelloWorld/HelloWorld.wxml +3 -3
- package/templates/tailwindcss/src/pages/index/index.wxml +8 -8
- package/templates/tailwindcss/src/pages/profile/index.wxml +7 -8
- package/templates/tdesign/package.json +2 -2
- package/templates/vant/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -42,7 +42,7 @@ __export(index_exports, {
|
|
|
42
42
|
});
|
|
43
43
|
module.exports = __toCommonJS(index_exports);
|
|
44
44
|
|
|
45
|
-
// ../../node_modules/.pnpm/tsup@8.5.1_@swc+core@1.15.
|
|
45
|
+
// ../../node_modules/.pnpm/tsup@8.5.1_@swc+core@1.15.3_jiti@2.6.1_postcss@8.5.6_tsx@4.20.6_typescript@5.9.3_yaml@2.8.1/node_modules/tsup/assets/cjs_shims.js
|
|
46
46
|
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
|
|
47
47
|
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
48
48
|
|
|
@@ -471,6 +471,13 @@ var posix = /* @__PURE__ */ mix(":");
|
|
|
471
471
|
var win32 = /* @__PURE__ */ mix(";");
|
|
472
472
|
|
|
473
473
|
// src/context.ts
|
|
474
|
+
function createDocument() {
|
|
475
|
+
return {
|
|
476
|
+
name: "",
|
|
477
|
+
path: "",
|
|
478
|
+
value: null
|
|
479
|
+
};
|
|
480
|
+
}
|
|
474
481
|
function createContext() {
|
|
475
482
|
return {
|
|
476
483
|
projectConfig: createDocument(),
|
|
@@ -482,13 +489,6 @@ function createContext() {
|
|
|
482
489
|
dts: createDocument()
|
|
483
490
|
};
|
|
484
491
|
}
|
|
485
|
-
function createDocument() {
|
|
486
|
-
return {
|
|
487
|
-
name: "",
|
|
488
|
-
path: "",
|
|
489
|
-
value: null
|
|
490
|
-
};
|
|
491
|
-
}
|
|
492
492
|
|
|
493
493
|
// src/state.ts
|
|
494
494
|
var ctx = createContext();
|
|
@@ -768,7 +768,7 @@ var import_logger3 = __toESM(require("@weapp-core/logger"), 1);
|
|
|
768
768
|
var import_fs_extra2 = __toESM(require("fs-extra"), 1);
|
|
769
769
|
|
|
770
770
|
// ../../packages/weapp-vite/package.json
|
|
771
|
-
var version = "5.
|
|
771
|
+
var version = "5.10.0";
|
|
772
772
|
|
|
773
773
|
// src/enums.ts
|
|
774
774
|
var TemplateName = /* @__PURE__ */ ((TemplateName2) => {
|
|
@@ -809,10 +809,13 @@ function getLatestVersionFromNpm(packageName) {
|
|
|
809
809
|
}).on("error", reject);
|
|
810
810
|
});
|
|
811
811
|
}
|
|
812
|
-
async function latestVersion(packageName, prefix = "^") {
|
|
812
|
+
async function latestVersion(packageName, prefix = "^", fetch = getLatestVersionFromNpm) {
|
|
813
813
|
try {
|
|
814
|
-
const resolved = await
|
|
815
|
-
|
|
814
|
+
const resolved = await fetch(packageName);
|
|
815
|
+
if (!resolved) {
|
|
816
|
+
return null;
|
|
817
|
+
}
|
|
818
|
+
return `${prefix}${resolved}`;
|
|
816
819
|
} catch {
|
|
817
820
|
return null;
|
|
818
821
|
}
|
|
@@ -858,6 +861,20 @@ dist
|
|
|
858
861
|
dist-plugin
|
|
859
862
|
dist-web
|
|
860
863
|
vite.config.ts.timestamp-*.mjs`;
|
|
864
|
+
function normalizeLineEndings(value) {
|
|
865
|
+
return value.replace(/\r\n/g, "\n");
|
|
866
|
+
}
|
|
867
|
+
function trimTrailingBlankLines(lines) {
|
|
868
|
+
let end = lines.length;
|
|
869
|
+
while (end > 0 && lines[end - 1] === "") {
|
|
870
|
+
end -= 1;
|
|
871
|
+
}
|
|
872
|
+
return lines.slice(0, end);
|
|
873
|
+
}
|
|
874
|
+
function ensureTrailingNewline(value) {
|
|
875
|
+
return value.endsWith("\n") ? value : `${value}
|
|
876
|
+
`;
|
|
877
|
+
}
|
|
861
878
|
function mergeGitignore(existing) {
|
|
862
879
|
const normalizedExisting = normalizeLineEndings(existing ?? "");
|
|
863
880
|
const existingLines = normalizedExisting.length ? normalizedExisting.split("\n") : [];
|
|
@@ -888,20 +905,6 @@ function mergeGitignore(existing) {
|
|
|
888
905
|
}
|
|
889
906
|
return ensureTrailingNewline(trimTrailingBlankLines(merged).join("\n"));
|
|
890
907
|
}
|
|
891
|
-
function normalizeLineEndings(value) {
|
|
892
|
-
return value.replace(/\r\n/g, "\n");
|
|
893
|
-
}
|
|
894
|
-
function trimTrailingBlankLines(lines) {
|
|
895
|
-
let end = lines.length;
|
|
896
|
-
while (end > 0 && lines[end - 1] === "") {
|
|
897
|
-
end -= 1;
|
|
898
|
-
}
|
|
899
|
-
return lines.slice(0, end);
|
|
900
|
-
}
|
|
901
|
-
function ensureTrailingNewline(value) {
|
|
902
|
-
return value.endsWith("\n") ? value : `${value}
|
|
903
|
-
`;
|
|
904
|
-
}
|
|
905
908
|
|
|
906
909
|
// src/updateGitignore.ts
|
|
907
910
|
async function updateGitIgnore(options) {
|
|
@@ -919,6 +922,38 @@ async function updateGitIgnore(options) {
|
|
|
919
922
|
|
|
920
923
|
// src/createProject.ts
|
|
921
924
|
var moduleDir = posix.dirname((0, import_node_url.fileURLToPath)(importMetaUrl));
|
|
925
|
+
async function ensureDotGitignore(root) {
|
|
926
|
+
const gitignorePath = posix.resolve(root, "gitignore");
|
|
927
|
+
const dotGitignorePath = posix.resolve(root, ".gitignore");
|
|
928
|
+
if (!await import_fs_extra2.default.pathExists(gitignorePath)) {
|
|
929
|
+
return;
|
|
930
|
+
}
|
|
931
|
+
if (await import_fs_extra2.default.pathExists(dotGitignorePath)) {
|
|
932
|
+
await import_fs_extra2.default.remove(gitignorePath);
|
|
933
|
+
return;
|
|
934
|
+
}
|
|
935
|
+
await import_fs_extra2.default.move(gitignorePath, dotGitignorePath);
|
|
936
|
+
}
|
|
937
|
+
function createEmptyPackageJson() {
|
|
938
|
+
return {
|
|
939
|
+
name: "weapp-vite-app",
|
|
940
|
+
homepage: "https://vite.icebreaker.top/",
|
|
941
|
+
type: "module",
|
|
942
|
+
scripts: {},
|
|
943
|
+
devDependencies: {}
|
|
944
|
+
};
|
|
945
|
+
}
|
|
946
|
+
async function upsertTailwindcssVersion(pkgJson) {
|
|
947
|
+
if (!pkgJson.devDependencies) {
|
|
948
|
+
return;
|
|
949
|
+
}
|
|
950
|
+
const resolved = await latestVersion("weapp-tailwindcss");
|
|
951
|
+
if (resolved) {
|
|
952
|
+
pkgJson.devDependencies["weapp-tailwindcss"] = resolved;
|
|
953
|
+
} else if (!pkgJson.devDependencies["weapp-tailwindcss"]) {
|
|
954
|
+
pkgJson.devDependencies["weapp-tailwindcss"] = "^4.3.3";
|
|
955
|
+
}
|
|
956
|
+
}
|
|
922
957
|
async function createProject(targetDir = "", templateName = "default" /* default */) {
|
|
923
958
|
const targetTemplateDir = posix.resolve(moduleDir, "../templates", templateName);
|
|
924
959
|
if (!await import_fs_extra2.default.pathExists(targetTemplateDir)) {
|
|
@@ -941,18 +976,16 @@ async function createProject(targetDir = "", templateName = "default" /* default
|
|
|
941
976
|
await updateGitIgnore({ root: targetDir, write: true });
|
|
942
977
|
import_logger3.default.log("\u2728 \u521B\u5EFA\u6A21\u677F\u6210\u529F!");
|
|
943
978
|
}
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
}
|
|
955
|
-
function createEmptyPackageJson() {
|
|
979
|
+
|
|
980
|
+
// src/packageJson.ts
|
|
981
|
+
var import_logger4 = __toESM(require("@weapp-core/logger"), 1);
|
|
982
|
+
var import_shared = require("@weapp-core/shared");
|
|
983
|
+
var FALLBACK_DEP_VERSIONS = {
|
|
984
|
+
"miniprogram-api-typings": "^4.1.0",
|
|
985
|
+
"typescript": "^5.9.2",
|
|
986
|
+
"weapp-tailwindcss": "^4.3.3"
|
|
987
|
+
};
|
|
988
|
+
function createDefaultPackageJson() {
|
|
956
989
|
return {
|
|
957
990
|
name: "weapp-vite-app",
|
|
958
991
|
homepage: "https://vite.icebreaker.top/",
|
|
@@ -961,27 +994,18 @@ function createEmptyPackageJson() {
|
|
|
961
994
|
devDependencies: {}
|
|
962
995
|
};
|
|
963
996
|
}
|
|
964
|
-
async function
|
|
965
|
-
const
|
|
966
|
-
const
|
|
967
|
-
if (
|
|
997
|
+
async function upsertDependencyVersion(packageJson, keyPath, packageName, options = {}) {
|
|
998
|
+
const currentValue = (0, import_shared.get)(packageJson, keyPath);
|
|
999
|
+
const resolved = options.skipNetwork ? null : await latestVersion(packageName);
|
|
1000
|
+
if (resolved) {
|
|
1001
|
+
(0, import_shared.set)(packageJson, keyPath, resolved);
|
|
968
1002
|
return;
|
|
969
1003
|
}
|
|
970
|
-
if (
|
|
971
|
-
|
|
972
|
-
|
|
1004
|
+
if (currentValue === void 0) {
|
|
1005
|
+
const fallback = FALLBACK_DEP_VERSIONS[packageName] ?? "latest";
|
|
1006
|
+
(0, import_shared.set)(packageJson, keyPath, fallback);
|
|
973
1007
|
}
|
|
974
|
-
await import_fs_extra2.default.move(gitignorePath, dotGitignorePath);
|
|
975
1008
|
}
|
|
976
|
-
|
|
977
|
-
// src/packageJson.ts
|
|
978
|
-
var import_logger4 = __toESM(require("@weapp-core/logger"), 1);
|
|
979
|
-
var import_shared = require("@weapp-core/shared");
|
|
980
|
-
var FALLBACK_DEP_VERSIONS = {
|
|
981
|
-
"miniprogram-api-typings": "^4.1.0",
|
|
982
|
-
"typescript": "^5.9.2",
|
|
983
|
-
"weapp-tailwindcss": "^4.3.3"
|
|
984
|
-
};
|
|
985
1009
|
async function createOrUpdatePackageJson(options) {
|
|
986
1010
|
const { root, dest, command, cb, write, filename } = (0, import_shared.defu)(options, {
|
|
987
1011
|
write: true,
|
|
@@ -1025,67 +1049,10 @@ async function createOrUpdatePackageJson(options) {
|
|
|
1025
1049
|
throw error;
|
|
1026
1050
|
}
|
|
1027
1051
|
}
|
|
1028
|
-
async function upsertDependencyVersion(packageJson, keyPath, packageName, options = {}) {
|
|
1029
|
-
const currentValue = (0, import_shared.get)(packageJson, keyPath);
|
|
1030
|
-
const resolved = options.skipNetwork ? null : await latestVersion(packageName);
|
|
1031
|
-
if (resolved) {
|
|
1032
|
-
(0, import_shared.set)(packageJson, keyPath, resolved);
|
|
1033
|
-
return;
|
|
1034
|
-
}
|
|
1035
|
-
if (currentValue === void 0) {
|
|
1036
|
-
const fallback = FALLBACK_DEP_VERSIONS[packageName] ?? "latest";
|
|
1037
|
-
(0, import_shared.set)(packageJson, keyPath, fallback);
|
|
1038
|
-
}
|
|
1039
|
-
}
|
|
1040
|
-
function createDefaultPackageJson() {
|
|
1041
|
-
return {
|
|
1042
|
-
name: "weapp-vite-app",
|
|
1043
|
-
homepage: "https://vite.icebreaker.top/",
|
|
1044
|
-
type: "module",
|
|
1045
|
-
scripts: {},
|
|
1046
|
-
devDependencies: {}
|
|
1047
|
-
};
|
|
1048
|
-
}
|
|
1049
1052
|
|
|
1050
1053
|
// src/projectConfig.ts
|
|
1051
1054
|
var import_logger5 = __toESM(require("@weapp-core/logger"), 1);
|
|
1052
1055
|
var import_shared2 = require("@weapp-core/shared");
|
|
1053
|
-
async function createOrUpdateProjectConfig(options) {
|
|
1054
|
-
const { root, dest, cb, write, filename } = (0, import_shared2.defu)(
|
|
1055
|
-
options,
|
|
1056
|
-
{
|
|
1057
|
-
write: true,
|
|
1058
|
-
filename: "project.config.json"
|
|
1059
|
-
}
|
|
1060
|
-
);
|
|
1061
|
-
const projectConfigFilename = ctx.projectConfig.name = filename;
|
|
1062
|
-
const projectConfigPath = ctx.projectConfig.path = posix.resolve(root, projectConfigFilename);
|
|
1063
|
-
const outputPath = resolveOutputPath(root, dest, projectConfigPath);
|
|
1064
|
-
try {
|
|
1065
|
-
let projectConfig = await readJsonIfExists(projectConfigPath);
|
|
1066
|
-
if (projectConfig) {
|
|
1067
|
-
applyProjectConfigDefaults(projectConfig);
|
|
1068
|
-
} else {
|
|
1069
|
-
projectConfig = createDefaultProjectConfig();
|
|
1070
|
-
import_logger5.default.info(`\u2728 \u6CA1\u6709\u627E\u5230 ${projectConfigFilename} \u6587\u4EF6\uFF0C\u6B63\u5728\u4F7F\u7528\u9ED8\u8BA4\u6A21\u677F\u521B\u5EFA...`);
|
|
1071
|
-
}
|
|
1072
|
-
cb?.(
|
|
1073
|
-
(...args) => {
|
|
1074
|
-
(0, import_shared2.set)(projectConfig, ...args);
|
|
1075
|
-
}
|
|
1076
|
-
);
|
|
1077
|
-
ensurePackNpmRelationList(projectConfig);
|
|
1078
|
-
ctx.projectConfig.value = projectConfig;
|
|
1079
|
-
if (write) {
|
|
1080
|
-
await writeJsonFile(outputPath, projectConfig);
|
|
1081
|
-
import_logger5.default.log(`\u2728 \u5199\u5165 ${posix.relative(root, outputPath)} \u6210\u529F!`);
|
|
1082
|
-
}
|
|
1083
|
-
return projectConfig;
|
|
1084
|
-
} catch (error) {
|
|
1085
|
-
import_logger5.default.error(`\u26A0\uFE0F \u8BBE\u7F6E ${projectConfigFilename} \u914D\u7F6E\u6587\u4EF6\u5931\u8D25`, error);
|
|
1086
|
-
throw error;
|
|
1087
|
-
}
|
|
1088
|
-
}
|
|
1089
1056
|
function applyProjectConfigDefaults(projectConfig) {
|
|
1090
1057
|
(0, import_shared2.set)(projectConfig, "miniprogramRoot", "dist/");
|
|
1091
1058
|
(0, import_shared2.set)(projectConfig, "srcMiniprogramRoot", "dist/");
|
|
@@ -1150,6 +1117,42 @@ function createDefaultProjectConfig() {
|
|
|
1150
1117
|
srcMiniprogramRoot: "dist/"
|
|
1151
1118
|
};
|
|
1152
1119
|
}
|
|
1120
|
+
async function createOrUpdateProjectConfig(options) {
|
|
1121
|
+
const { root, dest, cb, write, filename } = (0, import_shared2.defu)(
|
|
1122
|
+
options,
|
|
1123
|
+
{
|
|
1124
|
+
write: true,
|
|
1125
|
+
filename: "project.config.json"
|
|
1126
|
+
}
|
|
1127
|
+
);
|
|
1128
|
+
const projectConfigFilename = ctx.projectConfig.name = filename;
|
|
1129
|
+
const projectConfigPath = ctx.projectConfig.path = posix.resolve(root, projectConfigFilename);
|
|
1130
|
+
const outputPath = resolveOutputPath(root, dest, projectConfigPath);
|
|
1131
|
+
try {
|
|
1132
|
+
let projectConfig = await readJsonIfExists(projectConfigPath);
|
|
1133
|
+
if (projectConfig) {
|
|
1134
|
+
applyProjectConfigDefaults(projectConfig);
|
|
1135
|
+
} else {
|
|
1136
|
+
projectConfig = createDefaultProjectConfig();
|
|
1137
|
+
import_logger5.default.info(`\u2728 \u6CA1\u6709\u627E\u5230 ${projectConfigFilename} \u6587\u4EF6\uFF0C\u6B63\u5728\u4F7F\u7528\u9ED8\u8BA4\u6A21\u677F\u521B\u5EFA...`);
|
|
1138
|
+
}
|
|
1139
|
+
cb?.(
|
|
1140
|
+
(...args) => {
|
|
1141
|
+
(0, import_shared2.set)(projectConfig, ...args);
|
|
1142
|
+
}
|
|
1143
|
+
);
|
|
1144
|
+
ensurePackNpmRelationList(projectConfig);
|
|
1145
|
+
ctx.projectConfig.value = projectConfig;
|
|
1146
|
+
if (write) {
|
|
1147
|
+
await writeJsonFile(outputPath, projectConfig);
|
|
1148
|
+
import_logger5.default.log(`\u2728 \u5199\u5165 ${posix.relative(root, outputPath)} \u6210\u529F!`);
|
|
1149
|
+
}
|
|
1150
|
+
return projectConfig;
|
|
1151
|
+
} catch (error) {
|
|
1152
|
+
import_logger5.default.error(`\u26A0\uFE0F \u8BBE\u7F6E ${projectConfigFilename} \u914D\u7F6E\u6587\u4EF6\u5931\u8D25`, error);
|
|
1153
|
+
throw error;
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1153
1156
|
|
|
1154
1157
|
// src/index.ts
|
|
1155
1158
|
async function initConfig(options) {
|
package/dist/index.js
CHANGED
|
@@ -423,6 +423,13 @@ var posix = /* @__PURE__ */ mix(":");
|
|
|
423
423
|
var win32 = /* @__PURE__ */ mix(";");
|
|
424
424
|
|
|
425
425
|
// src/context.ts
|
|
426
|
+
function createDocument() {
|
|
427
|
+
return {
|
|
428
|
+
name: "",
|
|
429
|
+
path: "",
|
|
430
|
+
value: null
|
|
431
|
+
};
|
|
432
|
+
}
|
|
426
433
|
function createContext() {
|
|
427
434
|
return {
|
|
428
435
|
projectConfig: createDocument(),
|
|
@@ -434,13 +441,6 @@ function createContext() {
|
|
|
434
441
|
dts: createDocument()
|
|
435
442
|
};
|
|
436
443
|
}
|
|
437
|
-
function createDocument() {
|
|
438
|
-
return {
|
|
439
|
-
name: "",
|
|
440
|
-
path: "",
|
|
441
|
-
value: null
|
|
442
|
-
};
|
|
443
|
-
}
|
|
444
444
|
|
|
445
445
|
// src/state.ts
|
|
446
446
|
var ctx = createContext();
|
|
@@ -720,7 +720,7 @@ import logger3 from "@weapp-core/logger";
|
|
|
720
720
|
import fs2 from "fs-extra";
|
|
721
721
|
|
|
722
722
|
// ../../packages/weapp-vite/package.json
|
|
723
|
-
var version = "5.
|
|
723
|
+
var version = "5.10.0";
|
|
724
724
|
|
|
725
725
|
// src/enums.ts
|
|
726
726
|
var TemplateName = /* @__PURE__ */ ((TemplateName2) => {
|
|
@@ -761,10 +761,13 @@ function getLatestVersionFromNpm(packageName) {
|
|
|
761
761
|
}).on("error", reject);
|
|
762
762
|
});
|
|
763
763
|
}
|
|
764
|
-
async function latestVersion(packageName, prefix = "^") {
|
|
764
|
+
async function latestVersion(packageName, prefix = "^", fetch = getLatestVersionFromNpm) {
|
|
765
765
|
try {
|
|
766
|
-
const resolved = await
|
|
767
|
-
|
|
766
|
+
const resolved = await fetch(packageName);
|
|
767
|
+
if (!resolved) {
|
|
768
|
+
return null;
|
|
769
|
+
}
|
|
770
|
+
return `${prefix}${resolved}`;
|
|
768
771
|
} catch {
|
|
769
772
|
return null;
|
|
770
773
|
}
|
|
@@ -810,6 +813,20 @@ dist
|
|
|
810
813
|
dist-plugin
|
|
811
814
|
dist-web
|
|
812
815
|
vite.config.ts.timestamp-*.mjs`;
|
|
816
|
+
function normalizeLineEndings(value) {
|
|
817
|
+
return value.replace(/\r\n/g, "\n");
|
|
818
|
+
}
|
|
819
|
+
function trimTrailingBlankLines(lines) {
|
|
820
|
+
let end = lines.length;
|
|
821
|
+
while (end > 0 && lines[end - 1] === "") {
|
|
822
|
+
end -= 1;
|
|
823
|
+
}
|
|
824
|
+
return lines.slice(0, end);
|
|
825
|
+
}
|
|
826
|
+
function ensureTrailingNewline(value) {
|
|
827
|
+
return value.endsWith("\n") ? value : `${value}
|
|
828
|
+
`;
|
|
829
|
+
}
|
|
813
830
|
function mergeGitignore(existing) {
|
|
814
831
|
const normalizedExisting = normalizeLineEndings(existing ?? "");
|
|
815
832
|
const existingLines = normalizedExisting.length ? normalizedExisting.split("\n") : [];
|
|
@@ -840,20 +857,6 @@ function mergeGitignore(existing) {
|
|
|
840
857
|
}
|
|
841
858
|
return ensureTrailingNewline(trimTrailingBlankLines(merged).join("\n"));
|
|
842
859
|
}
|
|
843
|
-
function normalizeLineEndings(value) {
|
|
844
|
-
return value.replace(/\r\n/g, "\n");
|
|
845
|
-
}
|
|
846
|
-
function trimTrailingBlankLines(lines) {
|
|
847
|
-
let end = lines.length;
|
|
848
|
-
while (end > 0 && lines[end - 1] === "") {
|
|
849
|
-
end -= 1;
|
|
850
|
-
}
|
|
851
|
-
return lines.slice(0, end);
|
|
852
|
-
}
|
|
853
|
-
function ensureTrailingNewline(value) {
|
|
854
|
-
return value.endsWith("\n") ? value : `${value}
|
|
855
|
-
`;
|
|
856
|
-
}
|
|
857
860
|
|
|
858
861
|
// src/updateGitignore.ts
|
|
859
862
|
async function updateGitIgnore(options) {
|
|
@@ -871,6 +874,38 @@ async function updateGitIgnore(options) {
|
|
|
871
874
|
|
|
872
875
|
// src/createProject.ts
|
|
873
876
|
var moduleDir = posix.dirname(fileURLToPath(import.meta.url));
|
|
877
|
+
async function ensureDotGitignore(root) {
|
|
878
|
+
const gitignorePath = posix.resolve(root, "gitignore");
|
|
879
|
+
const dotGitignorePath = posix.resolve(root, ".gitignore");
|
|
880
|
+
if (!await fs2.pathExists(gitignorePath)) {
|
|
881
|
+
return;
|
|
882
|
+
}
|
|
883
|
+
if (await fs2.pathExists(dotGitignorePath)) {
|
|
884
|
+
await fs2.remove(gitignorePath);
|
|
885
|
+
return;
|
|
886
|
+
}
|
|
887
|
+
await fs2.move(gitignorePath, dotGitignorePath);
|
|
888
|
+
}
|
|
889
|
+
function createEmptyPackageJson() {
|
|
890
|
+
return {
|
|
891
|
+
name: "weapp-vite-app",
|
|
892
|
+
homepage: "https://vite.icebreaker.top/",
|
|
893
|
+
type: "module",
|
|
894
|
+
scripts: {},
|
|
895
|
+
devDependencies: {}
|
|
896
|
+
};
|
|
897
|
+
}
|
|
898
|
+
async function upsertTailwindcssVersion(pkgJson) {
|
|
899
|
+
if (!pkgJson.devDependencies) {
|
|
900
|
+
return;
|
|
901
|
+
}
|
|
902
|
+
const resolved = await latestVersion("weapp-tailwindcss");
|
|
903
|
+
if (resolved) {
|
|
904
|
+
pkgJson.devDependencies["weapp-tailwindcss"] = resolved;
|
|
905
|
+
} else if (!pkgJson.devDependencies["weapp-tailwindcss"]) {
|
|
906
|
+
pkgJson.devDependencies["weapp-tailwindcss"] = "^4.3.3";
|
|
907
|
+
}
|
|
908
|
+
}
|
|
874
909
|
async function createProject(targetDir = "", templateName = "default" /* default */) {
|
|
875
910
|
const targetTemplateDir = posix.resolve(moduleDir, "../templates", templateName);
|
|
876
911
|
if (!await fs2.pathExists(targetTemplateDir)) {
|
|
@@ -893,18 +928,16 @@ async function createProject(targetDir = "", templateName = "default" /* default
|
|
|
893
928
|
await updateGitIgnore({ root: targetDir, write: true });
|
|
894
929
|
logger3.log("\u2728 \u521B\u5EFA\u6A21\u677F\u6210\u529F!");
|
|
895
930
|
}
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
}
|
|
907
|
-
function createEmptyPackageJson() {
|
|
931
|
+
|
|
932
|
+
// src/packageJson.ts
|
|
933
|
+
import logger4 from "@weapp-core/logger";
|
|
934
|
+
import { defu, get, set } from "@weapp-core/shared";
|
|
935
|
+
var FALLBACK_DEP_VERSIONS = {
|
|
936
|
+
"miniprogram-api-typings": "^4.1.0",
|
|
937
|
+
"typescript": "^5.9.2",
|
|
938
|
+
"weapp-tailwindcss": "^4.3.3"
|
|
939
|
+
};
|
|
940
|
+
function createDefaultPackageJson() {
|
|
908
941
|
return {
|
|
909
942
|
name: "weapp-vite-app",
|
|
910
943
|
homepage: "https://vite.icebreaker.top/",
|
|
@@ -913,27 +946,18 @@ function createEmptyPackageJson() {
|
|
|
913
946
|
devDependencies: {}
|
|
914
947
|
};
|
|
915
948
|
}
|
|
916
|
-
async function
|
|
917
|
-
const
|
|
918
|
-
const
|
|
919
|
-
if (
|
|
949
|
+
async function upsertDependencyVersion(packageJson, keyPath, packageName, options = {}) {
|
|
950
|
+
const currentValue = get(packageJson, keyPath);
|
|
951
|
+
const resolved = options.skipNetwork ? null : await latestVersion(packageName);
|
|
952
|
+
if (resolved) {
|
|
953
|
+
set(packageJson, keyPath, resolved);
|
|
920
954
|
return;
|
|
921
955
|
}
|
|
922
|
-
if (
|
|
923
|
-
|
|
924
|
-
|
|
956
|
+
if (currentValue === void 0) {
|
|
957
|
+
const fallback = FALLBACK_DEP_VERSIONS[packageName] ?? "latest";
|
|
958
|
+
set(packageJson, keyPath, fallback);
|
|
925
959
|
}
|
|
926
|
-
await fs2.move(gitignorePath, dotGitignorePath);
|
|
927
960
|
}
|
|
928
|
-
|
|
929
|
-
// src/packageJson.ts
|
|
930
|
-
import logger4 from "@weapp-core/logger";
|
|
931
|
-
import { defu, get, set } from "@weapp-core/shared";
|
|
932
|
-
var FALLBACK_DEP_VERSIONS = {
|
|
933
|
-
"miniprogram-api-typings": "^4.1.0",
|
|
934
|
-
"typescript": "^5.9.2",
|
|
935
|
-
"weapp-tailwindcss": "^4.3.3"
|
|
936
|
-
};
|
|
937
961
|
async function createOrUpdatePackageJson(options) {
|
|
938
962
|
const { root, dest, command, cb, write, filename } = defu(options, {
|
|
939
963
|
write: true,
|
|
@@ -977,67 +1001,10 @@ async function createOrUpdatePackageJson(options) {
|
|
|
977
1001
|
throw error;
|
|
978
1002
|
}
|
|
979
1003
|
}
|
|
980
|
-
async function upsertDependencyVersion(packageJson, keyPath, packageName, options = {}) {
|
|
981
|
-
const currentValue = get(packageJson, keyPath);
|
|
982
|
-
const resolved = options.skipNetwork ? null : await latestVersion(packageName);
|
|
983
|
-
if (resolved) {
|
|
984
|
-
set(packageJson, keyPath, resolved);
|
|
985
|
-
return;
|
|
986
|
-
}
|
|
987
|
-
if (currentValue === void 0) {
|
|
988
|
-
const fallback = FALLBACK_DEP_VERSIONS[packageName] ?? "latest";
|
|
989
|
-
set(packageJson, keyPath, fallback);
|
|
990
|
-
}
|
|
991
|
-
}
|
|
992
|
-
function createDefaultPackageJson() {
|
|
993
|
-
return {
|
|
994
|
-
name: "weapp-vite-app",
|
|
995
|
-
homepage: "https://vite.icebreaker.top/",
|
|
996
|
-
type: "module",
|
|
997
|
-
scripts: {},
|
|
998
|
-
devDependencies: {}
|
|
999
|
-
};
|
|
1000
|
-
}
|
|
1001
1004
|
|
|
1002
1005
|
// src/projectConfig.ts
|
|
1003
1006
|
import logger5 from "@weapp-core/logger";
|
|
1004
1007
|
import { defu as defu2, get as get2, set as set2 } from "@weapp-core/shared";
|
|
1005
|
-
async function createOrUpdateProjectConfig(options) {
|
|
1006
|
-
const { root, dest, cb, write, filename } = defu2(
|
|
1007
|
-
options,
|
|
1008
|
-
{
|
|
1009
|
-
write: true,
|
|
1010
|
-
filename: "project.config.json"
|
|
1011
|
-
}
|
|
1012
|
-
);
|
|
1013
|
-
const projectConfigFilename = ctx.projectConfig.name = filename;
|
|
1014
|
-
const projectConfigPath = ctx.projectConfig.path = posix.resolve(root, projectConfigFilename);
|
|
1015
|
-
const outputPath = resolveOutputPath(root, dest, projectConfigPath);
|
|
1016
|
-
try {
|
|
1017
|
-
let projectConfig = await readJsonIfExists(projectConfigPath);
|
|
1018
|
-
if (projectConfig) {
|
|
1019
|
-
applyProjectConfigDefaults(projectConfig);
|
|
1020
|
-
} else {
|
|
1021
|
-
projectConfig = createDefaultProjectConfig();
|
|
1022
|
-
logger5.info(`\u2728 \u6CA1\u6709\u627E\u5230 ${projectConfigFilename} \u6587\u4EF6\uFF0C\u6B63\u5728\u4F7F\u7528\u9ED8\u8BA4\u6A21\u677F\u521B\u5EFA...`);
|
|
1023
|
-
}
|
|
1024
|
-
cb?.(
|
|
1025
|
-
(...args) => {
|
|
1026
|
-
set2(projectConfig, ...args);
|
|
1027
|
-
}
|
|
1028
|
-
);
|
|
1029
|
-
ensurePackNpmRelationList(projectConfig);
|
|
1030
|
-
ctx.projectConfig.value = projectConfig;
|
|
1031
|
-
if (write) {
|
|
1032
|
-
await writeJsonFile(outputPath, projectConfig);
|
|
1033
|
-
logger5.log(`\u2728 \u5199\u5165 ${posix.relative(root, outputPath)} \u6210\u529F!`);
|
|
1034
|
-
}
|
|
1035
|
-
return projectConfig;
|
|
1036
|
-
} catch (error) {
|
|
1037
|
-
logger5.error(`\u26A0\uFE0F \u8BBE\u7F6E ${projectConfigFilename} \u914D\u7F6E\u6587\u4EF6\u5931\u8D25`, error);
|
|
1038
|
-
throw error;
|
|
1039
|
-
}
|
|
1040
|
-
}
|
|
1041
1008
|
function applyProjectConfigDefaults(projectConfig) {
|
|
1042
1009
|
set2(projectConfig, "miniprogramRoot", "dist/");
|
|
1043
1010
|
set2(projectConfig, "srcMiniprogramRoot", "dist/");
|
|
@@ -1102,6 +1069,42 @@ function createDefaultProjectConfig() {
|
|
|
1102
1069
|
srcMiniprogramRoot: "dist/"
|
|
1103
1070
|
};
|
|
1104
1071
|
}
|
|
1072
|
+
async function createOrUpdateProjectConfig(options) {
|
|
1073
|
+
const { root, dest, cb, write, filename } = defu2(
|
|
1074
|
+
options,
|
|
1075
|
+
{
|
|
1076
|
+
write: true,
|
|
1077
|
+
filename: "project.config.json"
|
|
1078
|
+
}
|
|
1079
|
+
);
|
|
1080
|
+
const projectConfigFilename = ctx.projectConfig.name = filename;
|
|
1081
|
+
const projectConfigPath = ctx.projectConfig.path = posix.resolve(root, projectConfigFilename);
|
|
1082
|
+
const outputPath = resolveOutputPath(root, dest, projectConfigPath);
|
|
1083
|
+
try {
|
|
1084
|
+
let projectConfig = await readJsonIfExists(projectConfigPath);
|
|
1085
|
+
if (projectConfig) {
|
|
1086
|
+
applyProjectConfigDefaults(projectConfig);
|
|
1087
|
+
} else {
|
|
1088
|
+
projectConfig = createDefaultProjectConfig();
|
|
1089
|
+
logger5.info(`\u2728 \u6CA1\u6709\u627E\u5230 ${projectConfigFilename} \u6587\u4EF6\uFF0C\u6B63\u5728\u4F7F\u7528\u9ED8\u8BA4\u6A21\u677F\u521B\u5EFA...`);
|
|
1090
|
+
}
|
|
1091
|
+
cb?.(
|
|
1092
|
+
(...args) => {
|
|
1093
|
+
set2(projectConfig, ...args);
|
|
1094
|
+
}
|
|
1095
|
+
);
|
|
1096
|
+
ensurePackNpmRelationList(projectConfig);
|
|
1097
|
+
ctx.projectConfig.value = projectConfig;
|
|
1098
|
+
if (write) {
|
|
1099
|
+
await writeJsonFile(outputPath, projectConfig);
|
|
1100
|
+
logger5.log(`\u2728 \u5199\u5165 ${posix.relative(root, outputPath)} \u6210\u529F!`);
|
|
1101
|
+
}
|
|
1102
|
+
return projectConfig;
|
|
1103
|
+
} catch (error) {
|
|
1104
|
+
logger5.error(`\u26A0\uFE0F \u8BBE\u7F6E ${projectConfigFilename} \u914D\u7F6E\u6587\u4EF6\u5931\u8D25`, error);
|
|
1105
|
+
throw error;
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1105
1108
|
|
|
1106
1109
|
// src/index.ts
|
|
1107
1110
|
async function initConfig(options) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-core/init",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.0.
|
|
4
|
+
"version": "3.0.5",
|
|
5
5
|
"description": "@weapp-core/init",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"fs-extra": "^11.3.2",
|
|
42
|
-
"@weapp-core/
|
|
43
|
-
"@weapp-core/
|
|
42
|
+
"@weapp-core/shared": "^2.0.1",
|
|
43
|
+
"@weapp-core/logger": "^2.0.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/semver": "^7.7.1",
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"autoprefixer": "^10.4.22",
|
|
30
30
|
"miniprogram-api-typings": "^4.1.0",
|
|
31
31
|
"postcss": "^8.5.6",
|
|
32
|
-
"sass": "^1.94.
|
|
32
|
+
"sass": "^1.94.2",
|
|
33
33
|
"tailwindcss": "^3.4.18",
|
|
34
34
|
"typescript": "^5.9.3",
|
|
35
|
-
"weapp-tailwindcss": "^4.
|
|
35
|
+
"weapp-tailwindcss": "^4.8.4",
|
|
36
36
|
"weapp-vite": "workspace:*"
|
|
37
37
|
}
|
|
38
38
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
<view class="w-full max-w-[600rpx] mx-auto rounded-3xl p-8 bg-white/90 shadow-xl shadow-sky-200/40 dark:bg-slate-800/90 dark:shadow-slate-900/60 flex flex-col gap-
|
|
2
|
-
<view class="text-
|
|
3
|
-
<view class="text-
|
|
1
|
+
<view class="w-full max-w-[600rpx] mx-auto rounded-3xl p-8 bg-white/90 shadow-xl shadow-sky-200/40 dark:bg-slate-800/90 dark:shadow-slate-900/60 flex flex-col gap-2">
|
|
2
|
+
<view class="text-xl font-semibold text-sky-500 dark:text-sky-300">{{title}}</view>
|
|
3
|
+
<view class="text-xs leading-relaxed text-slate-700 dark:text-slate-200">{{description}}</view>
|
|
4
4
|
<view wx:if="{{links.length}}" class="flex flex-wrap gap-4">
|
|
5
5
|
<view
|
|
6
6
|
wx:for="{{links}}"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<view class="min-h-screen {{ mode === 'light'?'bg-gray-100 text-slate-800':'bg-gray-900 text-slate-200' }} transition-colors duration-500">
|
|
2
|
-
<view class="flex flex-col items-center pt-
|
|
2
|
+
<view class="flex flex-col items-center pt-6 space-y-4">
|
|
3
3
|
<view class="flex space-x-8">
|
|
4
4
|
<view class="w-24 h-24 bg-[url(https://vite.icebreaker.top/logo.png)] bg-[length:100%_100%] bg-no-repeat"></view>
|
|
5
5
|
<view class="w-32 h-24 bg-[url(https://vite.icebreaker.top/tw-logo.png)] bg-[length:100%_100%] bg-no-repeat"></view>
|
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
<view class="bg-gradient-to-r from-green-400 to-sky-400 bg-clip-text text-xl font-extrabold text-transparent underline">
|
|
8
8
|
weapp-vite & weapp-tailwindcss
|
|
9
9
|
</view>
|
|
10
|
-
<
|
|
11
|
-
title="{{hello.title}}"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
<view>
|
|
11
|
+
<HelloWorld title="{{hello.title}}" description="{{hello.description}}" docs="{{hello.docs}}" links="{{hello.links}}" />
|
|
12
|
+
</view>
|
|
13
|
+
<view class="flex items-center">
|
|
14
|
+
<text>切换模式</text>
|
|
15
|
+
<view class="{{ mode === 'light' ? 'i-mdi-moon-waxing-crescent':'i-mdi-weather-sunny text-white' }} text-4xl" bind:tap="switchMode"></view>
|
|
16
|
+
</view>
|
|
17
17
|
<view class="underline" mark:url="https://vite.icebreaker.top" bind:tap="copy">
|
|
18
18
|
https://vite.icebreaker.top
|
|
19
19
|
</view>
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
<view class="min-h-screen bg-gray-100 py-16">
|
|
2
|
-
<view class="flex flex-col items-center space-y-
|
|
3
|
-
<
|
|
2
|
+
<view class="flex flex-col items-center space-y-5">
|
|
3
|
+
<view>
|
|
4
|
+
<image class="w-[200px] h-[190px]" src="/logo.png" />
|
|
5
|
+
</view>
|
|
4
6
|
<view class="text-lg font-semibold" bind:tap="onClick">ice breaker</view>
|
|
5
|
-
<
|
|
6
|
-
title="{{hello.title}}"
|
|
7
|
-
|
|
8
|
-
docs="{{hello.docs}}"
|
|
9
|
-
links="{{hello.links}}"
|
|
10
|
-
/>
|
|
7
|
+
<view>
|
|
8
|
+
<HelloWorld title="{{hello.title}}" description="{{hello.description}}" docs="{{hello.docs}}" links="{{hello.links}}" />
|
|
9
|
+
</view>
|
|
11
10
|
</view>
|
|
12
11
|
</view>
|
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
"autoprefixer": "^10.4.22",
|
|
33
33
|
"miniprogram-api-typings": "^4.1.0",
|
|
34
34
|
"postcss": "^8.5.6",
|
|
35
|
-
"sass": "^1.94.
|
|
35
|
+
"sass": "^1.94.2",
|
|
36
36
|
"tailwindcss": "^3.4.18",
|
|
37
37
|
"typescript": "^5.9.3",
|
|
38
|
-
"weapp-tailwindcss": "^4.
|
|
38
|
+
"weapp-tailwindcss": "^4.8.4",
|
|
39
39
|
"weapp-vite": "workspace:*"
|
|
40
40
|
}
|
|
41
41
|
}
|
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
"autoprefixer": "^10.4.22",
|
|
33
33
|
"miniprogram-api-typings": "^4.1.0",
|
|
34
34
|
"postcss": "^8.5.6",
|
|
35
|
-
"sass": "^1.94.
|
|
35
|
+
"sass": "^1.94.2",
|
|
36
36
|
"tailwindcss": "^3.4.18",
|
|
37
37
|
"typescript": "^5.9.3",
|
|
38
|
-
"weapp-tailwindcss": "^4.
|
|
38
|
+
"weapp-tailwindcss": "^4.8.4",
|
|
39
39
|
"weapp-vite": "workspace:*"
|
|
40
40
|
}
|
|
41
41
|
}
|