Skip to content

Commit

Permalink
Merge pull request #419 from tsedio/chore-add-more-test
Browse files Browse the repository at this point in the history
Chore add more test
  • Loading branch information
Romakita authored Nov 9, 2024
2 parents 4511f45 + e30b500 commit 4be573f
Show file tree
Hide file tree
Showing 24 changed files with 72 additions and 55 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"packages": [
"packages/*"
],
"version": "6.0.0-beta.3"
"version": "6.0.0-rc.1"
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tsed/cli-root",
"version": "6.0.0-beta.3",
"version": "6.0.0-rc.1",
"description": "CLI to bootstrap your Ts.ED project",
"private": true,
"type": "module",
Expand Down Expand Up @@ -78,7 +78,7 @@
"@swc/core": "1.7.26",
"@swc/helpers": "0.5.13",
"@tsed/markdown-it-symbols": "3.20.8",
"@tsed/monorepo-utils": "2.3.5",
"@tsed/monorepo-utils": "2.3.10",
"@tsed/ts-doc": "^4.1.0",
"@types/node": "22.7.4",
"@typescript-eslint/eslint-plugin": "8.7.0",
Expand Down
49 changes: 19 additions & 30 deletions packages/barrels/bin/generate-barrel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@ import path, {dirname, join} from "node:path";

import {globby} from "globby";

// async function cleanIndex(cwd, excluded) {
// const patterns = [
// "**/index.ts",
// ...excluded
// ];
//
// const files = await globby(patterns, {
// cwd: cwd
// });
//
// return Promise.all(files.map((file) => fs.unlink(join(cwd, file))));
// }
async function generateIndex(directory, {cwd, excluded}) {
const baseIndex = join(cwd, directory?.path ?? directory);

const files = await globby(["**/*.{ts,tsx}", "!index.{ts,tsx}", ...excluded], {
cwd: path.join(cwd, directory)
});

const exports = files
.sort((a, b) => a.localeCompare(b))
.map((file) => {
// TODO set .js after all configuration are ok to resolve .js
return `export * from "./${file.replace(".ts", ".js")}";`;
});

const content = ["/**", " * @file Automatically generated by @tsed/barrels.", " */", ...exports];

await writeFile(join(baseIndex, "index.ts"), content.join("\n") + "\n", {encoding: "utf8"});
}

export async function generateBarrels({exclude, directory, cwd}) {
const excluded = exclude.map((path) => `!${path}`).concat(directory.map((path) => `!${path}/index.ts`));
Expand All @@ -32,24 +38,7 @@ export async function generateBarrels({exclude, directory, cwd}) {
return set.add(dirname(file));
}, new Set());

const promises = [...directories.keys()].map(async (directory) => {
const baseIndex = join(cwd, directory?.path ?? directory);

const files = await globby(["**/*.{ts,tsx}", "!index.{ts,tsx}", ...excluded], {
cwd: path.join(cwd, directory)
});

const exports = files
.sort((a, b) => a.localeCompare(b))
.map((file) => {
// TODO set .js after all configuration are ok to resolve .js
return `export * from "./${file.replace(".ts", ".js")}";`;
});

const content = ["/**", " * @file Automatically generated by @tsed/barrels.", " */", ...exports];

await writeFile(join(baseIndex, "index.ts"), content.join("\n") + "\n", {encoding: "utf8"});
});
const promises = [...directories.keys()].map((directory) => generateIndex(directory, {excluded, cwd}));

await Promise.all(promises);
}
2 changes: 1 addition & 1 deletion packages/barrels/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tsed/barrels",
"description": "A simple tool to generate barrels for your TypeScript project",
"version": "6.0.0-beta.3",
"version": "6.0.0-rc.1",
"type": "module",
"bin": "bin/barrels.js",
"keywords": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const file3 = "file3";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const file3 = "file3";
26 changes: 26 additions & 0 deletions packages/barrels/test/barrels.integration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,30 @@ describe("barrels.integration.ts", () => {
'export * from "./sub-directory/file2.js";\n'
);
});

// eslint-disable-next-line vitest/expect-expect
it("should generate barrels (with multiple directories)", async () => {
const cwd = join(import.meta.dirname, "__mock__");
// Test code here
await generateBarrels({
cwd,
directory: ["./scenario-2/sub-directory-1", "./scenario-2/sub-directory-2"],
exclude: ["**/__mock__", "**/__mocks__", "**/*.spec.ts"],
delete: true
});

const result = await fs.readFile(join(cwd, "scenario-2", "sub-directory-1", "index.ts"), "utf-8");

assert.strictEqual(
result,
"/**\n" + " * @file Automatically generated by @tsed/barrels.\n" + " */\n" + 'export * from "./file2.js";\n'
);

const result1 = await fs.readFile(join(cwd, "scenario-2", "sub-directory-2", "index.ts"), "utf-8");

assert.strictEqual(
result,
"/**\n" + " * @file Automatically generated by @tsed/barrels.\n" + " */\n" + 'export * from "./file2.js";\n'
);
});
});
2 changes: 1 addition & 1 deletion packages/cli-core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tsed/cli-core",
"description": "Build your CLI with TypeScript and Decorators",
"version": "6.0.0-beta.3",
"version": "6.0.0-rc.1",
"type": "module",
"main": "./lib/esm/index.js",
"source": "./src/index.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-generate-http-client/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tsed/cli-generate-http-client",
"description": "Ts.ED CLI plugin. Export a command that generate an HTTP Client (axios or fetch) from your Ts.ED controllers and OS3 spec.",
"version": "6.0.0-beta.3",
"version": "6.0.0-rc.1",
"type": "module",
"main": "./lib/esm/index.js",
"source": "./src/index.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-generate-swagger/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tsed/cli-generate-swagger",
"description": "Ts.ED CLI plugin. Export a command that generate the swagger.json from your Ts.ED controllers and OS3 spec.",
"version": "6.0.0-beta.3",
"version": "6.0.0-rc.1",
"type": "module",
"main": "./lib/esm/index.js",
"source": "./src/index.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-plugin-eslint/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tsed/cli-plugin-eslint",
"description": "Ts.ED CLI plugin. Add EsLint support",
"version": "6.0.0-beta.3",
"version": "6.0.0-rc.1",
"type": "module",
"main": "./lib/esm/index.js",
"source": "./src/index.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-plugin-jest/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tsed/cli-plugin-jest",
"description": "Ts.ED CLI plugin. Add Jest support",
"version": "6.0.0-beta.3",
"version": "6.0.0-rc.1",
"type": "module",
"main": "./lib/esm/index.js",
"source": "./src/index.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-plugin-mongoose/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tsed/cli-plugin-mongoose",
"description": "Ts.ED CLI plugin. Add Mongoose support",
"version": "6.0.0-beta.3",
"version": "6.0.0-rc.1",
"type": "module",
"main": "./lib/esm/index.js",
"source": "./src/index.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-plugin-oidc-provider/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tsed/cli-plugin-oidc-provider",
"description": "Ts.ED CLI plugin. Add OIDC Provider",
"version": "6.0.0-beta.3",
"version": "6.0.0-rc.1",
"type": "module",
"main": "./lib/esm/index.js",
"source": "./src/index.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-plugin-passport/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tsed/cli-plugin-passport",
"description": "Ts.ED CLI plugin. Add Passport.js support",
"version": "6.0.0-beta.3",
"version": "6.0.0-rc.1",
"type": "module",
"main": "./lib/esm/index.js",
"source": "./src/index.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-plugin-prisma/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tsed/cli-plugin-prisma",
"description": "Ts.ED CLI plugin. Add Prisma project initialisation support.",
"version": "6.0.0-beta.3",
"version": "6.0.0-rc.1",
"type": "module",
"main": "./lib/esm/index.js",
"source": "./src/index.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-plugin-typegraphql/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tsed/cli-plugin-typegraphql",
"description": "Ts.ED CLI plugin. Add TypeGraphql support.",
"version": "6.0.0-beta.3",
"version": "6.0.0-rc.1",
"type": "module",
"main": "./lib/esm/index.js",
"source": "./src/index.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-plugin-typeorm/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tsed/cli-plugin-typeorm",
"description": "Ts.ED CLI plugin. Add TypeORM support",
"version": "6.0.0-beta.3",
"version": "6.0.0-rc.1",
"type": "module",
"main": "./lib/esm/index.js",
"source": "./src/index.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-plugin-vitest/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tsed/cli-plugin-vitest",
"description": "Ts.ED CLI plugin. Add Jest support",
"version": "6.0.0-beta.3",
"version": "6.0.0-rc.1",
"type": "module",
"main": "./lib/esm/index.js",
"source": "./src/index.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-testing/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tsed/cli-testing",
"description": "Utils to test you CLI based on Ts.ED CLI",
"version": "6.0.0-beta.3",
"version": "6.0.0-rc.1",
"type": "module",
"main": "./lib/esm/index.js",
"source": "./src/index.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tsed/cli",
"description": "CLI to bootstrap your Ts.ED project",
"version": "6.0.0-beta.3",
"version": "6.0.0-rc.1",
"type": "module",
"main": "./lib/esm/index.js",
"source": "./src/index.ts",
Expand Down
2 changes: 1 addition & 1 deletion tools/typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tsed/typescript",
"version": "6.0.0-beta.3",
"version": "6.0.0-rc.1",
"description": "Util to compile source",
"type": "module",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion tools/vitest/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tsed/vitest",
"type": "module",
"version": "6.0.0-beta.3",
"version": "6.0.0-rc.1",
"private": true,
"exports": {
".": "./index.js",
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2552,7 +2552,7 @@ __metadata:
"@tsed/di": "npm:>=8.0.0-rc.1"
"@tsed/logger": "npm:>=6.2.1"
"@tsed/markdown-it-symbols": "npm:3.20.8"
"@tsed/monorepo-utils": "npm:2.3.5"
"@tsed/monorepo-utils": "npm:2.3.10"
"@tsed/normalize-path": "npm:>=8.0.0-rc.1"
"@tsed/openspec": "npm:>=8.0.0-rc.1"
"@tsed/schema": "npm:>=8.0.0-rc.1"
Expand Down Expand Up @@ -2705,9 +2705,9 @@ __metadata:
languageName: node
linkType: hard

"@tsed/monorepo-utils@npm:2.3.5":
version: 2.3.5
resolution: "@tsed/monorepo-utils@npm:2.3.5"
"@tsed/monorepo-utils@npm:2.3.10":
version: 2.3.10
resolution: "@tsed/monorepo-utils@npm:2.3.10"
dependencies:
"@samverschueren/stream-to-observable": "npm:>=0.3.1"
"@typescript-eslint/typescript-estree": "npm:>=6.20.0"
Expand All @@ -2734,7 +2734,7 @@ __metadata:
semantic-release: ">=19"
bin:
monorepo: bin/monorepo.js
checksum: 10/9336adfbf603e688d391595b9849a144d413da21132dece44ffa41f602e3547fc566b7b338e8c907562d73dfe74c9e809dda0b140f2ed5cbb0b3c5279fd1835e
checksum: 10/712bfc40bc97a658d726f8efd938501fb39222e34018cf2d052fc7b221014944668bc7edbd0b9f7171d24c30f2b5674b1c9cb8295079a2a49e7fb7ff65f50f59
languageName: node
linkType: hard

Expand Down

0 comments on commit 4be573f

Please sign in to comment.