@21torr/janus 1.0.0
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.
- package/LICENSE +21 -0
- package/README.md +43 -0
- package/_init/library/.stylelintrc.yml +2 -0
- package/_init/library/dprint.json +5 -0
- package/_init/library/eslint.config.mjs +14 -0
- package/_init/library/package.json +21 -0
- package/_init/library/tsconfig.json +37 -0
- package/_init/next-js/.stylelintrc.yml +2 -0
- package/_init/next-js/dprint.json +5 -0
- package/_init/next-js/eslint.config.mjs +14 -0
- package/_init/next-js/package.json +21 -0
- package/_init/next-js/tsconfig.json +52 -0
- package/bin/cli.mjs +115 -0
- package/dprint/app.json +51 -0
- package/eslint/base.mjs +178 -0
- package/eslint/next-js.mjs +36 -0
- package/package.json +38 -0
- package/src/dir.mjs +9 -0
- package/src/init.mjs +137 -0
- package/stylelint/base.config.mjs +102 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 21TORR
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
Janus TS
|
|
2
|
+
========
|
|
3
|
+
|
|
4
|
+
This repository contains all config files and tools for code style tools, formatters and linters for TS / JS / SCSS / CSS.
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add -D @21torr/janus
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Integration
|
|
14
|
+
|
|
15
|
+
You can automatically initialize all config files in your app, by just running:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm janus init [app-type]
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
This will copy all config files to your project and add required packages.
|
|
22
|
+
If any of the files changed, you should run the lint fixers + `pnpm i` afterwards.
|
|
23
|
+
|
|
24
|
+
You can currently initialize the following app types:
|
|
25
|
+
|
|
26
|
+
- `next-js`
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
## Contributing
|
|
30
|
+
|
|
31
|
+
### dprint
|
|
32
|
+
|
|
33
|
+
The rules are sorted by rule name and then scope. The rules are named `rule` or `scope.rule`.
|
|
34
|
+
|
|
35
|
+
Example:
|
|
36
|
+
|
|
37
|
+
```json
|
|
38
|
+
{
|
|
39
|
+
"a": true,
|
|
40
|
+
"test.b": true,
|
|
41
|
+
"ztest.b": true
|
|
42
|
+
}
|
|
43
|
+
```
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"scripts": {
|
|
3
|
+
"fix-lint": "pnpm run /^fix-lint:.*/",
|
|
4
|
+
"fix-lint:format": "dprint fmt",
|
|
5
|
+
"fix-lint:stylelint": "stylelint 'assets/**/*.{scss,css}' 'src/**/*.{scss,css}' --color --fix",
|
|
6
|
+
"fix-lint:package.json": "prettier-package-json --use-tabs --write",
|
|
7
|
+
"lint": "pnpm run /^lint:.*/",
|
|
8
|
+
"lint:format": "dprint check",
|
|
9
|
+
"lint:eslint": "eslint src",
|
|
10
|
+
"lint:stylelint": "stylelint 'assets/**/*.{scss,css}' 'src/**/*.{scss,css}' --color",
|
|
11
|
+
"lint:package.json": "prettier-package-json --use-tabs --list-different",
|
|
12
|
+
"test": "pnpm run /^test:.*/",
|
|
13
|
+
"test:typescript": "tsc --noEmit --diagnostics"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"dprint": "^0.47.2",
|
|
17
|
+
"eslint": "^8.57.0",
|
|
18
|
+
"stylelint": "^16.7.0",
|
|
19
|
+
"typescript": "^5.5.3"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"allowJs": true,
|
|
4
|
+
"baseUrl": ".",
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"esModuleInterop": true,
|
|
7
|
+
"forceConsistentCasingInFileNames": true,
|
|
8
|
+
"incremental": true,
|
|
9
|
+
"isolatedModules": true,
|
|
10
|
+
"jsx": "react",
|
|
11
|
+
"lib": [
|
|
12
|
+
"dom",
|
|
13
|
+
"dom.iterable",
|
|
14
|
+
"esnext"
|
|
15
|
+
],
|
|
16
|
+
"module": "ESNext",
|
|
17
|
+
"moduleDetection": "force",
|
|
18
|
+
"moduleResolution": "Bundler",
|
|
19
|
+
"noEmit": true,
|
|
20
|
+
"noImplicitThis": true,
|
|
21
|
+
"noImplicitOverride": true,
|
|
22
|
+
"noUncheckedIndexedAccess": true,
|
|
23
|
+
"removeComments": false,
|
|
24
|
+
"resolveJsonModule": true,
|
|
25
|
+
"skipLibCheck": true,
|
|
26
|
+
"sourceMap": false,
|
|
27
|
+
"strict": true,
|
|
28
|
+
"target": "ESNext"
|
|
29
|
+
},
|
|
30
|
+
"include": [
|
|
31
|
+
"${configDir}/**/*.ts",
|
|
32
|
+
"${configDir}/**/*.tsx"
|
|
33
|
+
],
|
|
34
|
+
"exclude": [
|
|
35
|
+
"${configDir}/node_modules"
|
|
36
|
+
]
|
|
37
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"scripts": {
|
|
3
|
+
"fix-lint": "pnpm run /^fix-lint:.*/",
|
|
4
|
+
"fix-lint:format": "dprint fmt",
|
|
5
|
+
"fix-lint:stylelint": "stylelint 'assets/**/*.{scss,css}' 'src/**/*.{scss,css}' --color --fix",
|
|
6
|
+
"fix-lint:package.json": "prettier-package-json --use-tabs --write",
|
|
7
|
+
"lint": "pnpm run /^lint:.*/",
|
|
8
|
+
"lint:format": "dprint check",
|
|
9
|
+
"lint:next": "next lint",
|
|
10
|
+
"lint:stylelint": "stylelint 'assets/**/*.{scss,css}' 'src/**/*.{scss,css}' --color",
|
|
11
|
+
"lint:package.json": "prettier-package-json --use-tabs --list-different",
|
|
12
|
+
"test": "pnpm run /^test:.*/",
|
|
13
|
+
"test:typescript": "tsc --noEmit --diagnostics"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"dprint": "^0.47.2",
|
|
17
|
+
"eslint": "^8.57.0",
|
|
18
|
+
"stylelint": "^16.7.0",
|
|
19
|
+
"typescript": "^5.5.3"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"allowJs": true,
|
|
4
|
+
"baseUrl": ".",
|
|
5
|
+
"esModuleInterop": true,
|
|
6
|
+
"forceConsistentCasingInFileNames": true,
|
|
7
|
+
"incremental": true,
|
|
8
|
+
"isolatedModules": true,
|
|
9
|
+
"jsx": "preserve",
|
|
10
|
+
"lib": [
|
|
11
|
+
"dom",
|
|
12
|
+
"dom.iterable",
|
|
13
|
+
"esnext"
|
|
14
|
+
],
|
|
15
|
+
"module": "NodeNext",
|
|
16
|
+
"moduleResolution": "bundler",
|
|
17
|
+
"noEmit": true,
|
|
18
|
+
"noImplicitOverride": true,
|
|
19
|
+
"noUncheckedIndexedAccess": true,
|
|
20
|
+
"paths": {
|
|
21
|
+
"@/*": [
|
|
22
|
+
"${configDir}/src/*"
|
|
23
|
+
],
|
|
24
|
+
"@assets/*": [
|
|
25
|
+
"${configDir}/assets/*"
|
|
26
|
+
],
|
|
27
|
+
"@public/*": [
|
|
28
|
+
"${configDir}/public/*"
|
|
29
|
+
]
|
|
30
|
+
},
|
|
31
|
+
"plugins": [
|
|
32
|
+
{
|
|
33
|
+
"name": "next"
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"resolveJsonModule": true,
|
|
37
|
+
"skipLibCheck": true,
|
|
38
|
+
"strict": true,
|
|
39
|
+
"target": "ESNext",
|
|
40
|
+
},
|
|
41
|
+
"include": [
|
|
42
|
+
"${configDir}/next-env.d.ts",
|
|
43
|
+
"${configDir}/**/*.ts",
|
|
44
|
+
"${configDir}/**/*.tsx",
|
|
45
|
+
"${configDir}/.storybook/**/*.ts",
|
|
46
|
+
"${configDir}/.storybook/**/*.tsx",
|
|
47
|
+
"${configDir}/.next/types/**/*.ts"
|
|
48
|
+
],
|
|
49
|
+
"exclude": [
|
|
50
|
+
"${configDir}/node_modules"
|
|
51
|
+
]
|
|
52
|
+
}
|
package/bin/cli.mjs
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import sade from "sade";
|
|
4
|
+
import kleur from "kleur";
|
|
5
|
+
import inquirer from "inquirer";
|
|
6
|
+
import {readJSONSync} from "fs-extra/esm";
|
|
7
|
+
import {getLibPath} from "../src/dir.mjs";
|
|
8
|
+
import {getSupportedAppTypes, initializeAppType} from "../src/init.mjs";
|
|
9
|
+
|
|
10
|
+
console.log(``);
|
|
11
|
+
console.log(kleur.cyan(` ╭─────────────────╮`));
|
|
12
|
+
console.log(kleur.cyan(` │ │`));
|
|
13
|
+
console.log(kleur.cyan(` │ 🕵️♀️ ${kleur.cyan("Janus")} │`));
|
|
14
|
+
console.log(kleur.cyan(` │ │`));
|
|
15
|
+
console.log(kleur.cyan(` ╰─────────────────╯`));
|
|
16
|
+
console.log(``);
|
|
17
|
+
|
|
18
|
+
const program = sade("janus");
|
|
19
|
+
const version = readJSONSync(getLibPath("package.json")).version;
|
|
20
|
+
|
|
21
|
+
program
|
|
22
|
+
.version(version);
|
|
23
|
+
|
|
24
|
+
program
|
|
25
|
+
.command("init [key]")
|
|
26
|
+
.describe("Initializes the config")
|
|
27
|
+
.action(async (appType, opts) =>
|
|
28
|
+
{
|
|
29
|
+
taskHeadline("Init");
|
|
30
|
+
|
|
31
|
+
if (!appType)
|
|
32
|
+
{
|
|
33
|
+
const promptResult = await inquirer.prompt({
|
|
34
|
+
type: "list",
|
|
35
|
+
name: "appType",
|
|
36
|
+
message: "Tool to initialize:",
|
|
37
|
+
choices: getSupportedAppTypes(),
|
|
38
|
+
}, {});
|
|
39
|
+
|
|
40
|
+
appType = promptResult.appType;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
console.log("");
|
|
44
|
+
console.log(`// Initializing app type: ${kleur.blue(appType)}`);
|
|
45
|
+
console.log("");
|
|
46
|
+
|
|
47
|
+
const result = await initializeAppType(appType);
|
|
48
|
+
|
|
49
|
+
console.log(`Updated ${result.length} files:`);
|
|
50
|
+
let hasAnyChange = false;
|
|
51
|
+
|
|
52
|
+
result.forEach(entry =>
|
|
53
|
+
{
|
|
54
|
+
const log = [" •"];
|
|
55
|
+
|
|
56
|
+
if (false === entry.removed)
|
|
57
|
+
{
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if ("package.json" === entry.file)
|
|
62
|
+
{
|
|
63
|
+
log.push(kleur.yellow(entry.file));
|
|
64
|
+
}
|
|
65
|
+
else
|
|
66
|
+
{
|
|
67
|
+
log.push(kleur.magenta(entry.file));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (true === entry.removed)
|
|
71
|
+
{
|
|
72
|
+
log.push(`(${kleur.red("removed")})`);
|
|
73
|
+
hasAnyChange = true;
|
|
74
|
+
}
|
|
75
|
+
else if (entry.changed)
|
|
76
|
+
{
|
|
77
|
+
log.push(`(${kleur.red("updated")})`);
|
|
78
|
+
hasAnyChange = true;
|
|
79
|
+
}
|
|
80
|
+
else
|
|
81
|
+
{
|
|
82
|
+
log.push(`(${kleur.gray("unchanged")})`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
console.log(log.join(" "));
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
console.log("");
|
|
89
|
+
|
|
90
|
+
if (hasAnyChange)
|
|
91
|
+
{
|
|
92
|
+
console.log(kleur.bgYellow(" "));
|
|
93
|
+
console.log(kleur.bgYellow(" ⚠️ some files were changed, please verify the changes "));
|
|
94
|
+
console.log(kleur.bgYellow(" "));
|
|
95
|
+
}
|
|
96
|
+
else
|
|
97
|
+
{
|
|
98
|
+
console.log(kleur.bgGreen(" "));
|
|
99
|
+
console.log(kleur.bgGreen(" All done. "));
|
|
100
|
+
console.log(kleur.bgGreen(" "));
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
program.parse(process.argv);
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Logs a task headline
|
|
109
|
+
*/
|
|
110
|
+
export function taskHeadline (headline)
|
|
111
|
+
{
|
|
112
|
+
headline = ` ${headline.toUpperCase()} `;
|
|
113
|
+
console.log(` ${kleur.bgCyan().black(headline)}`);
|
|
114
|
+
console.log("");
|
|
115
|
+
}
|
package/dprint/app.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"lineWidth": 120,
|
|
3
|
+
"useTabs": true,
|
|
4
|
+
"prettier": {
|
|
5
|
+
"associations": [
|
|
6
|
+
"**/*.{css,scss}"
|
|
7
|
+
],
|
|
8
|
+
"parser": "scss",
|
|
9
|
+
"printWidth": 120,
|
|
10
|
+
"useTabs": true
|
|
11
|
+
},
|
|
12
|
+
"typescript": {
|
|
13
|
+
"bracePosition": "nextLine",
|
|
14
|
+
"jsx.bracketPosition": "nextLine",
|
|
15
|
+
"jsx.multiLineParens": "prefer",
|
|
16
|
+
"nextControlFlowPosition": "nextLine",
|
|
17
|
+
"operatorPosition": "maintain",
|
|
18
|
+
"preferHanging": false,
|
|
19
|
+
"quoteProps": "asNeeded",
|
|
20
|
+
"quoteStyle": "preferDouble",
|
|
21
|
+
"semiColons": "always",
|
|
22
|
+
"exportDeclaration.sortNamedExports": "maintain",
|
|
23
|
+
"importDeclaration.sortNamedImports": "maintain",
|
|
24
|
+
"tupleType.spaceAround": false,
|
|
25
|
+
"typeAnnotation.spaceBeforeColon": false,
|
|
26
|
+
"functionDeclaration.spaceBeforeParentheses": true,
|
|
27
|
+
"functionExpression.spaceBeforeParentheses": true,
|
|
28
|
+
"getAccessor.spaceBeforeParentheses": true,
|
|
29
|
+
"method.spaceBeforeParentheses": true,
|
|
30
|
+
"setAccessor.spaceBeforeParentheses": true,
|
|
31
|
+
"exportDeclaration.spaceSurroundingNamedExports": false,
|
|
32
|
+
"importDeclaration.spaceSurroundingNamedImports": false,
|
|
33
|
+
"spaceSurroundingProperties": false,
|
|
34
|
+
"module.sortExportDeclarations": "maintain",
|
|
35
|
+
"module.sortImportDeclarations": "maintain",
|
|
36
|
+
"useBraces": "always",
|
|
37
|
+
"arrowFunction.useParentheses": "preferNone"
|
|
38
|
+
},
|
|
39
|
+
"json": {},
|
|
40
|
+
"excludes": [
|
|
41
|
+
"**/.next",
|
|
42
|
+
"**/node_modules",
|
|
43
|
+
"**/*-lock.json",
|
|
44
|
+
"**/storybook-static"
|
|
45
|
+
],
|
|
46
|
+
"plugins": [
|
|
47
|
+
"https://plugins.dprint.dev/json-0.19.3.wasm",
|
|
48
|
+
"https://plugins.dprint.dev/typescript-0.91.3.wasm",
|
|
49
|
+
"https://plugins.dprint.dev/prettier-0.40.0.json@68c668863ec834d4be0f6f5ccaab415df75336a992aceb7eeeb14fdf096a9e9c"
|
|
50
|
+
]
|
|
51
|
+
}
|
package/eslint/base.mjs
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import js from "@eslint/js";
|
|
2
|
+
import jsdoc from "eslint-plugin-jsdoc";
|
|
3
|
+
import globals from "globals";
|
|
4
|
+
import react from "eslint-plugin-react/configs/recommended.js";
|
|
5
|
+
import reactHooksPlugin from "eslint-plugin-react-hooks";
|
|
6
|
+
import * as jsXA11y from "eslint-plugin-jsx-a11y";
|
|
7
|
+
import tseslint from 'typescript-eslint';
|
|
8
|
+
|
|
9
|
+
export default [
|
|
10
|
+
js.configs.recommended,
|
|
11
|
+
// jsdoc.configs["flat/recommended"],
|
|
12
|
+
// └> We don't use the recommended flags, as they include quite a lot of code formatting rules
|
|
13
|
+
//jsXA11y.default.flatConfigs.recommended,
|
|
14
|
+
...tseslint.configs.recommended,
|
|
15
|
+
...tseslint.configs.strict,
|
|
16
|
+
// └> the *TypeChecked rule sets have too many false positives
|
|
17
|
+
react,
|
|
18
|
+
{
|
|
19
|
+
name: "21TORR Base",
|
|
20
|
+
languageOptions: {
|
|
21
|
+
parserOptions: {
|
|
22
|
+
ecmaVersion: "latest",
|
|
23
|
+
sourceType: "module",
|
|
24
|
+
ecmaFeatures: {
|
|
25
|
+
jsx: true,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
globals: {
|
|
29
|
+
...globals.browser,
|
|
30
|
+
...globals.es2020,
|
|
31
|
+
...globals["shared-node-browser"],
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
settings: {
|
|
35
|
+
jsdoc: {
|
|
36
|
+
mode: "typescript",
|
|
37
|
+
},
|
|
38
|
+
react: {
|
|
39
|
+
"version": "detect",
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
plugins: {
|
|
43
|
+
jsdoc: jsdoc,
|
|
44
|
+
"react-hooks": reactHooksPlugin,
|
|
45
|
+
},
|
|
46
|
+
rules: {
|
|
47
|
+
// region ESLint: Possible Problems
|
|
48
|
+
"no-await-in-loop": "error",
|
|
49
|
+
"no-constructor-return": "error",
|
|
50
|
+
"no-duplicate-imports": "warn",
|
|
51
|
+
"no-self-compare": "error",
|
|
52
|
+
"no-template-curly-in-string": "warn",
|
|
53
|
+
// "no-use-before-define": "error",
|
|
54
|
+
// └> see below: @typescript-eslint/no-use-before-define
|
|
55
|
+
// "no-useless-assignment": "warn",
|
|
56
|
+
// └> enable with ESLint v9
|
|
57
|
+
// endregion
|
|
58
|
+
|
|
59
|
+
// region ESLint: Suggestions
|
|
60
|
+
"block-scoped-var": "error",
|
|
61
|
+
"default-case-last": "warn",
|
|
62
|
+
// "default-param-last": "warn",
|
|
63
|
+
// └> see below: @typescript-eslint/default-param-last
|
|
64
|
+
"eqeqeq": ["error", "always", {
|
|
65
|
+
"null": "ignore",
|
|
66
|
+
}],
|
|
67
|
+
"max-depth": ["warn", 4],
|
|
68
|
+
// "max-params": ["warn", 5],
|
|
69
|
+
// └> see below: @typescript-eslint/max-params
|
|
70
|
+
"no-alert": "error",
|
|
71
|
+
"no-bitwise": "warn",
|
|
72
|
+
"no-caller": "warn",
|
|
73
|
+
"no-console": "warn",
|
|
74
|
+
"no-eval": "error",
|
|
75
|
+
"no-extend-native": "error",
|
|
76
|
+
// endregion
|
|
77
|
+
|
|
78
|
+
// region ESLint: Layout & Formatting
|
|
79
|
+
"unicode-bom": ["error", "never"],
|
|
80
|
+
// endregion
|
|
81
|
+
|
|
82
|
+
// region Plugin: JSDoc
|
|
83
|
+
"jsdoc/check-access": "error",
|
|
84
|
+
"jsdoc/check-param-names": ["error", {
|
|
85
|
+
disableMissingParamChecks: true,
|
|
86
|
+
}],
|
|
87
|
+
"jsdoc/check-property-names": "error",
|
|
88
|
+
"jsdoc/check-tag-names": "error",
|
|
89
|
+
"jsdoc/check-types": "error",
|
|
90
|
+
"jsdoc/check-values": "error",
|
|
91
|
+
"jsdoc/empty-tags": "error",
|
|
92
|
+
"jsdoc/implements-on-classes": "error",
|
|
93
|
+
"jsdoc/no-defaults": "error",
|
|
94
|
+
"jsdoc/no-types": "error",
|
|
95
|
+
"jsdoc/require-param-description": "warn",
|
|
96
|
+
"jsdoc/require-param-name": "error",
|
|
97
|
+
"jsdoc/require-param-type": "off",
|
|
98
|
+
// └> we use TypeScript for types
|
|
99
|
+
"jsdoc/require-property-description": "warn",
|
|
100
|
+
"jsdoc/require-property-name": "error",
|
|
101
|
+
"jsdoc/require-returns-check": "error",
|
|
102
|
+
"jsdoc/require-returns-description": "error",
|
|
103
|
+
"jsdoc/require-yields-check": "error",
|
|
104
|
+
"jsdoc/valid-types": "error",
|
|
105
|
+
// endregion
|
|
106
|
+
|
|
107
|
+
// region Plugin: React
|
|
108
|
+
"react/button-has-type": "error",
|
|
109
|
+
"react/jsx-curly-brace-presence": "warn",
|
|
110
|
+
"react/jsx-filename-extension": ["error", {
|
|
111
|
+
extensions: [".jsx", ".tsx"],
|
|
112
|
+
}],
|
|
113
|
+
"react/jsx-no-constructed-context-values": "error",
|
|
114
|
+
// "react/jsx-no-leaked-render": "off",
|
|
115
|
+
// └> false positives for inline conditionals
|
|
116
|
+
"react/jsx-no-script-url": "error",
|
|
117
|
+
"react/jsx-pascal-case": ["error"],
|
|
118
|
+
"react/no-access-state-in-setstate": ["error"],
|
|
119
|
+
"react/no-did-mount-set-state": ["error"],
|
|
120
|
+
"react/no-did-update-set-state": ["error"],
|
|
121
|
+
"react/no-this-in-sfc": "error",
|
|
122
|
+
"react/no-will-update-set-state": "error",
|
|
123
|
+
"react/prefer-es6-class": ["error", "always"],
|
|
124
|
+
"react/prefer-read-only-props": "error",
|
|
125
|
+
"react/prop-types": "off",
|
|
126
|
+
"react/react-in-jsx-scope": "off",
|
|
127
|
+
"react/style-prop-object": "warn",
|
|
128
|
+
"react/void-dom-elements-no-children": "error",
|
|
129
|
+
// endregion
|
|
130
|
+
|
|
131
|
+
// region Plugin: React Hooks
|
|
132
|
+
"react-hooks/rules-of-hooks": "error",
|
|
133
|
+
"react-hooks/exhaustive-deps": "warn",
|
|
134
|
+
// endregion
|
|
135
|
+
|
|
136
|
+
// region Plugin: TypeScript
|
|
137
|
+
"@typescript-eslint/adjacent-overload-signatures": "error",
|
|
138
|
+
"@typescript-eslint/ban-ts-comment": ["error", {
|
|
139
|
+
"ts-ignore": "allow-with-description",
|
|
140
|
+
}],
|
|
141
|
+
"@typescript-eslint/consistent-type-assertions": ["error", {
|
|
142
|
+
assertionStyle: 'as',
|
|
143
|
+
}],
|
|
144
|
+
"@typescript-eslint/default-param-last": "error",
|
|
145
|
+
"@typescript-eslint/explicit-function-return-type": "off",
|
|
146
|
+
// └> covered by: @typescript-eslint/explicit-module-boundary-types
|
|
147
|
+
"@typescript-eslint/explicit-member-accessibility": "error",
|
|
148
|
+
"@typescript-eslint/explicit-module-boundary-types": "error",
|
|
149
|
+
"@typescript-eslint/max-params": ["warn", {
|
|
150
|
+
max: 6,
|
|
151
|
+
}],
|
|
152
|
+
"@typescript-eslint/no-array-delete": "error",
|
|
153
|
+
"@typescript-eslint/no-confusing-non-null-assertion": "error",
|
|
154
|
+
"@typescript-eslint/no-empty-object-type": "error",
|
|
155
|
+
"@typescript-eslint/no-explicit-any": "off",
|
|
156
|
+
"@typescript-eslint/no-loop-func": "error",
|
|
157
|
+
"@typescript-eslint/no-non-null-assertion": "off",
|
|
158
|
+
"@typescript-eslint/no-unused-vars": ["warn", {
|
|
159
|
+
argsIgnorePattern: 'props',
|
|
160
|
+
}],
|
|
161
|
+
"@typescript-eslint/no-use-before-define": "off",
|
|
162
|
+
// └> false positives with named exports, even with `allowNamedExports: true`
|
|
163
|
+
"@typescript-eslint/no-useless-empty-export": "error",
|
|
164
|
+
"@typescript-eslint/prefer-find": "warn",
|
|
165
|
+
"@typescript-eslint/prefer-reduce-type-parameter": "warn",
|
|
166
|
+
"@typescript-eslint/prefer-string-starts-ends-with": "warn",
|
|
167
|
+
"@typescript-eslint/require-array-sort-compare": "error",
|
|
168
|
+
"@typescript-eslint/return-await": "off",
|
|
169
|
+
// endregion
|
|
170
|
+
|
|
171
|
+
// region Plugin: TypeScript disabled (they require parserServices)
|
|
172
|
+
"@typescript-eslint/await-thenable": "off",
|
|
173
|
+
"@typescript-eslint/no-base-to-string": "off",
|
|
174
|
+
"@typescript-eslint/no-duplicate-type-constituents": "off",
|
|
175
|
+
// endregion
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
];
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import base from './base.mjs';
|
|
2
|
+
import nextPlugin from "@next/eslint-plugin-next";
|
|
3
|
+
import { FlatCompat } from '@eslint/eslintrc'
|
|
4
|
+
import * as storybookPlugin from "eslint-plugin-storybook";
|
|
5
|
+
|
|
6
|
+
const compat = new FlatCompat({
|
|
7
|
+
baseDirectory: import.meta.dirname,
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
export default [
|
|
12
|
+
...compat.config({
|
|
13
|
+
extends: [
|
|
14
|
+
'plugin:storybook/recommended',
|
|
15
|
+
],
|
|
16
|
+
// .eslintignore is not supported with flat config, make sure to ignore also other build and test folders
|
|
17
|
+
ignorePatterns: ['!.storybook', 'storybook-static'],
|
|
18
|
+
}),
|
|
19
|
+
{
|
|
20
|
+
name: "Storybook",
|
|
21
|
+
plugins: {
|
|
22
|
+
"eslint-plugin-storybook": storybookPlugin,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: "Next.js",
|
|
27
|
+
plugins: {
|
|
28
|
+
'@next/next': nextPlugin,
|
|
29
|
+
},
|
|
30
|
+
rules: {
|
|
31
|
+
...nextPlugin.configs.recommended.rules,
|
|
32
|
+
...nextPlugin.configs['core-web-vitals'].rules,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
...base,
|
|
36
|
+
];
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@21torr/janus",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"bin": {
|
|
5
|
+
"janus": "bin/cli.mjs"
|
|
6
|
+
},
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@eslint/eslintrc": "^3.1.0",
|
|
9
|
+
"@eslint/js": "^9.6.0",
|
|
10
|
+
"@next/eslint-plugin-next": "^14.2.5",
|
|
11
|
+
"deep-equal-json": "^1.0.0",
|
|
12
|
+
"deep-extend": "^0.6.0",
|
|
13
|
+
"eslint-plugin-jsdoc": "^48.7.0",
|
|
14
|
+
"eslint-plugin-jsx-a11y": "^6.9.0",
|
|
15
|
+
"eslint-plugin-react": "^7.34.3",
|
|
16
|
+
"eslint-plugin-react-hooks": "^4.6.2",
|
|
17
|
+
"eslint-plugin-storybook": "^0.8.0",
|
|
18
|
+
"fs-extra": "^11.2.0",
|
|
19
|
+
"glob": "^10.3.10",
|
|
20
|
+
"globals": "^15.8.0",
|
|
21
|
+
"inquirer": "^9.2.12",
|
|
22
|
+
"kleur": "^4.1.5",
|
|
23
|
+
"postcss-scss": "^4.0.9",
|
|
24
|
+
"sade": "^1.8.1",
|
|
25
|
+
"stylelint-config-standard": "^36.0.1",
|
|
26
|
+
"stylelint-scss": "^6.4.1",
|
|
27
|
+
"typescript-eslint": "^7.16.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"eslint": "^9.6.0",
|
|
31
|
+
"stylelint": "^16.7.0"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"test": "pnpm run /^test:.*/",
|
|
35
|
+
"test:eslint-nextjs": "eslint --config tests/next-js/eslint.config.mjs tests/next-js/test.ts",
|
|
36
|
+
"test:stylelint": "stylelint --config tests/stylelint/.stylelintrc.yml 'tests/stylelint/*.{scss,css}' --color"
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/dir.mjs
ADDED
package/src/init.mjs
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import {globSync} from "glob";
|
|
2
|
+
import {getLibPath} from "./dir.mjs";
|
|
3
|
+
import {basename, join} from "node:path";
|
|
4
|
+
import {copySync, readJSONSync, writeJSONSync} from "fs-extra/esm";
|
|
5
|
+
import {readFileSync, existsSync, promises} from "node:fs";
|
|
6
|
+
import {Buffer} from "node:buffer";
|
|
7
|
+
import deepExtend from "deep-extend";
|
|
8
|
+
import deepEqual from "deep-equal-json";
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
export function getSupportedAppTypes ()
|
|
12
|
+
{
|
|
13
|
+
const files = globSync(getLibPath("_init") + "/*/");
|
|
14
|
+
|
|
15
|
+
return files.map(
|
|
16
|
+
dir => basename(dir)
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {string} appType
|
|
23
|
+
* @return {Promise<Array<{file: string, changed?: boolean, removed?: boolean}>>}
|
|
24
|
+
*/
|
|
25
|
+
export async function initializeAppType (appType)
|
|
26
|
+
{
|
|
27
|
+
if (!getSupportedAppTypes().includes(appType))
|
|
28
|
+
{
|
|
29
|
+
throw new Error(`Unknown tool: ${appType}`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const sourceDir = getLibPath(`_init/${appType}`);
|
|
33
|
+
const targetDir = process.cwd();
|
|
34
|
+
|
|
35
|
+
const filesToCopy = globSync("*", {
|
|
36
|
+
cwd: sourceDir,
|
|
37
|
+
dot: true,
|
|
38
|
+
nodir: true,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const filesToRemove = [
|
|
42
|
+
".eslintrc.yaml",
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
let changes = [];
|
|
46
|
+
|
|
47
|
+
changes = changes.concat(await Promise.all(filesToRemove.map(async fileName =>
|
|
48
|
+
{
|
|
49
|
+
const targetFilePath = join(targetDir, fileName);
|
|
50
|
+
|
|
51
|
+
if (existsSync(targetFilePath))
|
|
52
|
+
{
|
|
53
|
+
await promises.unlink(targetFilePath);
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
file: fileName,
|
|
57
|
+
removed: true,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
file: fileName,
|
|
63
|
+
removed: false,
|
|
64
|
+
};
|
|
65
|
+
})));
|
|
66
|
+
|
|
67
|
+
changes = changes.concat(await Promise.all(filesToCopy.map(async fileName =>
|
|
68
|
+
{
|
|
69
|
+
const sourceFilePath = join(sourceDir, fileName);
|
|
70
|
+
const targetFilePath = join(targetDir, fileName);
|
|
71
|
+
let hasChanged = true;
|
|
72
|
+
|
|
73
|
+
if (fileName === "package.json")
|
|
74
|
+
{
|
|
75
|
+
return {
|
|
76
|
+
file: fileName,
|
|
77
|
+
changed: mergePackageJson(sourceFilePath, targetFilePath),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (existsSync(targetFilePath))
|
|
82
|
+
{
|
|
83
|
+
const targetStat = await promises.stat(targetFilePath);
|
|
84
|
+
|
|
85
|
+
if (targetStat.isDirectory())
|
|
86
|
+
{
|
|
87
|
+
throw new Error(`Could not overwrite ${fileName}, as it is a directory`);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
hasChanged = 0 !== Buffer.compare(readFileSync(sourceFilePath), readFileSync(targetFilePath));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (!hasChanged)
|
|
94
|
+
{
|
|
95
|
+
return {
|
|
96
|
+
file: fileName,
|
|
97
|
+
changed: false,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
copySync(sourceFilePath, targetFilePath);
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
file: fileName,
|
|
105
|
+
changed: true,
|
|
106
|
+
};
|
|
107
|
+
})));
|
|
108
|
+
|
|
109
|
+
return changes;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Merges the package json files
|
|
115
|
+
*
|
|
116
|
+
* @param {string} sourcePackageJson
|
|
117
|
+
* @param {string} targetPackageJson
|
|
118
|
+
* @return {boolean} whether the file has changed
|
|
119
|
+
*/
|
|
120
|
+
function mergePackageJson (sourcePackageJson, targetPackageJson)
|
|
121
|
+
{
|
|
122
|
+
const sourceJson = readJSONSync(sourcePackageJson);
|
|
123
|
+
const targetJson = readJSONSync(targetPackageJson);
|
|
124
|
+
|
|
125
|
+
const updatedTargetJson = deepExtend({}, targetJson, sourceJson);
|
|
126
|
+
|
|
127
|
+
if (deepEqual(targetJson, updatedTargetJson))
|
|
128
|
+
{
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
writeJSONSync(targetPackageJson, updatedTargetJson, {
|
|
133
|
+
spaces: "\t",
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
console.log();
|
|
2
|
+
|
|
3
|
+
/** @type {import("stylelint").Config} */
|
|
4
|
+
export default {
|
|
5
|
+
extends: [
|
|
6
|
+
import.meta.resolve("stylelint-config-standard"),
|
|
7
|
+
],
|
|
8
|
+
customSyntax: import.meta.resolve("postcss-scss"),
|
|
9
|
+
plugins: [
|
|
10
|
+
import.meta.resolve("stylelint-scss"),
|
|
11
|
+
],
|
|
12
|
+
ignoreFiles: [
|
|
13
|
+
"storybook-static/**",
|
|
14
|
+
],
|
|
15
|
+
rules: {
|
|
16
|
+
// @-rules
|
|
17
|
+
// Disable the rule from CSS and enable it from SCSS
|
|
18
|
+
"at-rule-no-unknown": null,
|
|
19
|
+
"scss/at-rule-no-unknown": true,
|
|
20
|
+
"at-rule-empty-line-before": ["always", {
|
|
21
|
+
except: [
|
|
22
|
+
"blockless-after-same-name-blockless",
|
|
23
|
+
"blockless-after-blockless",
|
|
24
|
+
"first-nested",
|
|
25
|
+
],
|
|
26
|
+
ignore: ["after-comment"],
|
|
27
|
+
ignoreAtRules: ["else"],
|
|
28
|
+
}],
|
|
29
|
+
|
|
30
|
+
// Color
|
|
31
|
+
"color-named": "never",
|
|
32
|
+
|
|
33
|
+
// Declaration
|
|
34
|
+
"declaration-no-important": true,
|
|
35
|
+
|
|
36
|
+
// Font weight
|
|
37
|
+
"font-weight-notation": "numeric",
|
|
38
|
+
|
|
39
|
+
// Max & Min
|
|
40
|
+
"max-nesting-depth": 4,
|
|
41
|
+
|
|
42
|
+
// Rule
|
|
43
|
+
"rule-empty-line-before": ["always-multi-line", {
|
|
44
|
+
"except": [
|
|
45
|
+
"after-single-line-comment",
|
|
46
|
+
"first-nested",
|
|
47
|
+
],
|
|
48
|
+
"ignore": [
|
|
49
|
+
"after-comment",
|
|
50
|
+
],
|
|
51
|
+
}],
|
|
52
|
+
|
|
53
|
+
// Selector
|
|
54
|
+
"selector-max-id": 0,
|
|
55
|
+
"selector-max-type": [0, {
|
|
56
|
+
ignoreTypes: [
|
|
57
|
+
"a",
|
|
58
|
+
"body",
|
|
59
|
+
"button",
|
|
60
|
+
"dd",
|
|
61
|
+
"dt",
|
|
62
|
+
"em",
|
|
63
|
+
"html",
|
|
64
|
+
"i",
|
|
65
|
+
"iframe",
|
|
66
|
+
"img",
|
|
67
|
+
"li",
|
|
68
|
+
"mark",
|
|
69
|
+
"path",
|
|
70
|
+
"strong",
|
|
71
|
+
"svg",
|
|
72
|
+
"td",
|
|
73
|
+
"th",
|
|
74
|
+
"tr",
|
|
75
|
+
],
|
|
76
|
+
}],
|
|
77
|
+
"selector-pseudo-class-no-unknown": [true, {
|
|
78
|
+
ignorePseudoClasses: ["global"],
|
|
79
|
+
}],
|
|
80
|
+
|
|
81
|
+
// Unit
|
|
82
|
+
"unit-disallowed-list": ["pc", "in", "cm", "mm", "ex"],
|
|
83
|
+
"unit-no-unknown": true,
|
|
84
|
+
|
|
85
|
+
// Unknown
|
|
86
|
+
"no-unknown-animations": true,
|
|
87
|
+
|
|
88
|
+
// Value
|
|
89
|
+
"value-keyword-case": ["lower", {
|
|
90
|
+
camelCaseSvgKeywords: true,
|
|
91
|
+
}],
|
|
92
|
+
|
|
93
|
+
// Disabled Style Rules
|
|
94
|
+
// We use dprint for formatting
|
|
95
|
+
"color-function-notation": null,
|
|
96
|
+
"comment-empty-line-before": null,
|
|
97
|
+
"custom-property-empty-line-before": null,
|
|
98
|
+
"declaration-empty-line-before": null,
|
|
99
|
+
"font-family-name-quotes": null,
|
|
100
|
+
"declaration-block-no-redundant-longhand-properties": null,
|
|
101
|
+
},
|
|
102
|
+
};
|