@4399ywkf/core 5.4.0 → 5.4.1
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/cli/index.js +41 -42
- package/dist/cli/index.js.map +1 -1
- package/dist/config/index.js +41 -42
- package/dist/config/index.js.map +1 -1
- package/dist/index.js +41 -42
- package/dist/index.js.map +1 -1
- package/dist/rspack/index.js +41 -42
- package/dist/rspack/index.js.map +1 -1
- package/package.json +1 -1
package/dist/rspack/index.js
CHANGED
|
@@ -626,7 +626,7 @@ function scaffoldSourceFiles(cwd, sourceDir, namespaces, logger) {
|
|
|
626
626
|
}
|
|
627
627
|
const indexPath = join3(dir, "index.ts");
|
|
628
628
|
if (!existsSync3(indexPath)) {
|
|
629
|
-
const imports = namespaces.map((ns) => `import ${ns} from
|
|
629
|
+
const imports = namespaces.map((ns) => `import ${ns} from './${ns}';`).join("\n");
|
|
630
630
|
const entries = namespaces.join(",\n ");
|
|
631
631
|
const content = `${imports}
|
|
632
632
|
|
|
@@ -643,19 +643,19 @@ export default resources;
|
|
|
643
643
|
function buildDefaultNsFile(ns) {
|
|
644
644
|
if (ns === "common") {
|
|
645
645
|
return `export default {
|
|
646
|
-
welcome:
|
|
647
|
-
loading:
|
|
648
|
-
confirm:
|
|
649
|
-
cancel:
|
|
650
|
-
save:
|
|
651
|
-
delete:
|
|
652
|
-
edit:
|
|
653
|
-
back:
|
|
646
|
+
welcome: '\u6B22\u8FCE\u4F7F\u7528',
|
|
647
|
+
loading: '\u52A0\u8F7D\u4E2D...',
|
|
648
|
+
confirm: '\u786E\u5B9A',
|
|
649
|
+
cancel: '\u53D6\u6D88',
|
|
650
|
+
save: '\u4FDD\u5B58',
|
|
651
|
+
delete: '\u5220\u9664',
|
|
652
|
+
edit: '\u7F16\u8F91',
|
|
653
|
+
back: '\u8FD4\u56DE',
|
|
654
654
|
} as const;
|
|
655
655
|
`;
|
|
656
656
|
}
|
|
657
657
|
return `export default {
|
|
658
|
-
title:
|
|
658
|
+
title: '${ns}',
|
|
659
659
|
} as const;
|
|
660
660
|
`;
|
|
661
661
|
}
|
|
@@ -663,11 +663,11 @@ function scaffoldResourcesFile(cwd, sourceDir, _namespaces, locales, defaultLoca
|
|
|
663
663
|
const parentDir = join3(cwd, sourceDir, "..");
|
|
664
664
|
const filePath = join3(parentDir, "resources.ts");
|
|
665
665
|
if (existsSync3(filePath)) return;
|
|
666
|
-
const content = `import resources from
|
|
666
|
+
const content = `import type resources from './default';
|
|
667
667
|
|
|
668
|
-
export const DEFAULT_LOCALE =
|
|
668
|
+
export const DEFAULT_LOCALE = '${defaultLocale}';
|
|
669
669
|
|
|
670
|
-
export const SUPPORTED_LOCALES = ${
|
|
670
|
+
export const SUPPORTED_LOCALES = [${locales.map((l) => `'${l}'`).join(", ")}] as const;
|
|
671
671
|
|
|
672
672
|
export type SupportedLocale = (typeof SUPPORTED_LOCALES)[number];
|
|
673
673
|
|
|
@@ -679,7 +679,7 @@ export const normalizeLocale = (locale?: string): SupportedLocale => {
|
|
|
679
679
|
if (!locale) return DEFAULT_LOCALE as SupportedLocale;
|
|
680
680
|
|
|
681
681
|
for (const l of SUPPORTED_LOCALES) {
|
|
682
|
-
if (l.startsWith(locale) || locale.startsWith(l.split(
|
|
682
|
+
if (l.startsWith(locale) || locale.startsWith(l.split('-')[0])) {
|
|
683
683
|
return l;
|
|
684
684
|
}
|
|
685
685
|
}
|
|
@@ -687,11 +687,9 @@ export const normalizeLocale = (locale?: string): SupportedLocale => {
|
|
|
687
687
|
return DEFAULT_LOCALE as SupportedLocale;
|
|
688
688
|
};
|
|
689
689
|
|
|
690
|
-
export const localeOptions =
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
2
|
|
694
|
-
)} as const;
|
|
690
|
+
export const localeOptions = [
|
|
691
|
+
${locales.map((l) => ` { value: '${l}', label: '${getLocaleLabel(l)}' },`).join("\n")}
|
|
692
|
+
] as const;
|
|
695
693
|
`;
|
|
696
694
|
writeFileSync2(filePath, content, "utf-8");
|
|
697
695
|
logger.info(`\u5DF2\u751F\u6210\u7C7B\u578B\u6587\u4EF6: ${sourceDir}/../resources.ts`);
|
|
@@ -716,29 +714,29 @@ function getLocaleLabel(locale) {
|
|
|
716
714
|
}
|
|
717
715
|
function scaffoldConvertScript(cwd, sourceDir, localesDir, defaultLocale, logger) {
|
|
718
716
|
const scriptsDir = join3(cwd, "scripts");
|
|
719
|
-
const scriptPath = join3(scriptsDir, "i18n-gen.
|
|
720
|
-
if (existsSync3(scriptPath)) return;
|
|
717
|
+
const scriptPath = join3(scriptsDir, "i18n-gen.cjs");
|
|
718
|
+
if (existsSync3(scriptPath) || existsSync3(join3(scriptsDir, "i18n-gen.js"))) return;
|
|
721
719
|
if (!existsSync3(scriptsDir)) {
|
|
722
720
|
mkdirSync(scriptsDir, { recursive: true });
|
|
723
721
|
}
|
|
724
|
-
const content = `const fs = require(
|
|
725
|
-
const path = require(
|
|
722
|
+
const content = `const fs = require('node:fs');
|
|
723
|
+
const path = require('node:path');
|
|
726
724
|
|
|
727
|
-
const sourceDir = path.join(__dirname,
|
|
728
|
-
const targetDir = path.join(__dirname,
|
|
725
|
+
const sourceDir = path.join(__dirname, '../${sourceDir}');
|
|
726
|
+
const targetDir = path.join(__dirname, '../${localesDir}/${defaultLocale}');
|
|
729
727
|
|
|
730
728
|
const files = fs
|
|
731
729
|
.readdirSync(sourceDir)
|
|
732
|
-
.filter((file) => file.endsWith(
|
|
733
|
-
.map((file) => path.basename(file,
|
|
730
|
+
.filter((file) => file.endsWith('.ts') && file !== 'index.ts')
|
|
731
|
+
.map((file) => path.basename(file, '.ts'));
|
|
734
732
|
|
|
735
|
-
require(
|
|
733
|
+
require('ts-node/register');
|
|
736
734
|
|
|
737
735
|
if (!fs.existsSync(targetDir)) {
|
|
738
736
|
fs.mkdirSync(targetDir, { recursive: true });
|
|
739
737
|
}
|
|
740
738
|
|
|
741
|
-
console.log(
|
|
739
|
+
console.log('\u5F00\u59CB\u8F6C\u6362 TypeScript \u6587\u4EF6\u5230 JSON...\\n');
|
|
742
740
|
|
|
743
741
|
files.forEach((fileName) => {
|
|
744
742
|
try {
|
|
@@ -747,28 +745,28 @@ files.forEach((fileName) => {
|
|
|
747
745
|
const moduleContent = require(modulePath).default;
|
|
748
746
|
const jsonContent = JSON.stringify(moduleContent, null, 2);
|
|
749
747
|
const targetPath = path.join(targetDir, \`\${fileName}.json\`);
|
|
750
|
-
fs.writeFileSync(targetPath, jsonContent,
|
|
748
|
+
fs.writeFileSync(targetPath, jsonContent, 'utf8');
|
|
751
749
|
console.log(\` \${fileName}.ts \u2192 \${fileName}.json\`);
|
|
752
750
|
} catch (error) {
|
|
753
751
|
console.error(\` \u8F6C\u6362 \${fileName}.ts \u5931\u8D25:\`, error.message);
|
|
754
752
|
}
|
|
755
753
|
});
|
|
756
754
|
|
|
757
|
-
console.log(
|
|
755
|
+
console.log('\\n\u8F6C\u6362\u5B8C\u6210\uFF01');
|
|
758
756
|
`;
|
|
759
757
|
writeFileSync2(scriptPath, content, "utf-8");
|
|
760
|
-
logger.info("\u5DF2\u751F\u6210\u8F6C\u6362\u811A\u672C: scripts/i18n-gen.
|
|
758
|
+
logger.info("\u5DF2\u751F\u6210\u8F6C\u6362\u811A\u672C: scripts/i18n-gen.cjs");
|
|
761
759
|
}
|
|
762
760
|
function scaffoldI18nRc(cwd, localesDir, defaultLocale, locales, logger) {
|
|
763
761
|
const filePath = join3(cwd, ".i18nrc.js");
|
|
764
762
|
if (existsSync3(filePath)) return;
|
|
765
|
-
const outputLocales = locales.filter((l) => l !== defaultLocale).map((l) => `
|
|
766
|
-
const content = `const { defineConfig } = require(
|
|
763
|
+
const outputLocales = locales.filter((l) => l !== defaultLocale).map((l) => `'${l}'`).join(", ");
|
|
764
|
+
const content = `const { defineConfig } = require('@4399ywkf/i18n');
|
|
767
765
|
|
|
768
766
|
module.exports = defineConfig({
|
|
769
|
-
entry:
|
|
770
|
-
entryLocale:
|
|
771
|
-
output:
|
|
767
|
+
entry: '${localesDir}/${defaultLocale}',
|
|
768
|
+
entryLocale: '${defaultLocale}',
|
|
769
|
+
output: '${localesDir}',
|
|
772
770
|
outputLocales: [${outputLocales}],
|
|
773
771
|
});
|
|
774
772
|
`;
|
|
@@ -787,15 +785,16 @@ function scaffoldLocaleJsonDirs(cwd, localesDir, locales, defaultLocale, namespa
|
|
|
787
785
|
const filePath = join3(localeDir, `${ns}.json`);
|
|
788
786
|
if (!existsSync3(filePath)) {
|
|
789
787
|
const placeholder = ns === "common" ? JSON.stringify(
|
|
788
|
+
// 键按字母序排列,与 @4399ywkf/lint 的 Prettier(prettier-plugin-sort-json)一致
|
|
790
789
|
{
|
|
791
|
-
|
|
792
|
-
loading: "Loading...",
|
|
793
|
-
confirm: "OK",
|
|
790
|
+
back: "Back",
|
|
794
791
|
cancel: "Cancel",
|
|
795
|
-
|
|
792
|
+
confirm: "OK",
|
|
796
793
|
delete: "Delete",
|
|
797
794
|
edit: "Edit",
|
|
798
|
-
|
|
795
|
+
loading: "Loading...",
|
|
796
|
+
save: "Save",
|
|
797
|
+
welcome: "Welcome"
|
|
799
798
|
},
|
|
800
799
|
null,
|
|
801
800
|
2
|