@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/config/index.js
CHANGED
|
@@ -618,7 +618,7 @@ function scaffoldSourceFiles(cwd, sourceDir, namespaces, logger) {
|
|
|
618
618
|
}
|
|
619
619
|
const indexPath = join3(dir, "index.ts");
|
|
620
620
|
if (!existsSync3(indexPath)) {
|
|
621
|
-
const imports = namespaces.map((ns) => `import ${ns} from
|
|
621
|
+
const imports = namespaces.map((ns) => `import ${ns} from './${ns}';`).join("\n");
|
|
622
622
|
const entries = namespaces.join(",\n ");
|
|
623
623
|
const content = `${imports}
|
|
624
624
|
|
|
@@ -635,19 +635,19 @@ export default resources;
|
|
|
635
635
|
function buildDefaultNsFile(ns) {
|
|
636
636
|
if (ns === "common") {
|
|
637
637
|
return `export default {
|
|
638
|
-
welcome:
|
|
639
|
-
loading:
|
|
640
|
-
confirm:
|
|
641
|
-
cancel:
|
|
642
|
-
save:
|
|
643
|
-
delete:
|
|
644
|
-
edit:
|
|
645
|
-
back:
|
|
638
|
+
welcome: '\u6B22\u8FCE\u4F7F\u7528',
|
|
639
|
+
loading: '\u52A0\u8F7D\u4E2D...',
|
|
640
|
+
confirm: '\u786E\u5B9A',
|
|
641
|
+
cancel: '\u53D6\u6D88',
|
|
642
|
+
save: '\u4FDD\u5B58',
|
|
643
|
+
delete: '\u5220\u9664',
|
|
644
|
+
edit: '\u7F16\u8F91',
|
|
645
|
+
back: '\u8FD4\u56DE',
|
|
646
646
|
} as const;
|
|
647
647
|
`;
|
|
648
648
|
}
|
|
649
649
|
return `export default {
|
|
650
|
-
title:
|
|
650
|
+
title: '${ns}',
|
|
651
651
|
} as const;
|
|
652
652
|
`;
|
|
653
653
|
}
|
|
@@ -655,11 +655,11 @@ function scaffoldResourcesFile(cwd, sourceDir, _namespaces, locales, defaultLoca
|
|
|
655
655
|
const parentDir = join3(cwd, sourceDir, "..");
|
|
656
656
|
const filePath = join3(parentDir, "resources.ts");
|
|
657
657
|
if (existsSync3(filePath)) return;
|
|
658
|
-
const content = `import resources from
|
|
658
|
+
const content = `import type resources from './default';
|
|
659
659
|
|
|
660
|
-
export const DEFAULT_LOCALE =
|
|
660
|
+
export const DEFAULT_LOCALE = '${defaultLocale}';
|
|
661
661
|
|
|
662
|
-
export const SUPPORTED_LOCALES = ${
|
|
662
|
+
export const SUPPORTED_LOCALES = [${locales.map((l) => `'${l}'`).join(", ")}] as const;
|
|
663
663
|
|
|
664
664
|
export type SupportedLocale = (typeof SUPPORTED_LOCALES)[number];
|
|
665
665
|
|
|
@@ -671,7 +671,7 @@ export const normalizeLocale = (locale?: string): SupportedLocale => {
|
|
|
671
671
|
if (!locale) return DEFAULT_LOCALE as SupportedLocale;
|
|
672
672
|
|
|
673
673
|
for (const l of SUPPORTED_LOCALES) {
|
|
674
|
-
if (l.startsWith(locale) || locale.startsWith(l.split(
|
|
674
|
+
if (l.startsWith(locale) || locale.startsWith(l.split('-')[0])) {
|
|
675
675
|
return l;
|
|
676
676
|
}
|
|
677
677
|
}
|
|
@@ -679,11 +679,9 @@ export const normalizeLocale = (locale?: string): SupportedLocale => {
|
|
|
679
679
|
return DEFAULT_LOCALE as SupportedLocale;
|
|
680
680
|
};
|
|
681
681
|
|
|
682
|
-
export const localeOptions =
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
2
|
|
686
|
-
)} as const;
|
|
682
|
+
export const localeOptions = [
|
|
683
|
+
${locales.map((l) => ` { value: '${l}', label: '${getLocaleLabel(l)}' },`).join("\n")}
|
|
684
|
+
] as const;
|
|
687
685
|
`;
|
|
688
686
|
writeFileSync2(filePath, content, "utf-8");
|
|
689
687
|
logger.info(`\u5DF2\u751F\u6210\u7C7B\u578B\u6587\u4EF6: ${sourceDir}/../resources.ts`);
|
|
@@ -708,29 +706,29 @@ function getLocaleLabel(locale) {
|
|
|
708
706
|
}
|
|
709
707
|
function scaffoldConvertScript(cwd, sourceDir, localesDir, defaultLocale, logger) {
|
|
710
708
|
const scriptsDir = join3(cwd, "scripts");
|
|
711
|
-
const scriptPath = join3(scriptsDir, "i18n-gen.
|
|
712
|
-
if (existsSync3(scriptPath)) return;
|
|
709
|
+
const scriptPath = join3(scriptsDir, "i18n-gen.cjs");
|
|
710
|
+
if (existsSync3(scriptPath) || existsSync3(join3(scriptsDir, "i18n-gen.js"))) return;
|
|
713
711
|
if (!existsSync3(scriptsDir)) {
|
|
714
712
|
mkdirSync(scriptsDir, { recursive: true });
|
|
715
713
|
}
|
|
716
|
-
const content = `const fs = require(
|
|
717
|
-
const path = require(
|
|
714
|
+
const content = `const fs = require('node:fs');
|
|
715
|
+
const path = require('node:path');
|
|
718
716
|
|
|
719
|
-
const sourceDir = path.join(__dirname,
|
|
720
|
-
const targetDir = path.join(__dirname,
|
|
717
|
+
const sourceDir = path.join(__dirname, '../${sourceDir}');
|
|
718
|
+
const targetDir = path.join(__dirname, '../${localesDir}/${defaultLocale}');
|
|
721
719
|
|
|
722
720
|
const files = fs
|
|
723
721
|
.readdirSync(sourceDir)
|
|
724
|
-
.filter((file) => file.endsWith(
|
|
725
|
-
.map((file) => path.basename(file,
|
|
722
|
+
.filter((file) => file.endsWith('.ts') && file !== 'index.ts')
|
|
723
|
+
.map((file) => path.basename(file, '.ts'));
|
|
726
724
|
|
|
727
|
-
require(
|
|
725
|
+
require('ts-node/register');
|
|
728
726
|
|
|
729
727
|
if (!fs.existsSync(targetDir)) {
|
|
730
728
|
fs.mkdirSync(targetDir, { recursive: true });
|
|
731
729
|
}
|
|
732
730
|
|
|
733
|
-
console.log(
|
|
731
|
+
console.log('\u5F00\u59CB\u8F6C\u6362 TypeScript \u6587\u4EF6\u5230 JSON...\\n');
|
|
734
732
|
|
|
735
733
|
files.forEach((fileName) => {
|
|
736
734
|
try {
|
|
@@ -739,28 +737,28 @@ files.forEach((fileName) => {
|
|
|
739
737
|
const moduleContent = require(modulePath).default;
|
|
740
738
|
const jsonContent = JSON.stringify(moduleContent, null, 2);
|
|
741
739
|
const targetPath = path.join(targetDir, \`\${fileName}.json\`);
|
|
742
|
-
fs.writeFileSync(targetPath, jsonContent,
|
|
740
|
+
fs.writeFileSync(targetPath, jsonContent, 'utf8');
|
|
743
741
|
console.log(\` \${fileName}.ts \u2192 \${fileName}.json\`);
|
|
744
742
|
} catch (error) {
|
|
745
743
|
console.error(\` \u8F6C\u6362 \${fileName}.ts \u5931\u8D25:\`, error.message);
|
|
746
744
|
}
|
|
747
745
|
});
|
|
748
746
|
|
|
749
|
-
console.log(
|
|
747
|
+
console.log('\\n\u8F6C\u6362\u5B8C\u6210\uFF01');
|
|
750
748
|
`;
|
|
751
749
|
writeFileSync2(scriptPath, content, "utf-8");
|
|
752
|
-
logger.info("\u5DF2\u751F\u6210\u8F6C\u6362\u811A\u672C: scripts/i18n-gen.
|
|
750
|
+
logger.info("\u5DF2\u751F\u6210\u8F6C\u6362\u811A\u672C: scripts/i18n-gen.cjs");
|
|
753
751
|
}
|
|
754
752
|
function scaffoldI18nRc(cwd, localesDir, defaultLocale, locales, logger) {
|
|
755
753
|
const filePath = join3(cwd, ".i18nrc.js");
|
|
756
754
|
if (existsSync3(filePath)) return;
|
|
757
|
-
const outputLocales = locales.filter((l) => l !== defaultLocale).map((l) => `
|
|
758
|
-
const content = `const { defineConfig } = require(
|
|
755
|
+
const outputLocales = locales.filter((l) => l !== defaultLocale).map((l) => `'${l}'`).join(", ");
|
|
756
|
+
const content = `const { defineConfig } = require('@4399ywkf/i18n');
|
|
759
757
|
|
|
760
758
|
module.exports = defineConfig({
|
|
761
|
-
entry:
|
|
762
|
-
entryLocale:
|
|
763
|
-
output:
|
|
759
|
+
entry: '${localesDir}/${defaultLocale}',
|
|
760
|
+
entryLocale: '${defaultLocale}',
|
|
761
|
+
output: '${localesDir}',
|
|
764
762
|
outputLocales: [${outputLocales}],
|
|
765
763
|
});
|
|
766
764
|
`;
|
|
@@ -779,15 +777,16 @@ function scaffoldLocaleJsonDirs(cwd, localesDir, locales, defaultLocale, namespa
|
|
|
779
777
|
const filePath = join3(localeDir, `${ns}.json`);
|
|
780
778
|
if (!existsSync3(filePath)) {
|
|
781
779
|
const placeholder = ns === "common" ? JSON.stringify(
|
|
780
|
+
// 键按字母序排列,与 @4399ywkf/lint 的 Prettier(prettier-plugin-sort-json)一致
|
|
782
781
|
{
|
|
783
|
-
|
|
784
|
-
loading: "Loading...",
|
|
785
|
-
confirm: "OK",
|
|
782
|
+
back: "Back",
|
|
786
783
|
cancel: "Cancel",
|
|
787
|
-
|
|
784
|
+
confirm: "OK",
|
|
788
785
|
delete: "Delete",
|
|
789
786
|
edit: "Edit",
|
|
790
|
-
|
|
787
|
+
loading: "Loading...",
|
|
788
|
+
save: "Save",
|
|
789
|
+
welcome: "Welcome"
|
|
791
790
|
},
|
|
792
791
|
null,
|
|
793
792
|
2
|