@tsed/cli-plugin-eslint 6.6.3 → 7.0.0-alpha.2

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.
@@ -1,11 +1,5 @@
1
- import { __decorate } from "tslib";
2
- import { Module } from "@tsed/cli-core";
1
+ import { injectable } from "@tsed/di";
3
2
  import { EslintInitHook } from "./hooks/EslintInitHook.js";
4
- let CliPluginEslintModule = class CliPluginEslintModule {
5
- };
6
- CliPluginEslintModule = __decorate([
7
- Module({
8
- imports: [EslintInitHook]
9
- })
10
- ], CliPluginEslintModule);
11
- export { CliPluginEslintModule };
3
+ export class CliPluginEslintModule {
4
+ }
5
+ injectable(CliPluginEslintModule).imports([EslintInitHook]);
@@ -1,87 +1,44 @@
1
- import { __decorate, __metadata } from "tslib";
2
- import { RootRendererService } from "@tsed/cli";
3
- import { inject, Injectable, OnExec, OnPostInstall, PackageManagersModule, ProjectPackageJson } from "@tsed/cli-core";
1
+ import { render } from "@tsed/cli";
2
+ import { PackageManagersModule, ProjectPackageJson } from "@tsed/cli-core";
3
+ import { inject, injectable } from "@tsed/di";
4
4
  import { TEMPLATE_DIR } from "../utils/templateDir.js";
5
- let EslintInitHook = class EslintInitHook {
6
- constructor() {
7
- this.packageJson = inject(ProjectPackageJson);
8
- this.packageManagers = inject(PackageManagersModule);
9
- this.rootRenderer = inject(RootRendererService);
10
- }
11
- onExec(ctx) {
12
- if (!ctx.eslint) {
13
- return [];
5
+ export class EslintInitHook {
6
+ $alterRenderFiles(files, data) {
7
+ if (!data.eslint) {
8
+ return files;
14
9
  }
15
10
  return [
16
- {
17
- title: "Generate files for eslint",
18
- task: (ctx) => {
19
- return this.rootRenderer.renderAll([
20
- "eslint.config.mjs.hbs",
21
- ctx.lintstaged && ".husky/_/.gitignore.hbs",
22
- ctx.lintstaged && ".husky/_/husky.sh.hbs",
23
- ctx.lintstaged && ".husky/.gitignore.hbs",
24
- ctx.lintstaged && ".husky/post-commit.hbs",
25
- ctx.lintstaged && ".husky/pre-commit.hbs",
26
- ctx.lintstaged && ".lintstagedrc.json.hbs",
27
- ctx.prettier && ".prettierignore.hbs",
28
- ctx.prettier && ".prettierrc.hbs"
29
- ], ctx, {
30
- templateDir: `${TEMPLATE_DIR}/init`
31
- });
32
- }
33
- },
34
- {
35
- title: "Add dependencies",
36
- task: () => {
37
- this.addScripts(ctx);
38
- this.addDependencies(ctx);
39
- this.addDevDependencies(ctx);
40
- }
41
- }
42
- ];
43
- }
44
- onPostInstall(ctx) {
45
- return [
46
- {
47
- title: "Add husky prepare task",
48
- skip: !ctx.lintstaged,
49
- task: async () => {
50
- this.packageJson
51
- .refresh()
52
- .addScripts({
53
- prepare: "is-ci || husky install"
54
- })
55
- .write();
56
- await this.packageManagers.runScript("prepare");
57
- }
58
- },
59
- {
60
- title: "Run linter",
61
- task: () => {
62
- return this.packageManagers.runScript("test:lint:fix", {
63
- ignoreError: true
64
- });
65
- }
66
- }
11
+ ...files,
12
+ ...[
13
+ data.lintstaged && ".husky/_/.gitignore",
14
+ data.lintstaged && ".husky/_/husky.sh",
15
+ data.lintstaged && ".husky/.gitignore",
16
+ data.lintstaged && ".husky/post-commit",
17
+ data.lintstaged && ".husky/pre-commit",
18
+ data.lintstaged && ".lintstagedrc.json",
19
+ data.prettier && ".prettierignore",
20
+ data.prettier && ".prettierrc"
21
+ ]
22
+ .filter(Boolean)
23
+ .map((path) => {
24
+ return {
25
+ id: "/" + path,
26
+ from: `${TEMPLATE_DIR}/init`
27
+ };
28
+ })
67
29
  ];
68
30
  }
69
- addScripts(ctx) {
70
- this.packageJson.addScripts({
31
+ $alterPackageJson(packageJson, data) {
32
+ packageJson.addScripts({
71
33
  "test:lint": "eslint",
72
34
  "test:lint:fix": "eslint --fix"
73
35
  });
74
- if (ctx.prettier) {
75
- this.packageJson.addScripts({
36
+ if (data.prettier) {
37
+ packageJson.addScripts({
76
38
  prettier: "prettier '**/*.{json,md,yml,yaml}' --write"
77
39
  });
78
40
  }
79
- }
80
- addDependencies(ctx) {
81
- this.packageJson.addDependencies({}, ctx);
82
- }
83
- addDevDependencies(ctx) {
84
- this.packageJson.addDevDependencies({
41
+ packageJson.addDevDependencies({
85
42
  "@typescript-eslint/parser": "latest",
86
43
  "@typescript-eslint/eslint-plugin": "latest",
87
44
  eslint: "latest",
@@ -89,39 +46,64 @@ let EslintInitHook = class EslintInitHook {
89
46
  "eslint-plugin-prettier": "latest",
90
47
  "eslint-plugin-simple-import-sort": "latest",
91
48
  globals: "latest"
92
- }, ctx);
93
- if (ctx.lintstaged) {
94
- this.packageJson.addDevDependencies({
49
+ }, data);
50
+ if (data.lintstaged) {
51
+ packageJson.addDevDependencies({
95
52
  "is-ci": "latest",
96
53
  husky: "latest",
97
54
  "lint-staged": "latest"
98
- }, ctx);
55
+ }, data);
99
56
  }
100
- if (ctx.vitest) {
101
- this.packageJson.addDevDependencies({
57
+ if (data.vitest) {
58
+ packageJson.addDevDependencies({
102
59
  "eslint-plugin-vitest": "latest"
103
- }, ctx);
60
+ }, data);
104
61
  }
105
- if (ctx.prettier) {
106
- this.packageJson.addDevDependencies({
62
+ if (data.prettier) {
63
+ packageJson.addDevDependencies({
107
64
  prettier: "latest"
108
- }, ctx);
65
+ }, data);
109
66
  }
67
+ return packageJson;
68
+ }
69
+ $alterInitPostInstallTasks(tasks, data) {
70
+ const packageJson = inject(ProjectPackageJson);
71
+ const packageManagers = inject(PackageManagersModule);
72
+ return [
73
+ ...tasks,
74
+ {
75
+ title: "Add eslint configuration",
76
+ task: () => {
77
+ render("eslint.config", {
78
+ ...data,
79
+ name: "eslint.config"
80
+ });
81
+ }
82
+ },
83
+ {
84
+ title: "Add husky prepare task",
85
+ skip: !data.lintstaged,
86
+ task: async () => {
87
+ packageJson
88
+ .refresh()
89
+ .addScripts({
90
+ prepare: "is-ci || husky install"
91
+ })
92
+ .write();
93
+ return packageManagers.runScript("prepare", {
94
+ ignoreError: true
95
+ });
96
+ }
97
+ },
98
+ {
99
+ title: "Run linter",
100
+ task: () => {
101
+ return packageManagers.runScript("test:lint:fix", {
102
+ ignoreError: true
103
+ });
104
+ }
105
+ }
106
+ ];
110
107
  }
111
- };
112
- __decorate([
113
- OnExec("init"),
114
- __metadata("design:type", Function),
115
- __metadata("design:paramtypes", [Object]),
116
- __metadata("design:returntype", void 0)
117
- ], EslintInitHook.prototype, "onExec", null);
118
- __decorate([
119
- OnPostInstall("init"),
120
- __metadata("design:type", Function),
121
- __metadata("design:paramtypes", [Object]),
122
- __metadata("design:returntype", void 0)
123
- ], EslintInitHook.prototype, "onPostInstall", null);
124
- EslintInitHook = __decorate([
125
- Injectable()
126
- ], EslintInitHook);
127
- export { EslintInitHook };
108
+ }
109
+ injectable(EslintInitHook);
package/lib/esm/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import "./templates/eslint.template.js";
1
2
  import { CliPluginEslintModule } from "./CliPluginEslintModule.js";
2
3
  export * from "./utils/templateDir.js";
3
4
  export default CliPluginEslintModule;
@@ -1,9 +1,35 @@
1
- import typescriptEslint from "@typescript-eslint/eslint-plugin";
2
- import typescriptParser from "@typescript-eslint/parser";
3
- {{#if prettier}}import pluginPrettierRecommended from "eslint-plugin-prettier/recommended";
4
- {{/if}}import pluginSimpleImportSort from "eslint-plugin-simple-import-sort";
5
- {{#if vitest}}import vitest from "eslint-plugin-vitest";
6
- {{/if}}import globals from "globals";
1
+ import { defineTemplate } from "@tsed/cli";
2
+ function vitest() {
3
+ return `
4
+ {
5
+ files: ["**/*.spec.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}"], // or any other pattern
6
+ plugins: {
7
+ vitest
8
+ },
9
+ rules: {
10
+ ...vitest.configs.recommended.rules, // you can also use vitest.configs.all.rules to enable all rules
11
+ "vitest/consistent-test-it": ["error", {fn: "it", withinDescribe: "it"}],
12
+ "vitest/no-alias-methods": "error"
13
+ }
14
+ },`;
15
+ }
16
+ export default defineTemplate({
17
+ id: "eslint.config",
18
+ label: "ESLint configuration",
19
+ hidden: true,
20
+ fileName: "eslint.config",
21
+ outputDir: ".",
22
+ preserveCase: true,
23
+ ext: "mjs",
24
+ render(_, data) {
25
+ const imports = [
26
+ 'import typescriptEslint from "@typescript-eslint/eslint-plugin";',
27
+ data.prettier ? 'import pluginPrettierRecommended from "eslint-plugin-prettier/recommended";' : "",
28
+ 'import pluginSimpleImportSort from "eslint-plugin-simple-import-sort";',
29
+ data.vitest ? 'import vitest from "eslint-plugin-vitest";' : "",
30
+ 'import globals from "globals";'
31
+ ];
32
+ return `${imports.filter(Boolean).join("\n")}
7
33
 
8
34
  export default [
9
35
  {
@@ -36,18 +62,7 @@ export default [
36
62
  "@typescript-eslint/no-explicit-any": 0,
37
63
  "@typescript-eslint/no-non-null-assertion": 0
38
64
  }
39
- },{{#if vitest}}
40
- {
41
- files: ["**/*.spec.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}"], // or any other pattern
42
- plugins: {
43
- vitest
44
- },
45
- rules: {
46
- ...vitest.configs.recommended.rules, // you can also use vitest.configs.all.rules to enable all rules
47
- "vitest/consistent-test-it": ["error", {fn: "it", withinDescribe: "it"}],
48
- "vitest/no-alias-methods": "error"
49
- }
50
- },{{/if}}
65
+ },${data.vitest ? vitest() : ""}
51
66
  {
52
67
  files: ["**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}"],
53
68
  languageOptions: {
@@ -60,6 +75,11 @@ export default [
60
75
  "simple-import-sort/imports": "error",
61
76
  "simple-import-sort/exports": "error"
62
77
  }
63
- }{{#if prettier}},
64
- pluginPrettierRecommended{{/if}}
78
+ }${data.prettier
79
+ ? `,
80
+ pluginPrettierRecommended`
81
+ : ""}
65
82
  ];
83
+ `;
84
+ }
85
+ });
@@ -1,26 +1,10 @@
1
- import { type InitCmdContext, RootRendererService } from "@tsed/cli";
2
- import { PackageManagersModule, ProjectPackageJson } from "@tsed/cli-core";
3
- export declare class EslintInitHook {
4
- protected packageJson: ProjectPackageJson;
5
- protected packageManagers: PackageManagersModule;
6
- protected rootRenderer: RootRendererService;
7
- onExec(ctx: InitCmdContext): ({
8
- title: string;
9
- task: (ctx: any) => import("rxjs").Observable<unknown>;
10
- } | {
11
- title: string;
12
- task: () => void;
1
+ import { type CliCommandHooks, type InitCmdContext, type RenderDataContext } from "@tsed/cli";
2
+ import { ProjectPackageJson, type Task } from "@tsed/cli-core";
3
+ export declare class EslintInitHook implements CliCommandHooks {
4
+ $alterRenderFiles(files: string[], data: RenderDataContext): (string | {
5
+ id: string;
6
+ from: string;
13
7
  })[];
14
- onPostInstall(ctx: InitCmdContext): ({
15
- title: string;
16
- skip: boolean;
17
- task: () => Promise<void>;
18
- } | {
19
- title: string;
20
- task: () => import("rxjs").Observable<unknown>;
21
- skip?: undefined;
22
- })[];
23
- addScripts(ctx: InitCmdContext): void;
24
- addDependencies(ctx: InitCmdContext): void;
25
- addDevDependencies(ctx: InitCmdContext): void;
8
+ $alterPackageJson(packageJson: ProjectPackageJson, data: RenderDataContext): ProjectPackageJson | Promise<ProjectPackageJson>;
9
+ $alterInitPostInstallTasks(tasks: Task[], data: InitCmdContext): Task[] | Promise<Task[]>;
26
10
  }
@@ -1,3 +1,4 @@
1
+ import "./templates/eslint.template.js";
1
2
  import { CliPluginEslintModule } from "./CliPluginEslintModule.js";
2
3
  export * from "./utils/templateDir.js";
3
4
  export default CliPluginEslintModule;
@@ -0,0 +1,2 @@
1
+ declare const _default: import("@tsed/cli").DefineTemplateOptions;
2
+ export default _default;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tsed/cli-plugin-eslint",
3
3
  "description": "Ts.ED CLI plugin. Add EsLint support",
4
- "version": "6.6.3",
4
+ "version": "7.0.0-alpha.2",
5
5
  "type": "module",
6
6
  "main": "./lib/esm/index.js",
7
7
  "source": "./src/index.ts",
@@ -17,12 +17,14 @@
17
17
  },
18
18
  "scripts": {
19
19
  "build": "yarn build:ts",
20
- "build:ts": "tsc --build tsconfig.esm.json"
20
+ "build:ts": "tsc --build tsconfig.esm.json",
21
+ "/test": "vitest run",
22
+ "/test:ci": "vitest run --coverage.thresholds.autoUpdate=true"
21
23
  },
22
24
  "devDependencies": {
23
- "@tsed/cli": "6.6.3",
24
- "@tsed/cli-core": "6.6.3",
25
- "@tsed/typescript": "6.6.3",
25
+ "@tsed/cli": "7.0.0-alpha.2",
26
+ "@tsed/cli-core": "7.0.0-alpha.2",
27
+ "@tsed/typescript": "7.0.0-alpha.2",
26
28
  "cross-env": "7.0.3",
27
29
  "typescript": "5.6.2",
28
30
  "vitest": "3.2.4"
@@ -37,5 +39,8 @@
37
39
  },
38
40
  "homepage": "https://github.com/tsedio/tsed-cli/tree/master/packages/cli-plugin-eslint",
39
41
  "author": "Romain Lenzotti",
40
- "license": "MIT"
42
+ "license": "MIT",
43
+ "publishConfig": {
44
+ "tag": "alpha"
45
+ }
41
46
  }
@@ -0,0 +1,4 @@
1
+ {
2
+ "**/*.{ts,js}": ["eslint --fix"],
3
+ "**/*.{ts,js,json,md,yml,yaml}": ["prettier --write"]
4
+ }
@@ -1 +0,0 @@
1
- _
@@ -1 +0,0 @@
1
- *
@@ -1,31 +0,0 @@
1
- #!/bin/sh
2
- if [ -z "$husky_skip_init" ]; then
3
- debug () {
4
- if [ "$HUSKY_DEBUG" = "1" ]; then
5
- echo "husky (debug) - $1"
6
- fi
7
- }
8
-
9
- readonly hook_name="$(basename "$0")"
10
- debug "starting $hook_name..."
11
-
12
- if [ "$HUSKY" = "0" ]; then
13
- debug "HUSKY env variable is set to 0, skipping hook"
14
- exit 0
15
- fi
16
-
17
- if [ -f ~/.huskyrc ]; then
18
- debug "sourcing ~/.huskyrc"
19
- . ~/.huskyrc
20
- fi
21
-
22
- export readonly husky_skip_init=1
23
- sh -e "$0" "$@"
24
- exitCode="$?"
25
-
26
- if [ $exitCode != 0 ]; then
27
- echo "husky - $hook_name hook exited with code $exitCode (error)"
28
- fi
29
-
30
- exit $exitCode
31
- fi
@@ -1,4 +0,0 @@
1
- { {{#if prettier}}
2
- "**/*.{ts,js}": ["eslint --fix"],{{/if}}
3
- "**/*.{ts,js,json,md,yml,yaml}": ["prettier --write"]
4
- }
File without changes