Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump dependencies #412

Merged
merged 15 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"packages/*"
],
"version": "6.0.0-alpha.10"
}
}
24 changes: 13 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,23 @@
},
"homepage": "https://github.com/tsedio/tsed-cli",
"dependencies": {
"@tsed/core": ">=7.14.2",
"@tsed/di": ">=7.14.2",
"@tsed/core": ">=7.83.3",
"@tsed/di": ">=7.83.3",
"@tsed/logger": ">=6.2.1",
"@tsed/normalize-path": ">=7.14.2",
"@tsed/normalize-path": ">=7.83.3",
"@tsed/openspec": ">=7.83.3",
"@tsed/schema": ">=7.83.3",
"axios": "^1.7.7",
"chalk": "^5.3.0",
"commander": "^9.3.0",
"commander": "^12.1.0",
"consolidate": "^1.0.4",
"execa": "8.0.1",
"figures": "^6.1.0",
"fs-extra": "^11.2.0",
"handlebars": "^4.7.8",
"handlebars-helpers": "^0.10.0",
"inquirer": "^8.2.6",
"inquirer-autocomplete-prompt": "^2.0.1",
"inquirer": "^9.3.7",
"inquirer-autocomplete-prompt": "^3.0.1",
"js-yaml": "^4.1.0",
"lerna": "^8.1.8",
"listr2": "^8.2.4",
Expand All @@ -73,12 +75,12 @@
"devDependencies": {
"@commitlint/cli": "19.5.0",
"@commitlint/config-conventional": "19.5.0",
"@swc/core": "1.7.28",
"@swc/core": "1.7.26",
"@swc/helpers": "0.5.13",
"@tsed/markdown-it-symbols": "3.20.4",
"@tsed/markdown-it-symbols": "3.20.8",
"@tsed/monorepo-utils": "2.3.5",
"@tsed/ts-doc": "^4.1.0",
"@types/node": "22.7.0",
"@types/node": "22.7.4",
"@typescript-eslint/eslint-plugin": "8.7.0",
"@typescript-eslint/parser": "8.7.0",
"@vitest/coverage-v8": "^2.1.1",
Expand All @@ -94,9 +96,9 @@
"husky": "9.1.6",
"is-ci": "3.0.1",
"lint-staged": "15.2.10",
"markdown-it": "13.0.2",
"markdown-it": "14.1.0",
"prettier": "3.3.3",
"semantic-release": "24.1.1",
"semantic-release": "24.1.2",
"semantic-release-slack-bot": "4.0.2",
"ts-node": "^10.9.2",
"typescript": "5.6.2",
Expand Down
1 change: 1 addition & 0 deletions packages/barrels/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/__mock__/**/index.ts
77 changes: 4 additions & 73 deletions packages/barrels/bin/barrels.js
Original file line number Diff line number Diff line change
@@ -1,79 +1,10 @@
#!/usr/bin/env node
import {existsSync} from "node:fs";
import {readFile, writeFile} from "node:fs/promises";
import {dirname, join} from "node:path";

import {globby} from "globby";

function resolveConfig() {
return [join(process.cwd(), ".barrelsby.json"), join(process.cwd(), ".barrels.json")].find((path) => {
return existsSync(path);
});
}

async function readJSON(path) {
const content = await readFile(path, "utf-8");

return JSON.parse(content);
}

function getConfig() {
const configPath = resolveConfig();

if (!configPath) {
return {};
}

return readJSON(configPath);
}

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))));
}
import {generateBarrels} from "./generate-barrel.js";
import {getConfig} from "./get-config.js";

async function build() {
const {
directory = ["./src"],
exclude = ["**/__mock__", "**/__mocks__", "**/*.spec.ts", "**/*.benchmark.ts"],
delete: shouldDelete
} = await getConfig();

const excluded = exclude.map((path) => `!${path}`).concat(directory.map((path) => `!${path}/index.ts`));

const directories = (
await globby(directory, {
cwd: process.cwd()
})
).reduce((set, file) => {
return set.add(dirname(file));
}, new Set());

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

const files = await globby(["**/*.ts", "!index.ts", ...excluded], {
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"});
});

await Promise.all(promises);
const {directory = ["./src"], exclude = ["**/__mock__", "**/__mocks__", "**/*.spec.ts", "**/*.benchmark.ts"]} = await getConfig();
await generateBarrels({exclude, directory, cwd: process.cwd()});
}

await build();
55 changes: 55 additions & 0 deletions packages/barrels/bin/generate-barrel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {writeFile} from "node:fs/promises";
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))));
// }

export async function generateBarrels({exclude, directory, cwd}) {
const excluded = exclude.map((path) => `!${path}`).concat(directory.map((path) => `!${path}/index.ts`));

const directories = (
await globby(
directory.map((d) => {
return join(d, "*");
}),
{
cwd
}
)
).reduce((set, file) => {
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"});
});

await Promise.all(promises);
}
25 changes: 25 additions & 0 deletions packages/barrels/bin/get-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {existsSync} from "node:fs";
import {readFile} from "node:fs/promises";
import {join} from "node:path";

function resolveConfig() {
return [join(process.cwd(), ".barrelsby.json"), join(process.cwd(), ".barrels.json")].find((path) => {
return existsSync(path);
});
}

async function readJSON(path) {
const content = await readFile(path, "utf-8");

return JSON.parse(content);
}

export function getConfig() {
const configPath = resolveConfig();

if (!configPath) {
return {};
}

return readJSON(configPath);
}
4 changes: 3 additions & 1 deletion packages/barrels/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"version": "6.0.0-alpha.10",
"type": "module",
"bin": "bin/barrels.js",
"files": [],
"keywords": [
"Ts.ED",
"barrels"
Expand All @@ -14,5 +13,8 @@
},
"dependencies": {
"globby": "14.0.2"
},
"scripts": {
"test": "node --test test/barrels.integration.spec.js"
}
}
2 changes: 1 addition & 1 deletion packages/barrels/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
npm install -g @tsed/barrels
```

Then create a `barrels.json` configuration:
Then create a `.barrels.json` configuration:

```
{
Expand Down
7 changes: 7 additions & 0 deletions packages/barrels/test/__mock__/scenario-1/file1.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {file1} from "./file1";

describe("barrels", () => {
it("should", () => {
expect(file1).toEqual("file1");
});
});
1 change: 1 addition & 0 deletions packages/barrels/test/__mock__/scenario-1/file1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const file1 = "file1";
1 change: 1 addition & 0 deletions packages/barrels/test/__mock__/scenario-1/file2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const file2 = "file2";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const file3 = "file3";
33 changes: 33 additions & 0 deletions packages/barrels/test/barrels.integration.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import assert from "node:assert";
import * as fs from "node:fs/promises";
import {join} from "node:path";

import {describe, it} from "vitest";

import {generateBarrels} from "../bin/generate-barrel.js";

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

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

assert.strictEqual(
result,
"/**\n" +
" * @file Automatically generated by @tsed/barrels.\n" +
" */\n" +
'export * from "./file1.js";\n' +
'export * from "./file2.js";\n' +
'export * from "./sub-directory/file2.js";\n'
);
});
});
9 changes: 4 additions & 5 deletions packages/cli-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"listr"
],
"dependencies": {
"@npmcli/run-script": "8.1.0",
"@npmcli/run-script": "9.0.0",
"@tsed/logger": ">=6.1.1",
"@tsed/normalize-path": ">=7.14.2",
"@types/fs-extra": "^11.0.4",
Expand All @@ -40,7 +40,7 @@
"axios": "^1.7.7",
"chalk": "^5.3.0",
"change-case": "^5.4.4",
"commander": "^9.3.0",
"commander": "^12.1.0",
"consolidate": "^1.0.4",
"create-frame": "^1.0.0",
"enquirer": "^2.4.1",
Expand All @@ -50,8 +50,8 @@
"globby": "^14.0.2",
"handlebars": "^4.7.8",
"handlebars-utils": "^1.0.6",
"inquirer": "^8.2.6",
"inquirer-autocomplete-prompt": "^2.0.1",
"inquirer": "^9.3.7",
"inquirer-autocomplete-prompt": "^3.0.1",
"js-yaml": "^4.1.0",
"listr2": "^8.2.4",
"read-pkg-up": "^11.0.0",
Expand All @@ -71,7 +71,6 @@
"@types/consolidate": "0.14.4",
"@types/figures": "3.0.1",
"@types/globby": "9.1.0",
"@types/inquirer": "9.0.7",
"@types/js-yaml": "4.0.9",
"@types/semver": "7.5.8",
"@types/tunnel": "0.0.7",
Expand Down
11 changes: 7 additions & 4 deletions packages/cli-core/src/services/CliService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import type {CommandProvider} from "../interfaces/CommandProvider.js";
import {PackageManagersModule} from "../packageManagers/index.js";
import {createSubTasks, createTasksRunner} from "../utils/createTasksRunner.js";
import {getCommandMetadata} from "../utils/getCommandMetadata.js";
import {mapCommanderOptions} from "../utils/index.js";
import {mapCommanderArgs} from "../utils/mapCommanderArgs.js";
import {mapCommanderOptions} from "../utils/mapCommanderOptions.js";
import {parseOption} from "../utils/parseOption.js";
import {CliHooks} from "./CliHooks.js";
import {ProjectPackageJson} from "./ProjectPackageJson.js";
Expand Down Expand Up @@ -196,10 +196,13 @@ export class CliService {

let cmd = this.program.command(name);

const onAction = (...commanderArgs: any[]) => {
const onAction = (commandName: string) => {
const [, ...rawArgs] = cmd.args;
const mappedArgs = mapCommanderArgs(args, commanderArgs);
const allOpts = mapCommanderOptions(this.program.commands);
const mappedArgs = mapCommanderArgs(
args,
this.program.args.filter((arg) => commandName === arg)
);
const allOpts = mapCommanderOptions(commandName, this.program.commands);

const data = {
...allOpts,
Expand Down
7 changes: 6 additions & 1 deletion packages/cli-core/src/utils/mapCommanderOptions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import type {Command} from "commander";

export function mapCommanderOptions(commands: Command[]) {
export function mapCommanderOptions(commandName: string, commands: readonly Command[]) {
const options: any = {};

commands.forEach((command) => {
if (command.name() !== commandName) {
return;
}

Object.entries(command.opts())
.filter(([key]) => !key.startsWith("_") && !["commands", "options", "parent", "rawArgs", "args"].includes(key))
.forEach(([key, value]) => {
Expand Down
Loading
Loading