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