@weapp-core/init 2.1.4 → 3.0.0-alpha.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/dist/index.cjs +491 -303
- package/dist/index.d.cts +71 -41
- package/dist/index.d.ts +71 -41
- package/dist/index.js +488 -301
- package/package.json +4 -3
- package/templates/default/gitignore +34 -0
- package/templates/default/package.json +2 -2
- package/templates/tailwindcss/gitignore +34 -0
- package/templates/tailwindcss/package.json +3 -3
- package/templates/tdesign/gitignore +34 -0
- package/templates/tdesign/package.json +3 -3
- package/templates/vant/gitignore +34 -0
- package/templates/vant/package.json +3 -3
- package/templates/default/CHANGELOG.md +0 -9
- package/templates/tailwindcss/CHANGELOG.md +0 -9
- package/templates/tdesign/CHANGELOG.md +0 -9
- package/templates/vant/CHANGELOG.md +0 -9
package/dist/index.cjs
CHANGED
|
@@ -37,20 +37,20 @@ __export(index_exports, {
|
|
|
37
37
|
initConfig: () => initConfig,
|
|
38
38
|
initTsDtsFile: () => initTsDtsFile,
|
|
39
39
|
initTsJsonFiles: () => initTsJsonFiles,
|
|
40
|
-
initViteConfigFile: () => initViteConfigFile
|
|
40
|
+
initViteConfigFile: () => initViteConfigFile,
|
|
41
|
+
resetContext: () => resetContext
|
|
41
42
|
});
|
|
42
43
|
module.exports = __toCommonJS(index_exports);
|
|
43
44
|
|
|
44
|
-
// ../../node_modules/.pnpm/tsup@8.5.0_@swc+core@1.13.
|
|
45
|
+
// ../../node_modules/.pnpm/tsup@8.5.0_@swc+core@1.13.19_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
|
|
45
46
|
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
46
47
|
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
47
48
|
|
|
48
49
|
// src/index.ts
|
|
49
50
|
var import_node_process = __toESM(require("process"), 1);
|
|
50
|
-
|
|
51
|
+
|
|
52
|
+
// src/configFiles.ts
|
|
51
53
|
var import_logger = __toESM(require("@weapp-core/logger"), 1);
|
|
52
|
-
var import_shared = require("@weapp-core/shared");
|
|
53
|
-
var import_fs_extra = __toESM(require("fs-extra"), 1);
|
|
54
54
|
|
|
55
55
|
// ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
|
|
56
56
|
var _lazyMatch = () => {
|
|
@@ -470,119 +470,35 @@ var mix = (del = delimiter) => {
|
|
|
470
470
|
var posix = /* @__PURE__ */ mix(":");
|
|
471
471
|
var win32 = /* @__PURE__ */ mix(";");
|
|
472
472
|
|
|
473
|
-
// ../../packages/weapp-vite/package.json
|
|
474
|
-
var version = "5.1.7";
|
|
475
|
-
|
|
476
473
|
// src/context.ts
|
|
477
474
|
function createContext() {
|
|
478
475
|
return {
|
|
479
|
-
projectConfig:
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
name: "",
|
|
486
|
-
path: "",
|
|
487
|
-
value: {}
|
|
488
|
-
},
|
|
489
|
-
viteConfig: {
|
|
490
|
-
name: "",
|
|
491
|
-
path: "",
|
|
492
|
-
value: ""
|
|
493
|
-
},
|
|
494
|
-
tsconfig: {
|
|
495
|
-
name: "",
|
|
496
|
-
path: "",
|
|
497
|
-
value: {}
|
|
498
|
-
},
|
|
499
|
-
tsconfigNode: {
|
|
500
|
-
name: "",
|
|
501
|
-
path: "",
|
|
502
|
-
value: {}
|
|
503
|
-
},
|
|
504
|
-
dts: {
|
|
505
|
-
name: "",
|
|
506
|
-
path: "",
|
|
507
|
-
value: ""
|
|
508
|
-
}
|
|
476
|
+
projectConfig: createDocument(),
|
|
477
|
+
packageJson: createDocument(),
|
|
478
|
+
viteConfig: createDocument(),
|
|
479
|
+
tsconfig: createDocument(),
|
|
480
|
+
tsconfigNode: createDocument(),
|
|
481
|
+
dts: createDocument()
|
|
509
482
|
};
|
|
510
483
|
}
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
TemplateName2["tdesign"] = "tdesign";
|
|
518
|
-
return TemplateName2;
|
|
519
|
-
})(TemplateName || {});
|
|
520
|
-
|
|
521
|
-
// src/gitignore.ts
|
|
522
|
-
function getDefaultGitignore() {
|
|
523
|
-
return `# dependencies
|
|
524
|
-
node_modules
|
|
525
|
-
.pnp
|
|
526
|
-
.pnp.js
|
|
527
|
-
|
|
528
|
-
# testing
|
|
529
|
-
coverage
|
|
530
|
-
|
|
531
|
-
# next.js
|
|
532
|
-
.next/
|
|
533
|
-
out/
|
|
534
|
-
build
|
|
535
|
-
|
|
536
|
-
# misc
|
|
537
|
-
.DS_Store
|
|
538
|
-
*.pem
|
|
539
|
-
|
|
540
|
-
# debug
|
|
541
|
-
npm-debug.log*
|
|
542
|
-
yarn-debug.log*
|
|
543
|
-
yarn-error.log*
|
|
544
|
-
.pnpm-debug.log*
|
|
545
|
-
|
|
546
|
-
# local env files
|
|
547
|
-
.env.local
|
|
548
|
-
.env.development.local
|
|
549
|
-
.env.test.local
|
|
550
|
-
.env.production.local
|
|
551
|
-
|
|
552
|
-
# turbo
|
|
553
|
-
.turbo
|
|
554
|
-
|
|
555
|
-
dist
|
|
556
|
-
dist-plugin
|
|
557
|
-
vite.config.ts.timestamp-*.mjs`;
|
|
484
|
+
function createDocument() {
|
|
485
|
+
return {
|
|
486
|
+
name: "",
|
|
487
|
+
path: "",
|
|
488
|
+
value: null
|
|
489
|
+
};
|
|
558
490
|
}
|
|
559
491
|
|
|
560
|
-
// src/
|
|
561
|
-
var
|
|
562
|
-
function
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
const json = JSON.parse(data);
|
|
571
|
-
resolve2(json.version);
|
|
572
|
-
} catch (err) {
|
|
573
|
-
reject(err);
|
|
574
|
-
}
|
|
575
|
-
});
|
|
576
|
-
}).on("error", reject);
|
|
577
|
-
});
|
|
578
|
-
}
|
|
579
|
-
async function latestVersion(packageName, prefix = "^") {
|
|
580
|
-
let version2 = "latest";
|
|
581
|
-
try {
|
|
582
|
-
version2 = `${prefix}${await getLatestVersionFromNpm(packageName)}`;
|
|
583
|
-
} catch {
|
|
584
|
-
}
|
|
585
|
-
return version2;
|
|
492
|
+
// src/state.ts
|
|
493
|
+
var ctx = createContext();
|
|
494
|
+
function resetContext() {
|
|
495
|
+
const next = createContext();
|
|
496
|
+
Object.assign(ctx.projectConfig, next.projectConfig);
|
|
497
|
+
Object.assign(ctx.packageJson, next.packageJson);
|
|
498
|
+
Object.assign(ctx.viteConfig, next.viteConfig);
|
|
499
|
+
Object.assign(ctx.tsconfig, next.tsconfig);
|
|
500
|
+
Object.assign(ctx.tsconfigNode, next.tsconfigNode);
|
|
501
|
+
Object.assign(ctx.dts, next.dts);
|
|
586
502
|
}
|
|
587
503
|
|
|
588
504
|
// src/tsconfigJson.ts
|
|
@@ -655,6 +571,69 @@ function getDefaultTsDts() {
|
|
|
655
571
|
`;
|
|
656
572
|
}
|
|
657
573
|
|
|
574
|
+
// src/utils/fs.ts
|
|
575
|
+
var import_fs_extra = __toESM(require("fs-extra"), 1);
|
|
576
|
+
async function readJsonIfExists(filepath) {
|
|
577
|
+
try {
|
|
578
|
+
if (!await import_fs_extra.default.pathExists(filepath)) {
|
|
579
|
+
return null;
|
|
580
|
+
}
|
|
581
|
+
return await import_fs_extra.default.readJSON(filepath);
|
|
582
|
+
} catch (error) {
|
|
583
|
+
throw new FsReadError(filepath, error);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
async function readFileIfExists(filepath) {
|
|
587
|
+
try {
|
|
588
|
+
if (!await import_fs_extra.default.pathExists(filepath)) {
|
|
589
|
+
return null;
|
|
590
|
+
}
|
|
591
|
+
return await import_fs_extra.default.readFile(filepath, "utf8");
|
|
592
|
+
} catch (error) {
|
|
593
|
+
throw new FsReadError(filepath, error);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
async function writeJsonFile(filepath, data, spaces = 2) {
|
|
597
|
+
try {
|
|
598
|
+
await import_fs_extra.default.outputJSON(filepath, data, {
|
|
599
|
+
spaces
|
|
600
|
+
});
|
|
601
|
+
} catch (error) {
|
|
602
|
+
throw new FsWriteError(filepath, error);
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
async function writeFile(filepath, contents) {
|
|
606
|
+
try {
|
|
607
|
+
await import_fs_extra.default.outputFile(filepath, contents, "utf8");
|
|
608
|
+
} catch (error) {
|
|
609
|
+
throw new FsWriteError(filepath, error);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
var FsReadError = class extends Error {
|
|
613
|
+
constructor(filepath, cause) {
|
|
614
|
+
super(`Failed to read ${filepath}`);
|
|
615
|
+
this.filepath = filepath;
|
|
616
|
+
this.cause = cause;
|
|
617
|
+
this.name = "FsReadError";
|
|
618
|
+
}
|
|
619
|
+
};
|
|
620
|
+
var FsWriteError = class extends Error {
|
|
621
|
+
constructor(filepath, cause) {
|
|
622
|
+
super(`Failed to write ${filepath}`);
|
|
623
|
+
this.filepath = filepath;
|
|
624
|
+
this.cause = cause;
|
|
625
|
+
this.name = "FsWriteError";
|
|
626
|
+
}
|
|
627
|
+
};
|
|
628
|
+
|
|
629
|
+
// src/utils/path.ts
|
|
630
|
+
function resolveOutputPath(root, dest, fallback) {
|
|
631
|
+
if (!dest) {
|
|
632
|
+
return fallback;
|
|
633
|
+
}
|
|
634
|
+
return posix.isAbsolute(dest) ? dest : posix.resolve(root, dest);
|
|
635
|
+
}
|
|
636
|
+
|
|
658
637
|
// src/viteConfig.ts
|
|
659
638
|
function getDefaultViteConfig() {
|
|
660
639
|
return `import { defineConfig } from 'weapp-vite/config'
|
|
@@ -667,104 +646,277 @@ export default defineConfig({
|
|
|
667
646
|
`;
|
|
668
647
|
}
|
|
669
648
|
|
|
670
|
-
// src/
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
const
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
649
|
+
// src/configFiles.ts
|
|
650
|
+
async function initViteConfigFile(options) {
|
|
651
|
+
const { root, dest, write = true } = options;
|
|
652
|
+
const packageType = ctx.packageJson.value?.type ?? "module";
|
|
653
|
+
const targetFilename = ctx.viteConfig.name = packageType === "module" ? "vite.config.ts" : "vite.config.mts";
|
|
654
|
+
const viteConfigFilePath = ctx.viteConfig.path = posix.resolve(root, targetFilename);
|
|
655
|
+
const outputPath = resolveOutputPath(root, dest, viteConfigFilePath);
|
|
656
|
+
const code = getDefaultViteConfig();
|
|
657
|
+
ctx.viteConfig.value = code;
|
|
658
|
+
if (write) {
|
|
659
|
+
await writeFile(outputPath, code);
|
|
660
|
+
import_logger.default.log(`\u2728 \u5199\u5165 ${posix.relative(root, outputPath)} \u6210\u529F!`);
|
|
661
|
+
}
|
|
662
|
+
return code;
|
|
663
|
+
}
|
|
664
|
+
async function initTsDtsFile(options) {
|
|
665
|
+
const { root, dest, write = true } = options;
|
|
666
|
+
const targetFilename = ctx.dts.name = "vite-env.d.ts";
|
|
667
|
+
const viteDtsFilePath = ctx.dts.path = posix.resolve(root, targetFilename);
|
|
668
|
+
const outputPath = resolveOutputPath(root, dest, viteDtsFilePath);
|
|
669
|
+
const code = getDefaultTsDts();
|
|
670
|
+
ctx.dts.value = code;
|
|
671
|
+
if (write) {
|
|
672
|
+
await writeFile(outputPath, code);
|
|
673
|
+
import_logger.default.log(`\u2728 \u5199\u5165 ${posix.relative(root, outputPath)} \u6210\u529F!`);
|
|
674
|
+
}
|
|
675
|
+
return code;
|
|
676
|
+
}
|
|
677
|
+
async function initTsJsonFiles(options) {
|
|
678
|
+
const { root, dest, write = true } = options;
|
|
679
|
+
const tsJsonFilename = ctx.tsconfig.name = "tsconfig.json";
|
|
680
|
+
const tsJsonFilePath = ctx.tsconfig.path = posix.resolve(root, tsJsonFilename);
|
|
681
|
+
const tsNodeJsonFilename = ctx.tsconfigNode.name = "tsconfig.node.json";
|
|
682
|
+
const tsNodeJsonFilePath = ctx.tsconfigNode.path = posix.resolve(root, tsNodeJsonFilename);
|
|
683
|
+
const tsconfig = getDefaultTsconfigJson();
|
|
684
|
+
const includeFiles = ctx.viteConfig.name ? [ctx.viteConfig.name] : [];
|
|
685
|
+
const tsconfigNode = getDefaultTsconfigNodeJson(includeFiles);
|
|
686
|
+
ctx.tsconfig.value = tsconfig;
|
|
687
|
+
ctx.tsconfigNode.value = tsconfigNode;
|
|
688
|
+
if (write) {
|
|
689
|
+
const tsconfigOutputPath = resolveOutputPath(root, dest, tsJsonFilePath);
|
|
690
|
+
const tsconfigNodeOutputPath = tsNodeJsonFilePath;
|
|
691
|
+
await writeJsonFile(tsconfigOutputPath, tsconfig);
|
|
692
|
+
await writeJsonFile(tsconfigNodeOutputPath, tsconfigNode);
|
|
693
|
+
import_logger.default.log(`\u2728 \u5199\u5165 ${posix.relative(root, tsconfigOutputPath)} \u4E0E ${posix.relative(root, tsconfigNodeOutputPath)} \u6210\u529F!`);
|
|
694
|
+
}
|
|
695
|
+
return {
|
|
696
|
+
tsconfig,
|
|
697
|
+
tsconfigNode
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
// src/createProject.ts
|
|
702
|
+
var import_node_url = require("url");
|
|
703
|
+
var import_logger3 = __toESM(require("@weapp-core/logger"), 1);
|
|
704
|
+
var import_fs_extra2 = __toESM(require("fs-extra"), 1);
|
|
705
|
+
|
|
706
|
+
// ../../packages/weapp-vite/package.json
|
|
707
|
+
var version = "5.2.0-alpha.0";
|
|
708
|
+
|
|
709
|
+
// src/enums.ts
|
|
710
|
+
var TemplateName = /* @__PURE__ */ ((TemplateName2) => {
|
|
711
|
+
TemplateName2["default"] = "default";
|
|
712
|
+
TemplateName2["tailwindcss"] = "tailwindcss";
|
|
713
|
+
TemplateName2["vant"] = "vant";
|
|
714
|
+
TemplateName2["tdesign"] = "tdesign";
|
|
715
|
+
return TemplateName2;
|
|
716
|
+
})(TemplateName || {});
|
|
717
|
+
|
|
718
|
+
// src/npm.ts
|
|
719
|
+
var import_node_https = __toESM(require("https"), 1);
|
|
720
|
+
function getLatestVersionFromNpm(packageName) {
|
|
721
|
+
return new Promise((resolve2, reject) => {
|
|
722
|
+
const url = `https://registry.npmjs.org/${packageName}/latest`;
|
|
723
|
+
import_node_https.default.get(url, (res) => {
|
|
724
|
+
if (!res || res.statusCode && res.statusCode >= 400) {
|
|
725
|
+
res?.resume();
|
|
726
|
+
reject(new Error(`Request to ${url} failed with status ${res?.statusCode ?? "unknown"}`));
|
|
727
|
+
return;
|
|
692
728
|
}
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
if (!x) {
|
|
703
|
-
projectConfig.setting.packNpmRelationList.push({
|
|
704
|
-
packageJsonPath: "./package.json",
|
|
705
|
-
miniprogramNpmDistDir: "./dist"
|
|
706
|
-
});
|
|
707
|
-
}
|
|
708
|
-
} else {
|
|
709
|
-
(0, import_shared.set)(projectConfig, "setting.packNpmRelationList", [
|
|
710
|
-
{
|
|
711
|
-
packageJsonPath: "./package.json",
|
|
712
|
-
miniprogramNpmDistDir: "./dist"
|
|
729
|
+
let data = "";
|
|
730
|
+
res.setEncoding("utf8");
|
|
731
|
+
res.on("data", (chunk) => data += chunk);
|
|
732
|
+
res.on("end", () => {
|
|
733
|
+
try {
|
|
734
|
+
const json = JSON.parse(data);
|
|
735
|
+
if (!json.version || typeof json.version !== "string") {
|
|
736
|
+
reject(new Error(`Unexpected response when fetching ${packageName}: missing version`));
|
|
737
|
+
return;
|
|
713
738
|
}
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
739
|
+
resolve2(json.version);
|
|
740
|
+
} catch (err) {
|
|
741
|
+
reject(err);
|
|
742
|
+
}
|
|
743
|
+
});
|
|
744
|
+
res.on("error", reject);
|
|
745
|
+
}).on("error", reject);
|
|
746
|
+
});
|
|
747
|
+
}
|
|
748
|
+
async function latestVersion(packageName, prefix = "^") {
|
|
749
|
+
try {
|
|
750
|
+
const resolved = await getLatestVersionFromNpm(packageName);
|
|
751
|
+
return resolved ? `${prefix}${resolved}` : null;
|
|
752
|
+
} catch {
|
|
753
|
+
return null;
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
// src/updateGitignore.ts
|
|
758
|
+
var import_logger2 = __toESM(require("@weapp-core/logger"), 1);
|
|
759
|
+
|
|
760
|
+
// src/gitignore.ts
|
|
761
|
+
var DEFAULT_GITIGNORE = `# dependencies
|
|
762
|
+
node_modules
|
|
763
|
+
.pnp
|
|
764
|
+
.pnp.js
|
|
765
|
+
|
|
766
|
+
# testing
|
|
767
|
+
coverage
|
|
768
|
+
|
|
769
|
+
# next.js
|
|
770
|
+
.next/
|
|
771
|
+
out/
|
|
772
|
+
build
|
|
773
|
+
|
|
774
|
+
# misc
|
|
775
|
+
.DS_Store
|
|
776
|
+
*.pem
|
|
777
|
+
|
|
778
|
+
# debug
|
|
779
|
+
npm-debug.log*
|
|
780
|
+
yarn-debug.log*
|
|
781
|
+
yarn-error.log*
|
|
782
|
+
.pnpm-debug.log*
|
|
783
|
+
|
|
784
|
+
# local env files
|
|
785
|
+
.env.local
|
|
786
|
+
.env.development.local
|
|
787
|
+
.env.test.local
|
|
788
|
+
.env.production.local
|
|
789
|
+
|
|
790
|
+
# turbo
|
|
791
|
+
.turbo
|
|
792
|
+
|
|
793
|
+
dist
|
|
794
|
+
dist-plugin
|
|
795
|
+
vite.config.ts.timestamp-*.mjs`;
|
|
796
|
+
function mergeGitignore(existing) {
|
|
797
|
+
const normalizedExisting = normalizeLineEndings(existing ?? "");
|
|
798
|
+
const existingLines = normalizedExisting.length ? normalizedExisting.split("\n") : [];
|
|
799
|
+
const merged = [...existingLines];
|
|
800
|
+
while (merged.length > 0 && merged[merged.length - 1] === "") {
|
|
801
|
+
merged.pop();
|
|
802
|
+
}
|
|
803
|
+
const seen = new Set(merged);
|
|
804
|
+
let appendedNonBlank = false;
|
|
805
|
+
for (const line of DEFAULT_GITIGNORE.split("\n")) {
|
|
806
|
+
const isBlank = line.length === 0;
|
|
807
|
+
if (isBlank) {
|
|
808
|
+
if (merged.length === 0 || merged[merged.length - 1] === "") {
|
|
809
|
+
continue;
|
|
721
810
|
}
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
} catch {
|
|
725
|
-
import_logger.default.warn(`\u2728 \u8BBE\u7F6E ${projectConfigFilename} \u914D\u7F6E\u6587\u4EF6\u5931\u8D25!`);
|
|
811
|
+
merged.push("");
|
|
812
|
+
continue;
|
|
726
813
|
}
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
}, { spaces: 2 });
|
|
765
|
-
import_logger.default.success(`\u2728 \u521B\u5EFA\u5B8C\u6210! \u522B\u5FD8\u4E86\u5728\u91CC\u9762\u8BBE\u7F6E\u4F60\u7684 \`appid\` `);
|
|
814
|
+
if (seen.has(line)) {
|
|
815
|
+
continue;
|
|
816
|
+
}
|
|
817
|
+
if (!appendedNonBlank && merged.length > 0 && merged[merged.length - 1] !== "") {
|
|
818
|
+
merged.push("");
|
|
819
|
+
}
|
|
820
|
+
merged.push(line);
|
|
821
|
+
seen.add(line);
|
|
822
|
+
appendedNonBlank = true;
|
|
823
|
+
}
|
|
824
|
+
return ensureTrailingNewline(trimTrailingBlankLines(merged).join("\n"));
|
|
825
|
+
}
|
|
826
|
+
function normalizeLineEndings(value) {
|
|
827
|
+
return value.replace(/\r\n/g, "\n");
|
|
828
|
+
}
|
|
829
|
+
function trimTrailingBlankLines(lines) {
|
|
830
|
+
let end = lines.length;
|
|
831
|
+
while (end > 0 && lines[end - 1] === "") {
|
|
832
|
+
end -= 1;
|
|
833
|
+
}
|
|
834
|
+
return lines.slice(0, end);
|
|
835
|
+
}
|
|
836
|
+
function ensureTrailingNewline(value) {
|
|
837
|
+
return value.endsWith("\n") ? value : `${value}
|
|
838
|
+
`;
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
// src/updateGitignore.ts
|
|
842
|
+
async function updateGitIgnore(options) {
|
|
843
|
+
const { root, dest, write = true } = options;
|
|
844
|
+
const gitignorePath = posix.resolve(root, ".gitignore");
|
|
845
|
+
const outputPath = resolveOutputPath(root, dest, gitignorePath);
|
|
846
|
+
const existing = await readFileIfExists(outputPath);
|
|
847
|
+
const merged = mergeGitignore(existing);
|
|
848
|
+
if (write && merged !== (existing ?? "")) {
|
|
849
|
+
await writeFile(outputPath, merged);
|
|
850
|
+
import_logger2.default.log(`\u2728 \u66F4\u65B0 ${posix.relative(root, outputPath)} \u6210\u529F!`);
|
|
766
851
|
}
|
|
852
|
+
return merged;
|
|
767
853
|
}
|
|
854
|
+
|
|
855
|
+
// src/createProject.ts
|
|
856
|
+
var moduleDir = posix.dirname((0, import_node_url.fileURLToPath)(importMetaUrl));
|
|
857
|
+
async function createProject(targetDir = "", templateName = "default" /* default */) {
|
|
858
|
+
const targetTemplateDir = posix.resolve(moduleDir, "../templates", templateName);
|
|
859
|
+
if (!await import_fs_extra2.default.pathExists(targetTemplateDir)) {
|
|
860
|
+
import_logger3.default.warn(`\u6CA1\u6709\u627E\u5230 ${templateName} \u6A21\u677F!`);
|
|
861
|
+
return;
|
|
862
|
+
}
|
|
863
|
+
await import_fs_extra2.default.copy(targetTemplateDir, targetDir);
|
|
864
|
+
const templatePackagePath = posix.resolve(targetTemplateDir, "package.json");
|
|
865
|
+
const packageJsonPath = posix.resolve(targetDir, "package.json");
|
|
866
|
+
await ensureDotGitignore(targetDir);
|
|
867
|
+
const pkgJson = await import_fs_extra2.default.pathExists(templatePackagePath) ? await import_fs_extra2.default.readJSON(templatePackagePath) : createEmptyPackageJson();
|
|
868
|
+
if (!pkgJson.devDependencies) {
|
|
869
|
+
pkgJson.devDependencies = {};
|
|
870
|
+
}
|
|
871
|
+
if (pkgJson.devDependencies["weapp-vite"]) {
|
|
872
|
+
pkgJson.devDependencies["weapp-vite"] = version;
|
|
873
|
+
}
|
|
874
|
+
await upsertTailwindcssVersion(pkgJson);
|
|
875
|
+
await writeJsonFile(packageJsonPath, pkgJson);
|
|
876
|
+
await updateGitIgnore({ root: targetDir, write: true });
|
|
877
|
+
import_logger3.default.log("\u2728 \u521B\u5EFA\u6A21\u677F\u6210\u529F!");
|
|
878
|
+
}
|
|
879
|
+
async function upsertTailwindcssVersion(pkgJson) {
|
|
880
|
+
if (!pkgJson.devDependencies) {
|
|
881
|
+
return;
|
|
882
|
+
}
|
|
883
|
+
const resolved = await latestVersion("weapp-tailwindcss");
|
|
884
|
+
if (resolved) {
|
|
885
|
+
pkgJson.devDependencies["weapp-tailwindcss"] = resolved;
|
|
886
|
+
} else if (!pkgJson.devDependencies["weapp-tailwindcss"]) {
|
|
887
|
+
pkgJson.devDependencies["weapp-tailwindcss"] = "^4.3.3";
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
function createEmptyPackageJson() {
|
|
891
|
+
return {
|
|
892
|
+
name: "weapp-vite-app",
|
|
893
|
+
homepage: "https://vite.icebreaker.top/",
|
|
894
|
+
type: "module",
|
|
895
|
+
scripts: {},
|
|
896
|
+
devDependencies: {}
|
|
897
|
+
};
|
|
898
|
+
}
|
|
899
|
+
async function ensureDotGitignore(root) {
|
|
900
|
+
const gitignorePath = posix.resolve(root, "gitignore");
|
|
901
|
+
const dotGitignorePath = posix.resolve(root, ".gitignore");
|
|
902
|
+
if (!await import_fs_extra2.default.pathExists(gitignorePath)) {
|
|
903
|
+
return;
|
|
904
|
+
}
|
|
905
|
+
if (await import_fs_extra2.default.pathExists(dotGitignorePath)) {
|
|
906
|
+
await import_fs_extra2.default.remove(gitignorePath);
|
|
907
|
+
return;
|
|
908
|
+
}
|
|
909
|
+
await import_fs_extra2.default.move(gitignorePath, dotGitignorePath);
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
// src/packageJson.ts
|
|
913
|
+
var import_logger4 = __toESM(require("@weapp-core/logger"), 1);
|
|
914
|
+
var import_shared = require("@weapp-core/shared");
|
|
915
|
+
var FALLBACK_DEP_VERSIONS = {
|
|
916
|
+
"miniprogram-api-typings": "^4.1.0",
|
|
917
|
+
"typescript": "^5.9.2",
|
|
918
|
+
"weapp-tailwindcss": "^4.3.3"
|
|
919
|
+
};
|
|
768
920
|
async function createOrUpdatePackageJson(options) {
|
|
769
921
|
const { root, dest, command, cb, write, filename } = (0, import_shared.defu)(options, {
|
|
770
922
|
write: true,
|
|
@@ -773,110 +925,168 @@ async function createOrUpdatePackageJson(options) {
|
|
|
773
925
|
});
|
|
774
926
|
const packageJsonFilename = ctx.packageJson.name = filename;
|
|
775
927
|
const packageJsonPath = ctx.packageJson.path = posix.resolve(root, packageJsonFilename);
|
|
776
|
-
|
|
777
|
-
if (await import_fs_extra.default.exists(packageJsonPath)) {
|
|
778
|
-
packageJson = await import_fs_extra.default.readJSON(packageJsonPath);
|
|
779
|
-
} else {
|
|
780
|
-
packageJson = {
|
|
781
|
-
name: "weapp-vite-app",
|
|
782
|
-
homepage: "https://vite.icebreaker.top/",
|
|
783
|
-
type: "module"
|
|
784
|
-
};
|
|
785
|
-
}
|
|
928
|
+
const outputPath = resolveOutputPath(root, dest, packageJsonPath);
|
|
786
929
|
try {
|
|
930
|
+
let packageJson = await readJsonIfExists(packageJsonPath);
|
|
931
|
+
if (!packageJson) {
|
|
932
|
+
packageJson = createDefaultPackageJson();
|
|
933
|
+
import_logger4.default.info(`\u2728 \u6CA1\u6709\u627E\u5230 ${packageJsonFilename} \u6587\u4EF6\uFF0C\u6B63\u5728\u521B\u5EFA\u9ED8\u8BA4 package.json ...`);
|
|
934
|
+
}
|
|
787
935
|
(0, import_shared.set)(packageJson, "scripts.dev", `${command} dev`);
|
|
788
936
|
(0, import_shared.set)(packageJson, "scripts.dev:open", `${command} dev -o`);
|
|
789
937
|
(0, import_shared.set)(packageJson, "scripts.build", `${command} build`);
|
|
790
938
|
if (command === "weapp-vite") {
|
|
791
939
|
(0, import_shared.set)(packageJson, "scripts.open", `${command} open`);
|
|
792
940
|
(0, import_shared.set)(packageJson, "scripts.g", `${command} generate`);
|
|
793
|
-
(0, import_shared.set)(packageJson, "devDependencies.
|
|
794
|
-
|
|
795
|
-
|
|
941
|
+
(0, import_shared.set)(packageJson, "devDependencies.weapp-vite", `^${version}`);
|
|
942
|
+
await Promise.all([
|
|
943
|
+
upsertDependencyVersion(packageJson, "devDependencies.miniprogram-api-typings", "miniprogram-api-typings", { skipNetwork: !write }),
|
|
944
|
+
upsertDependencyVersion(packageJson, "devDependencies.typescript", "typescript", { skipNetwork: !write })
|
|
945
|
+
]);
|
|
796
946
|
}
|
|
797
947
|
cb?.(
|
|
798
948
|
(...args) => {
|
|
799
949
|
(0, import_shared.set)(packageJson, ...args);
|
|
800
950
|
}
|
|
801
951
|
);
|
|
952
|
+
ctx.packageJson.value = packageJson;
|
|
802
953
|
if (write) {
|
|
803
|
-
await
|
|
804
|
-
|
|
805
|
-
});
|
|
806
|
-
import_logger.default.log(`\u2728 \u8BBE\u7F6E ${packageJsonFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
954
|
+
await writeJsonFile(outputPath, packageJson);
|
|
955
|
+
import_logger4.default.log(`\u2728 \u5199\u5165 ${posix.relative(root, outputPath)} \u6210\u529F!`);
|
|
807
956
|
}
|
|
808
|
-
ctx.packageJson.value = packageJson;
|
|
809
957
|
return packageJson;
|
|
810
|
-
} catch {
|
|
958
|
+
} catch (error) {
|
|
959
|
+
import_logger4.default.error(`\u26A0\uFE0F \u8BBE\u7F6E ${packageJsonFilename} \u914D\u7F6E\u6587\u4EF6\u5931\u8D25`, error);
|
|
960
|
+
throw error;
|
|
811
961
|
}
|
|
812
962
|
}
|
|
813
|
-
async function
|
|
814
|
-
const
|
|
815
|
-
const
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
if (write) {
|
|
820
|
-
await import_fs_extra.default.outputFile(viteConfigFilePath, viteConfigFileCode, "utf8");
|
|
821
|
-
import_logger.default.log(`\u2728 \u8BBE\u7F6E ${targetFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
963
|
+
async function upsertDependencyVersion(packageJson, keyPath, packageName, options = {}) {
|
|
964
|
+
const currentValue = (0, import_shared.get)(packageJson, keyPath);
|
|
965
|
+
const resolved = options.skipNetwork ? null : await latestVersion(packageName);
|
|
966
|
+
if (resolved) {
|
|
967
|
+
(0, import_shared.set)(packageJson, keyPath, resolved);
|
|
968
|
+
return;
|
|
822
969
|
}
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
const { root, write = true } = options;
|
|
827
|
-
const targetFilename = "vite-env.d.ts";
|
|
828
|
-
const viteDtsFilePath = posix.resolve(root, targetFilename);
|
|
829
|
-
const code = getDefaultTsDts();
|
|
830
|
-
if (write) {
|
|
831
|
-
await import_fs_extra.default.outputFile(viteDtsFilePath, code, "utf8");
|
|
832
|
-
import_logger.default.log(`\u2728 \u8BBE\u7F6E ${targetFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
970
|
+
if (currentValue === void 0) {
|
|
971
|
+
const fallback = FALLBACK_DEP_VERSIONS[packageName] ?? "latest";
|
|
972
|
+
(0, import_shared.set)(packageJson, keyPath, fallback);
|
|
833
973
|
}
|
|
834
|
-
return code;
|
|
835
974
|
}
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
975
|
+
function createDefaultPackageJson() {
|
|
976
|
+
return {
|
|
977
|
+
name: "weapp-vite-app",
|
|
978
|
+
homepage: "https://vite.icebreaker.top/",
|
|
979
|
+
type: "module",
|
|
980
|
+
scripts: {},
|
|
981
|
+
devDependencies: {}
|
|
982
|
+
};
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
// src/projectConfig.ts
|
|
986
|
+
var import_logger5 = __toESM(require("@weapp-core/logger"), 1);
|
|
987
|
+
var import_shared2 = require("@weapp-core/shared");
|
|
988
|
+
async function createOrUpdateProjectConfig(options) {
|
|
989
|
+
const { root, dest, cb, write, filename } = (0, import_shared2.defu)(
|
|
990
|
+
options,
|
|
991
|
+
{
|
|
992
|
+
write: true,
|
|
993
|
+
filename: "project.config.json"
|
|
854
994
|
}
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
995
|
+
);
|
|
996
|
+
const projectConfigFilename = ctx.projectConfig.name = filename;
|
|
997
|
+
const projectConfigPath = ctx.projectConfig.path = posix.resolve(root, projectConfigFilename);
|
|
998
|
+
const outputPath = resolveOutputPath(root, dest, projectConfigPath);
|
|
999
|
+
try {
|
|
1000
|
+
let projectConfig = await readJsonIfExists(projectConfigPath);
|
|
1001
|
+
if (projectConfig) {
|
|
1002
|
+
applyProjectConfigDefaults(projectConfig);
|
|
1003
|
+
} else {
|
|
1004
|
+
projectConfig = createDefaultProjectConfig();
|
|
1005
|
+
import_logger5.default.info(`\u2728 \u6CA1\u6709\u627E\u5230 ${projectConfigFilename} \u6587\u4EF6\uFF0C\u6B63\u5728\u4F7F\u7528\u9ED8\u8BA4\u6A21\u677F\u521B\u5EFA...`);
|
|
1006
|
+
}
|
|
1007
|
+
cb?.(
|
|
1008
|
+
(...args) => {
|
|
1009
|
+
(0, import_shared2.set)(projectConfig, ...args);
|
|
1010
|
+
}
|
|
1011
|
+
);
|
|
1012
|
+
ensurePackNpmRelationList(projectConfig);
|
|
1013
|
+
ctx.projectConfig.value = projectConfig;
|
|
859
1014
|
if (write) {
|
|
860
|
-
await
|
|
861
|
-
|
|
862
|
-
spaces: 2
|
|
863
|
-
});
|
|
864
|
-
import_logger.default.log(`\u2728 \u8BBE\u7F6E ${tsNodeJsonFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
1015
|
+
await writeJsonFile(outputPath, projectConfig);
|
|
1016
|
+
import_logger5.default.log(`\u2728 \u5199\u5165 ${posix.relative(root, outputPath)} \u6210\u529F!`);
|
|
865
1017
|
}
|
|
866
|
-
|
|
1018
|
+
return projectConfig;
|
|
1019
|
+
} catch (error) {
|
|
1020
|
+
import_logger5.default.error(`\u26A0\uFE0F \u8BBE\u7F6E ${projectConfigFilename} \u914D\u7F6E\u6587\u4EF6\u5931\u8D25`, error);
|
|
1021
|
+
throw error;
|
|
867
1022
|
}
|
|
868
1023
|
}
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
1024
|
+
function applyProjectConfigDefaults(projectConfig) {
|
|
1025
|
+
(0, import_shared2.set)(projectConfig, "miniprogramRoot", "dist/");
|
|
1026
|
+
(0, import_shared2.set)(projectConfig, "srcMiniprogramRoot", "dist/");
|
|
1027
|
+
(0, import_shared2.set)(projectConfig, "setting.packNpmManually", true);
|
|
1028
|
+
const compileType = (0, import_shared2.get)(projectConfig, "compileType");
|
|
1029
|
+
if (compileType === "plugin") {
|
|
1030
|
+
(0, import_shared2.set)(projectConfig, "pluginRoot", "dist-plugin");
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
function ensurePackNpmRelationList(projectConfig) {
|
|
1034
|
+
const relations = (0, import_shared2.get)(projectConfig, "setting.packNpmRelationList");
|
|
1035
|
+
const defaultRelation = {
|
|
1036
|
+
packageJsonPath: "./package.json",
|
|
1037
|
+
miniprogramNpmDistDir: "./dist"
|
|
1038
|
+
};
|
|
1039
|
+
if (Array.isArray(relations)) {
|
|
1040
|
+
const exists = relations.some(
|
|
1041
|
+
(relation) => relation.packageJsonPath === defaultRelation.packageJsonPath && relation.miniprogramNpmDistDir === defaultRelation.miniprogramNpmDistDir
|
|
1042
|
+
);
|
|
1043
|
+
if (!exists) {
|
|
1044
|
+
relations.push(defaultRelation);
|
|
1045
|
+
}
|
|
1046
|
+
} else {
|
|
1047
|
+
(0, import_shared2.set)(projectConfig, "setting.packNpmRelationList", [defaultRelation]);
|
|
877
1048
|
}
|
|
878
|
-
return data;
|
|
879
1049
|
}
|
|
1050
|
+
function createDefaultProjectConfig() {
|
|
1051
|
+
return {
|
|
1052
|
+
compileType: "miniprogram",
|
|
1053
|
+
libVersion: "trial",
|
|
1054
|
+
packOptions: {
|
|
1055
|
+
ignore: [],
|
|
1056
|
+
include: []
|
|
1057
|
+
},
|
|
1058
|
+
setting: {
|
|
1059
|
+
coverView: true,
|
|
1060
|
+
es6: true,
|
|
1061
|
+
postcss: true,
|
|
1062
|
+
minified: true,
|
|
1063
|
+
enhance: true,
|
|
1064
|
+
showShadowRootInWxmlPanel: true,
|
|
1065
|
+
packNpmRelationList: [
|
|
1066
|
+
{
|
|
1067
|
+
packageJsonPath: "./package.json",
|
|
1068
|
+
miniprogramNpmDistDir: "./dist"
|
|
1069
|
+
}
|
|
1070
|
+
],
|
|
1071
|
+
babelSetting: {
|
|
1072
|
+
ignore: [],
|
|
1073
|
+
disablePlugins: [],
|
|
1074
|
+
outputPath: ""
|
|
1075
|
+
},
|
|
1076
|
+
packNpmManually: true
|
|
1077
|
+
},
|
|
1078
|
+
condition: {},
|
|
1079
|
+
editorSetting: {
|
|
1080
|
+
tabIndent: "auto",
|
|
1081
|
+
tabSize: 2
|
|
1082
|
+
},
|
|
1083
|
+
appid: "",
|
|
1084
|
+
miniprogramRoot: "dist/",
|
|
1085
|
+
srcMiniprogramRoot: "dist/"
|
|
1086
|
+
};
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
// src/index.ts
|
|
880
1090
|
async function initConfig(options) {
|
|
881
1091
|
const { root = import_node_process.default.cwd(), command } = options;
|
|
882
1092
|
await createOrUpdateProjectConfig({ root });
|
|
@@ -889,29 +1099,6 @@ async function initConfig(options) {
|
|
|
889
1099
|
}
|
|
890
1100
|
return ctx;
|
|
891
1101
|
}
|
|
892
|
-
async function createProject(targetDir = "", templateName = "default" /* default */) {
|
|
893
|
-
const targetTemplateDir = posix.resolve(__dirname, "../templates", templateName);
|
|
894
|
-
if (await import_fs_extra.default.exists(targetTemplateDir)) {
|
|
895
|
-
await import_fs_extra.default.copy(targetTemplateDir, targetDir);
|
|
896
|
-
const pkgJsonPath = posix.resolve(targetTemplateDir, "package.json");
|
|
897
|
-
const pkgJson = await import_fs_extra.default.readJson(pkgJsonPath);
|
|
898
|
-
if (pkgJson.devDependencies) {
|
|
899
|
-
if (pkgJson.devDependencies["weapp-vite"]) {
|
|
900
|
-
pkgJson.devDependencies["weapp-vite"] = version;
|
|
901
|
-
}
|
|
902
|
-
if (pkgJson.devDependencies["weapp-tailwindcss"]) {
|
|
903
|
-
pkgJson.devDependencies["weapp-tailwindcss"] = await latestVersion("weapp-tailwindcss");
|
|
904
|
-
}
|
|
905
|
-
}
|
|
906
|
-
await import_fs_extra.default.writeJson(posix.resolve(targetDir, "package.json"), pkgJson, { spaces: 2 });
|
|
907
|
-
if (!await import_fs_extra.default.exists(posix.resolve(targetDir, ".gitignore"))) {
|
|
908
|
-
await updateGitIgnore({ root: targetDir, write: true });
|
|
909
|
-
}
|
|
910
|
-
import_logger.default.log(`\u2728 \u521B\u5EFA\u6A21\u677F\u6210\u529F!`);
|
|
911
|
-
} else {
|
|
912
|
-
import_logger.default.warn(`\u6CA1\u6709\u627E\u5230 ${templateName} \u6A21\u677F!`);
|
|
913
|
-
}
|
|
914
|
-
}
|
|
915
1102
|
// Annotate the CommonJS export names for ESM import in node:
|
|
916
1103
|
0 && (module.exports = {
|
|
917
1104
|
TemplateName,
|
|
@@ -921,5 +1108,6 @@ async function createProject(targetDir = "", templateName = "default" /* default
|
|
|
921
1108
|
initConfig,
|
|
922
1109
|
initTsDtsFile,
|
|
923
1110
|
initTsJsonFiles,
|
|
924
|
-
initViteConfigFile
|
|
1111
|
+
initViteConfigFile,
|
|
1112
|
+
resetContext
|
|
925
1113
|
});
|