Skip to content

Commit 6b5d512

Browse files
committed
chore: add formatting
1 parent ab7dde5 commit 6b5d512

File tree

14 files changed

+3593
-76
lines changed

14 files changed

+3593
-76
lines changed

.prettierignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
node_modules/
22
dist/
3-
3+
formatting/
44
package.json

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,6 @@ publish: install-dependencies
4545
pnpm run build
4646
pnpm lerna changed
4747
pnpm exec lerna publish -y --registry $(NPM_PUBLISH_REGISTRY) --ignore-scripts
48+
49+
format-generated:
50+
./formatting/run.sh -i "./packages_generated" -f "new-package"

biome.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"*.snap",
3232
"**/__snapshots__/",
3333
".docusaurus",
34-
".vitest-reports"
34+
".vitest-reports",
35+
"formatting/**"
3536
]
3637
},
3738
"formatter": {

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default [
2121
'packages/configuration-loader/.eslintrc.cjs',
2222
'scripts/generatePackages.ts',
2323
'scripts/*.ts',
24+
'formatting/**',
2425
],
2526
},
2627
{

formatting/biome.json

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
3+
"vcs": {
4+
"clientKind": "git",
5+
"useIgnoreFile": false,
6+
"defaultBranch": "main"
7+
},
8+
"formatter": {
9+
"enabled": true,
10+
"formatWithErrors": false,
11+
"indentStyle": "space",
12+
"indentWidth": 2,
13+
"lineEnding": "lf",
14+
"lineWidth": 80
15+
},
16+
"javascript": {
17+
"formatter": {
18+
"jsxQuoteStyle": "double",
19+
"quoteProperties": "asNeeded",
20+
"trailingCommas": "all",
21+
"semicolons": "asNeeded",
22+
"arrowParentheses": "asNeeded",
23+
"bracketSpacing": true,
24+
"bracketSameLine": false,
25+
"quoteStyle": "single"
26+
}
27+
},
28+
"json": {
29+
"formatter": {
30+
"enabled": true
31+
},
32+
"parser": {
33+
"allowComments": true
34+
}
35+
},
36+
"linter": {
37+
"enabled": false
38+
},
39+
"files": {
40+
"maxSize": 10000000,
41+
"ignoreUnknown": true,
42+
"include": ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx", "**/*.json"],
43+
"ignore": [
44+
".next/",
45+
".pnpm-store/",
46+
"coverage/",
47+
"/public/outdated",
48+
"/public/.well-known",
49+
"**/node_modules/",
50+
".turbo/**",
51+
"dist",
52+
"build",
53+
"out",
54+
"node_modules/**",
55+
"**/pnpm-lock.yaml",
56+
"**/package.json",
57+
"**/CHANGELOG.md",
58+
"*.snap",
59+
"**/__snapshots__/",
60+
".vitest-reports"
61+
]
62+
}
63+
}

formatting/eslint.config.mjs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import tsPlugin from '@typescript-eslint/eslint-plugin'
2+
import typescriptParser from '@typescript-eslint/parser'
3+
import importPlugin from 'eslint-plugin-import'
4+
import unusedImports from 'eslint-plugin-unused-imports'
5+
6+
export default [
7+
{
8+
ignores: [
9+
'**/node_modules/',
10+
'**/dist/',
11+
'**/examples/',
12+
'**/vite.config.ts',
13+
'vite.config.ts',
14+
'packages/clients/.eslintrc.cjs',
15+
'eslint.config.mjs',
16+
'packages/clients/src/vendor/base64/index.js',
17+
],
18+
},
19+
{
20+
files: ['packages_generated/**/*.ts'],
21+
languageOptions: {
22+
parser: typescriptParser,
23+
parserOptions: {
24+
project: null, // ou ['tsconfig.json'] si tu veux du typed linting
25+
},
26+
},
27+
plugins: {
28+
'unused-imports': unusedImports,
29+
import: importPlugin,
30+
// ajoute d'autres plugins si besoin
31+
},
32+
rules: {
33+
// Mets ici les règles que tu veux pour le généré
34+
'object-shorthand': ['error', 'always'],
35+
'arrow-body-style': ['error', 'as-needed'],
36+
'unused-imports/no-unused-imports': 'error',
37+
'unused-imports/no-unused-vars': [
38+
'warn',
39+
{
40+
vars: 'all',
41+
args: 'all',
42+
argsIgnorePattern: 'defaults|request',
43+
},
44+
],
45+
'sort-imports': [
46+
'error',
47+
{
48+
ignoreDeclarationSort: true,
49+
},
50+
],
51+
'no-useless-escape': 'off',
52+
'import/order': [
53+
'error',
54+
{
55+
alphabetize: {
56+
order: 'asc',
57+
},
58+
},
59+
],
60+
},
61+
},
62+
]

formatting/generate.ts

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import fs from 'node:fs'
2+
import path from 'node:path'
3+
import process from 'node:process'
4+
5+
const { ENTRY_POINT } = process.env
6+
7+
// https://gitlab.infra.online.net/protobuf/pipelines/-/blob/main/scripts/global/update-all-protobuf.sh#L578
8+
if (!ENTRY_POINT) {
9+
throw new Error('ENTRY_POINT is not defined')
10+
}
11+
12+
const INPUT_PATH_DIR = path.resolve(process.cwd(), ENTRY_POINT)
13+
14+
const DEFAULT_GENERATED_EXPORT_PATH = 'index.gen.ts' as const
15+
16+
const PRODUCT_EXPORT_FILE =
17+
`${INPUT_PATH_DIR}/${DEFAULT_GENERATED_EXPORT_PATH}` as const
18+
19+
const AUTO_GENERATE_MESSAGE = `/**
20+
* This file is automatically generated from /scripts/generate.js
21+
* PLEASE DO NOT EDIT HERE
22+
*/\n
23+
` as const
24+
25+
const CUSTOM = {
26+
/** Std is use for type generation */
27+
PRODUCT_EXPORT: new Set(['std']),
28+
/** Theses product are manually update to add waitFor... */
29+
PRODUCT_VERSION_EXPORT: new Set([
30+
'baremetal/v1',
31+
'instance/v1',
32+
'k8s/v1',
33+
'lb/v1',
34+
]),
35+
}
36+
37+
const upperFirst = (str: string) =>
38+
str.slice(0, 1).toUpperCase() + str.slice(1, str.length)
39+
40+
const snakeToPascal = (str: string) =>
41+
str
42+
.split('_')
43+
.map(s => upperFirst(s.split('/').map(upperFirst).join('/')))
44+
.join('')
45+
46+
const exportProductVersions = (productDir: string) => {
47+
const fullPath = path.join(INPUT_PATH_DIR, productDir)
48+
const versionDirs = fs.readdirSync(fullPath)
49+
50+
const pathFile = `${fullPath}/${DEFAULT_GENERATED_EXPORT_PATH}` as const
51+
52+
fs.writeFileSync(pathFile, AUTO_GENERATE_MESSAGE)
53+
54+
for (const versionDir of versionDirs) {
55+
const pathVersion = `${fullPath}/${versionDir}`
56+
57+
if (fs.statSync(pathVersion).isDirectory()) {
58+
const exportPath = CUSTOM.PRODUCT_VERSION_EXPORT.has(
59+
`${productDir}/${versionDir}`,
60+
)
61+
? `./${versionDir}/index`
62+
: `./${versionDir}/index.gen`
63+
64+
fs.appendFileSync(
65+
pathFile,
66+
`\nexport * as ${versionDir} from '${exportPath}'`,
67+
)
68+
}
69+
}
70+
}
71+
72+
/**
73+
* This function will an index.ts with an export of all product. Std is a custom
74+
* export as it's only serve for types.
75+
*/
76+
const exportProducts = () => {
77+
const productsDirs = fs.readdirSync(INPUT_PATH_DIR)
78+
const productExports = []
79+
80+
fs.writeFileSync(PRODUCT_EXPORT_FILE, AUTO_GENERATE_MESSAGE)
81+
82+
for (const productDir of productsDirs) {
83+
const fullPath = path.join(INPUT_PATH_DIR, productDir)
84+
85+
if (fs.statSync(fullPath).isDirectory()) {
86+
if (!CUSTOM.PRODUCT_EXPORT.has(productDir)) {
87+
exportProductVersions(productDir)
88+
}
89+
90+
fs.appendFileSync(
91+
PRODUCT_EXPORT_FILE,
92+
`\nimport * as ${snakeToPascal(productDir)} from './${productDir}/index.gen'`,
93+
)
94+
95+
productExports.push(snakeToPascal(productDir))
96+
}
97+
}
98+
99+
fs.appendFileSync(
100+
`${PRODUCT_EXPORT_FILE}`,
101+
`\n\nexport { ${productExports.toString()}}`,
102+
)
103+
}
104+
105+
exportProducts()

formatting/generatePackages.ts

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import fs from 'node:fs'
2+
import path from 'node:path'
3+
import process from 'node:process'
4+
5+
const SOURCE_DIR = 'src'
6+
const DEFAULT_GENERATED_EXPORT_PATH = 'index.gen.ts'
7+
8+
const AUTO_GENERATE_MESSAGE = `/**
9+
* This file is automatically generated
10+
* PLEASE DO NOT EDIT HERE
11+
*/\n
12+
`
13+
14+
const { ENTRY_POINT } = process.env
15+
16+
// https://gitlab.infra.online.net/protobuf/pipelines/-/blob/main/scripts/global/update-all-protobuf.sh#L578
17+
if (!ENTRY_POINT) {
18+
throw new Error('ENTRY_POINT is not defined')
19+
}
20+
21+
const INPUT_PATH_DIR = path.resolve(process.cwd(), ENTRY_POINT)
22+
23+
const CUSTOM = {
24+
/** Std is use for type generation */
25+
PRODUCT_EXPORT: new Set(['std']),
26+
/** Theses product are manually update to add waitFor... */
27+
// DEACTIVATED FOR NOW
28+
PRODUCT_VERSION_EXPORT: new Set([
29+
'',
30+
// 'baremetal/v1',
31+
// This product is fully rewritten
32+
'instance/v1',
33+
// K8s export a protected function
34+
'k8s/v1',
35+
// Manual
36+
'payment/v1',
37+
'billing/v1',
38+
]),
39+
}
40+
41+
// const snakeToSlug = (str: string) => str.split('_').join('-')
42+
const upperFirst = (str: string) =>
43+
str.slice(0, 1).toUpperCase() + str.slice(1, str.length)
44+
const snakeToPascal = (str: string) =>
45+
str
46+
.split('_')
47+
.map(s => upperFirst(s.split('/').map(upperFirst).join('/')))
48+
.join('')
49+
50+
const exportProductVersions = (productDir: string) => {
51+
const fullPath = path.join(INPUT_PATH_DIR, productDir, SOURCE_DIR)
52+
const versionDirs = fs.readdirSync(fullPath)
53+
54+
const pathFile = `${fullPath}/${DEFAULT_GENERATED_EXPORT_PATH}` as const
55+
56+
fs.writeFileSync(pathFile, AUTO_GENERATE_MESSAGE)
57+
58+
for (const versionDir of versionDirs) {
59+
const pathVersion = `${fullPath}/${versionDir}`
60+
61+
if (fs.statSync(pathVersion).isDirectory()) {
62+
const exportPath = CUSTOM.PRODUCT_VERSION_EXPORT.has(
63+
`${productDir}/${versionDir}`,
64+
)
65+
? `./${versionDir}/index`
66+
: `./${versionDir}/index.gen`
67+
68+
fs.appendFileSync(
69+
pathFile,
70+
`\nexport * as ${snakeToPascal(productDir)}${versionDir} from '${exportPath}'`,
71+
)
72+
}
73+
}
74+
}
75+
76+
/**
77+
* This function will an index.ts with an export of all product. Std is a custom
78+
* export as it's only serve for types.
79+
*/
80+
const exportProducts = () => {
81+
const productsDirs = fs.readdirSync(INPUT_PATH_DIR)
82+
const productExports = []
83+
84+
for (const productDir of productsDirs) {
85+
const fullPath = path.join(INPUT_PATH_DIR, productDir)
86+
87+
if (fs.statSync(fullPath).isDirectory()) {
88+
if (!CUSTOM.PRODUCT_EXPORT.has(productDir)) {
89+
exportProductVersions(productDir)
90+
}
91+
92+
productExports.push(snakeToPascal(productDir))
93+
}
94+
}
95+
}
96+
97+
exportProducts()

formatting/package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "formatting",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"license": "MIT",
6+
"type": "module",
7+
"packageManager": "[email protected]",
8+
"engines": {
9+
"yarn": "1.22.x",
10+
"node": ">=18.x",
11+
"pnpm": ">=9.x"
12+
},
13+
"scripts": {
14+
"format": "pnpm biome check --linter-enabled=false --write ."
15+
},
16+
"devDependencies": {
17+
"@biomejs/biome": "2.0.6",
18+
"@typescript-eslint/eslint-plugin": "7.18.0",
19+
"@typescript-eslint/parser": "8.26.1",
20+
"@types/node": "20.17.24",
21+
"eslint": "8.57.1",
22+
"eslint-import-resolver-typescript": "3.8.7",
23+
"eslint-plugin-import": "2.31.0",
24+
"eslint-plugin-unused-imports": "3.2.0",
25+
"typescript": "5.8.2",
26+
"tsx": "4.19.3"
27+
}
28+
}

0 commit comments

Comments
 (0)