Skip to content

Commit

Permalink
Fix: copy dir content not transform correctly when has `import 'modul…
Browse files Browse the repository at this point in the history
…e-name';`
  • Loading branch information
suhaotian committed Dec 30, 2023
1 parent 298e00e commit 6d1a932
Show file tree
Hide file tree
Showing 13 changed files with 163 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion examples/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*",
Expand Down
4 changes: 3 additions & 1 deletion examples/server/packages/fe-sdk-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
44 changes: 44 additions & 0 deletions examples/server/packages/fe-sdk-demo/src/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -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
}
}
2 changes: 2 additions & 0 deletions examples/server/packages/fe-sdk-demo/src/shared-refs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
45 changes: 45 additions & 0 deletions examples/server/src/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -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
}
}
4 changes: 4 additions & 0 deletions examples/server/tsdk.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/tsdk-server-adapters/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/tsdk/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
1 change: 0 additions & 1 deletion packages/tsdk/src/sync-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 4 additions & 1 deletion packages/tsdk/src/transform-import-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
53 changes: 51 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6d1a932

Please sign in to comment.