diff --git a/CHANGELOG.mdx b/CHANGELOG.mdx index d3d3a8f..53f4c13 100644 --- a/CHANGELOG.mdx +++ b/CHANGELOG.mdx @@ -2,6 +2,10 @@ This is the log of notable changes to the `tsdk` that are developer-facing. +### 0.0.33 2023/12/22 + +- Fix: copy dir content not transform correctly when has `import 'module-name';` + ### 0.0.32 2023/12/22 - Feat: Generate `React Query` and `SWR` hooks support `undefined` payload diff --git a/examples/server/package.json b/examples/server/package.json index 318084c..857d135 100644 --- a/examples/server/package.json +++ b/examples/server/package.json @@ -36,7 +36,9 @@ "hono": "^3.10.2", "fastify": "^4.24.3", "@fastify/express": "^2.3.0", - "@hono/node-server": "^1.2.3" + "@hono/node-server": "^1.2.3", + "i18next": "^23.7.13", + "intl-pluralrules": "^2.0.1" }, "devDependencies": { "@configs/test-config": "*", diff --git a/examples/server/packages/fe-sdk-demo/package.json b/examples/server/packages/fe-sdk-demo/package.json index da1eda2..613d056 100644 --- a/examples/server/packages/fe-sdk-demo/package.json +++ b/examples/server/packages/fe-sdk-demo/package.json @@ -12,7 +12,9 @@ "axios": "1.6.1", "change-case": "^4.1.2", "kysely": "^0.26.3", - "@tanstack/react-query": "^5.14.0" + "@tanstack/react-query": "^5.14.0", + "i18next": "^23.7.13", + "intl-pluralrules": "^2.0.1" }, "devDependencies": { "typescript": "^5", diff --git a/examples/server/packages/fe-sdk-demo/src/i18n/index.ts b/examples/server/packages/fe-sdk-demo/src/i18n/index.ts new file mode 100644 index 0000000..392724c --- /dev/null +++ b/examples/server/packages/fe-sdk-demo/src/i18n/index.ts @@ -0,0 +1,44 @@ +import 'intl-pluralrules'; +import i18next from 'i18next'; +const translation = { + hello: 'hello world', +}; +export const i18n = i18next.createInstance( + { + fallbackLng: 'en', + debug: true, + ns: ['translation'], + resources: { + en: { + translation, + }, + 'zh-TW': { + translation: { + hello: '您好世界', + }, + }, + }, + }, + (err, t) => { + if (err) return console.log('something went wrong loading', err); + } +); + +// i18n.addResource +// i18n.addResources +// i18n.addResourceBundle + +// i18n.t('hello'); + +declare module 'i18next' { + // Extend CustomTypeOptions + interface CustomTypeOptions { + // custom namespace type, if you changed it + defaultNS: 'translation'; + // custom resources type + resources: { + translation: typeof translation; + }; + // other + } +} diff --git a/examples/server/packages/fe-sdk-demo/src/shared-refs.ts b/examples/server/packages/fe-sdk-demo/src/shared-refs.ts index 80d3fa1..2df64f2 100644 --- a/examples/server/packages/fe-sdk-demo/src/shared-refs.ts +++ b/examples/server/packages/fe-sdk-demo/src/shared-refs.ts @@ -2,6 +2,8 @@ * This is auto generated by `tsdk`. * Don't edit this file. */ +export * from './i18n/index'; + export * from './modules/hello.shared'; export * from './modules/todo/apiconf/TodoSchema.shared'; diff --git a/examples/server/src/i18n/index.ts b/examples/server/src/i18n/index.ts new file mode 100644 index 0000000..cef2016 --- /dev/null +++ b/examples/server/src/i18n/index.ts @@ -0,0 +1,45 @@ +import 'intl-pluralrules'; +import i18next from 'i18next'; + +const translation = { + hello: 'hello world', +}; +export const i18n = i18next.createInstance( + { + fallbackLng: 'en', + debug: true, + ns: ['translation'], + resources: { + en: { + translation, + }, + 'zh-TW': { + translation: { + hello: '您好世界', + }, + }, + }, + }, + (err, t) => { + if (err) return console.log('something went wrong loading', err); + } +); + +// i18n.addResource +// i18n.addResources +// i18n.addResourceBundle + +// i18n.t('hello'); + +declare module 'i18next' { + // Extend CustomTypeOptions + interface CustomTypeOptions { + // custom namespace type, if you changed it + defaultNS: 'translation'; + // custom resources type + resources: { + translation: typeof translation; + }; + // other + } +} diff --git a/examples/server/tsdk.config.js b/examples/server/tsdk.config.js index 9925ee0..f6043d8 100644 --- a/examples/server/tsdk.config.js +++ b/examples/server/tsdk.config.js @@ -9,4 +9,8 @@ module.exports = { apiconfExt: 'apiconf', sharedDirs: ['./src/shared', './src/i18n'], dataHookLib: 'ReactQuery', + dependencies: { + i18next: '^23.7.13', + 'intl-pluralrules': '^2.0.1', + }, }; diff --git a/package.json b/package.json index c0c872f..b665047 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "build": "turbo build", "dev": "turbo dev", "start:tsdk": "pnpm build:tsdk && pnpm --filter tsdk start", - "build:tsdk": "pnpm --filter tsdk-server-adapters build", + "build:tsdk": "pnpm --filter tsdk-server-adapters --filter tsdk build", "dev:web-example": "pnpm --filter server-example --filter web-example dev", "dev:app-example": "pnpm --filter server-example --filter app-example dev", "dev:app-web-example": "pnpm --filter server-example --filter app-example dev", diff --git a/packages/tsdk-server-adapters/package.json b/packages/tsdk-server-adapters/package.json index 9d24244..5dde3d6 100644 --- a/packages/tsdk-server-adapters/package.json +++ b/packages/tsdk-server-adapters/package.json @@ -1,6 +1,6 @@ { "name": "tsdk-server-adapters", - "version": "0.0.32", + "version": "0.0.33", "main": "lib/index.js", "repository": "tsdk-monorepo/tsdk", "bugs": "https://github.com/tsdk-monorepo/tsdk/issues", diff --git a/packages/tsdk/package.json b/packages/tsdk/package.json index 32fe8a5..1f50bf8 100644 --- a/packages/tsdk/package.json +++ b/packages/tsdk/package.json @@ -1,6 +1,6 @@ { "name": "tsdk", - "version": "0.0.32", + "version": "0.0.33", "description": "Type-safe API development and code share tool for TypeScript projects.", "repository": "tsdk-monorepo/tsdk", "bugs": "https://github.com/tsdk-monorepo/tsdk/issues", diff --git a/packages/tsdk/src/sync-files.ts b/packages/tsdk/src/sync-files.ts index b1fd25b..fd16ef7 100644 --- a/packages/tsdk/src/sync-files.ts +++ b/packages/tsdk/src/sync-files.ts @@ -240,7 +240,6 @@ export async function syncSharedFiles() { files.map(async (file) => { const filePath = path.join(ensureDir, file.replace(`${config.baseDir}/`, 'src/')); const content = await transformImportPath(file); - await fsExtra.ensureDir(path.dirname(filePath)); let fromPath = path.relative( diff --git a/packages/tsdk/src/transform-import-path.ts b/packages/tsdk/src/transform-import-path.ts index cff34ff..3358ead 100644 --- a/packages/tsdk/src/transform-import-path.ts +++ b/packages/tsdk/src/transform-import-path.ts @@ -92,10 +92,13 @@ export async function transformImportPath(filePath: string, isEntity?: boolean) const otherContent: string[] = []; let importArr: string[] = []; result.forEach((i) => { + const inlineImport = i.indexOf("import '") > -1 || i.indexOf('import "') > -1; const hasImport = i.indexOf('import ') > -1; const hasFrom = i.indexOf(' from') > -1; - if (hasImport && hasFrom) { + if (inlineImport) { + imports.push(i); + } else if (hasImport && hasFrom) { imports.push(processImportPath(i, filePath)); } else if (hasImport) { importArr.push(i); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2deffc1..ca6c66c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -190,6 +190,12 @@ importers: hono: specifier: ^3.10.2 version: 3.10.2 + i18next: + specifier: ^23.7.13 + version: 23.7.13 + intl-pluralrules: + specifier: ^2.0.1 + version: 2.0.1 kysely: specifier: ^0.26.3 version: 0.26.3 @@ -254,6 +260,12 @@ importers: change-case: specifier: ^4.1.2 version: 4.1.2 + i18next: + specifier: ^23.7.13 + version: 23.7.13 + intl-pluralrules: + specifier: ^2.0.1 + version: 2.0.1 kysely: specifier: ^0.26.3 version: 0.26.3 @@ -330,7 +342,7 @@ importers: version: 3.10.2 tsdk-server-adapters: specifier: ^0.0.31 - version: link:../tsdk-server-adapters + version: 0.0.31(express@4.18.2)(fastify@4.24.3)(hono@3.10.2)(zod@3.22.4) zod: specifier: ^3.22.4 version: 3.22.4 @@ -2293,6 +2305,7 @@ packages: engines: {node: '>=6.9.0'} dependencies: regenerator-runtime: 0.13.11 + dev: false /@babel/runtime@7.23.2: resolution: {integrity: sha512-mM8eg4yl5D6i3lu2QKPuPH4FArvJ8KhTofbE7jwMUv9KX5mBvwPAqnV3MlyBNqdp9RyRKP6Yck8TrfYrPvX3bg==} @@ -9734,6 +9747,12 @@ packages: resolution: {integrity: sha512-ygGZLjmXfPHj+ZWh6LwbC37l43MhfztxetbFCoYTM2VjkIUpeHgSNn7QIyVFj7YQ1Wl9Cbw5sholVJPzWvC2MQ==} dev: false + /i18next@23.7.13: + resolution: {integrity: sha512-DbCPlw6VmURSZa43iOnycxq9o15e+WuBWDBZ3aj+gQZcDz4sgnuKwrcwmP1n8gSSCwCN7CRFGTpnwTd93A16Mg==} + dependencies: + '@babel/runtime': 7.23.2 + dev: false + /iconv-lite@0.4.24: resolution: {integrity: sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==} engines: {node: '>=0.10.0'} @@ -9903,6 +9922,10 @@ packages: resolution: {integrity: sha512-7m1vEcPCxXYI8HqnL8CKI6siDyD+eIWSwgB3DZA+ZTogxk9I4CDnj4wilt9x/+/QbHI4YG5YZNmC6458/e9Ktg==} dev: false + /intl-pluralrules@2.0.1: + resolution: {integrity: sha512-astxTLzIdXPeN0K9Rumi6LfMpm3rvNO0iJE+h/k8Kr/is+wPbRe4ikyDjlLr6VTh/mEfNv8RjN+gu3KwDiuhqg==} + dev: false + /invariant@2.2.4: resolution: {integrity: sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==} dependencies: @@ -14148,6 +14171,7 @@ packages: /regenerator-runtime@0.13.11: resolution: {integrity: sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==} + dev: false /regenerator-runtime@0.14.0: resolution: {integrity: sha512-srw17NI0TUWHuGa5CFGGmhfNIeja30WMBfbslPNhf6JrqQlLN5gcrvig1oqPxiVaXb0oW0XRKtH6Nngs5lKCIA==} @@ -14155,7 +14179,7 @@ packages: /regenerator-transform@0.15.0: resolution: {integrity: sha512-LsrGtPmbYg19bcPHwdtmXwbW+TqNvtY4riE3P83foeHRroMbH6/2ddFBfab3t7kbzc7v7p4wbkIecHImqt0QNg==} dependencies: - '@babel/runtime': 7.21.0 + '@babel/runtime': 7.23.2 /regex-not@1.0.2: resolution: {integrity: sha512-J6SDjUgDxQj5NusnOtdFxDwN/+HWykR8GELwctJ7mdqhcyy1xEc4SRFHUXvxTp661YaVKAjfRLZ9cCqS6tn32A==} @@ -15915,6 +15939,31 @@ packages: strip-bom: 3.0.0 dev: true + /tsdk-server-adapters@0.0.31(express@4.18.2)(fastify@4.24.3)(hono@3.10.2)(zod@3.22.4): + resolution: {integrity: sha512-6dTA0HvQg7pzMMYE0yWxBiTcdkTQ57VU19MgAIRsBKECtReXLiQepmgzc1Xk/QX27KW4wLLx/mZLKsN+eKmsPw==} + peerDependencies: + express: ^4.18.2 + fastify: ^4.24.3 + hono: ^3.10.2 + socket.io: ^4.7.2 + zod: ^3 + peerDependenciesMeta: + express: + optional: true + fastify: + optional: true + hono: + optional: true + socket.io: + optional: true + dependencies: + eventemitter3: 4.0.7 + express: 4.18.2 + fastify: 4.24.3 + hono: 3.10.2 + zod: 3.22.4 + dev: false + /tslib@1.14.1: resolution: {integrity: sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==} dev: false