Skip to content
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
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules/
dist/
formatting/

package.json
package.json
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ lint:
pnpm run lint

test:
pnpm turbo test
pnpm run test

test-coverage:
pnpm run test:coverage
Expand All @@ -45,3 +45,7 @@ publish: install-dependencies
pnpm run build
pnpm lerna changed
pnpm exec lerna publish -y --registry $(NPM_PUBLISH_REGISTRY) --ignore-scripts

format-generated:
./formatting/run.sh -i "./packages_generated" -f "new-package"

3 changes: 2 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"*.snap",
"**/__snapshots__/",
".docusaurus",
".vitest-reports"
".vitest-reports",
"formatting/**"
]
},
"formatter": {
Expand Down
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default [
'packages/configuration-loader/.eslintrc.cjs',
'scripts/generatePackages.ts',
'scripts/*.ts',
'formatting/**',
],
},
{
Expand Down
63 changes: 63 additions & 0 deletions formatting/biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
"vcs": {
"clientKind": "git",
"useIgnoreFile": false,
"defaultBranch": "main"
},
"formatter": {
"enabled": true,
"formatWithErrors": false,
"indentStyle": "space",
"indentWidth": 2,
"lineEnding": "lf",
"lineWidth": 80
},
"javascript": {
"formatter": {
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"trailingCommas": "all",
"semicolons": "asNeeded",
"arrowParentheses": "asNeeded",
"bracketSpacing": true,
"bracketSameLine": false,
"quoteStyle": "single"
}
},
"json": {
"formatter": {
"enabled": true
},
"parser": {
"allowComments": true
}
},
"linter": {
"enabled": false
},
"files": {
"maxSize": 10000000,
"ignoreUnknown": true,
"include": ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx", "**/*.json"],
"ignore": [
".next/",
".pnpm-store/",
"coverage/",
"/public/outdated",
"/public/.well-known",
"**/node_modules/",
".turbo/**",
"dist",
"build",
"out",
"node_modules/**",
"**/pnpm-lock.yaml",
"**/package.json",
"**/CHANGELOG.md",
"*.snap",
"**/__snapshots__/",
".vitest-reports"
]
}
}
60 changes: 60 additions & 0 deletions formatting/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import tsPlugin from '@typescript-eslint/eslint-plugin'
import typescriptParser from '@typescript-eslint/parser'
import importPlugin from 'eslint-plugin-import'
import unusedImports from 'eslint-plugin-unused-imports'

export default [
{
ignores: [
'**/node_modules/',
'**/dist/',
'**/examples/',
'**/vite.config.ts',
'vite.config.ts',
'packages/clients/.eslintrc.cjs',
'eslint.config.mjs',
'packages/clients/src/vendor/base64/index.js',
],
},
{
files: ['packages_generated/**/*.ts'],
languageOptions: {
parser: typescriptParser,
parserOptions: {
project: null,
},
},
plugins: {
'unused-imports': unusedImports,
import: importPlugin,
},
rules: {
'object-shorthand': ['error', 'always'],
'arrow-body-style': ['error', 'as-needed'],
'unused-imports/no-unused-imports': 'error',
'unused-imports/no-unused-vars': [
'warn',
{
vars: 'all',
args: 'all',
argsIgnorePattern: 'defaults|request',
},
],
'sort-imports': [
'error',
{
ignoreDeclarationSort: true,
},
],
'no-useless-escape': 'off',
'import/order': [
'error',
{
alphabetize: {
order: 'asc',
},
},
],
},
},
]
104 changes: 104 additions & 0 deletions formatting/generate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import fs from 'node:fs'
import path from 'node:path'
import process from 'node:process'

const { ENTRY_POINT } = process.env

if (!ENTRY_POINT) {
throw new Error('ENTRY_POINT is not defined')
}

const INPUT_PATH_DIR = path.resolve(process.cwd(), ENTRY_POINT)

const DEFAULT_GENERATED_EXPORT_PATH = 'index.gen.ts' as const

const PRODUCT_EXPORT_FILE =
`${INPUT_PATH_DIR}/${DEFAULT_GENERATED_EXPORT_PATH}` as const

const AUTO_GENERATE_MESSAGE = `/**
* This file is automatically generated from /scripts/generate.js
* PLEASE DO NOT EDIT HERE
*/\n
` as const

const CUSTOM = {
/** Std is use for type generation */
PRODUCT_EXPORT: new Set(['std']),
/** Theses product are manually update to add waitFor... */
PRODUCT_VERSION_EXPORT: new Set([
'baremetal/v1',
'instance/v1',
'k8s/v1',
'lb/v1',
]),
}

const upperFirst = (str: string) =>
str.slice(0, 1).toUpperCase() + str.slice(1, str.length)

const snakeToPascal = (str: string) =>
str
.split('_')
.map(s => upperFirst(s.split('/').map(upperFirst).join('/')))
.join('')

const exportProductVersions = (productDir: string) => {
const fullPath = path.join(INPUT_PATH_DIR, productDir)
const versionDirs = fs.readdirSync(fullPath)

const pathFile = `${fullPath}/${DEFAULT_GENERATED_EXPORT_PATH}` as const

fs.writeFileSync(pathFile, AUTO_GENERATE_MESSAGE)

for (const versionDir of versionDirs) {
const pathVersion = `${fullPath}/${versionDir}`

if (fs.statSync(pathVersion).isDirectory()) {
const exportPath = CUSTOM.PRODUCT_VERSION_EXPORT.has(
`${productDir}/${versionDir}`,
)
? `./${versionDir}/index`
: `./${versionDir}/index.gen`

fs.appendFileSync(
pathFile,
`\nexport * as ${versionDir} from '${exportPath}'`,
)
}
}
}

/**
* This function will an index.ts with an export of all product. Std is a custom
* export as it's only serve for types.
*/
const exportProducts = () => {
const productsDirs = fs.readdirSync(INPUT_PATH_DIR)
const productExports = []

fs.writeFileSync(PRODUCT_EXPORT_FILE, AUTO_GENERATE_MESSAGE)

for (const productDir of productsDirs) {
const fullPath = path.join(INPUT_PATH_DIR, productDir)

if (fs.statSync(fullPath).isDirectory()) {
if (!CUSTOM.PRODUCT_EXPORT.has(productDir)) {
exportProductVersions(productDir)
}

fs.appendFileSync(
PRODUCT_EXPORT_FILE,
`\nimport * as ${snakeToPascal(productDir)} from './${productDir}/index.gen'`,
)

productExports.push(snakeToPascal(productDir))
}
}

fs.appendFileSync(
`${PRODUCT_EXPORT_FILE}`,
`\n\nexport { ${productExports.toString()}}`,
)
}

exportProducts()
96 changes: 96 additions & 0 deletions formatting/generatePackages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import fs from 'node:fs'
import path from 'node:path'
import process from 'node:process'

const SOURCE_DIR = 'src'
const DEFAULT_GENERATED_EXPORT_PATH = 'index.gen.ts'

const AUTO_GENERATE_MESSAGE = `/**
* This file is automatically generated
* PLEASE DO NOT EDIT HERE
*/\n
`

const { ENTRY_POINT } = process.env

if (!ENTRY_POINT) {
throw new Error('ENTRY_POINT is not defined')
}

const INPUT_PATH_DIR = path.resolve(process.cwd(), ENTRY_POINT)

const CUSTOM = {
/** Std is use for type generation */
PRODUCT_EXPORT: new Set(['std']),
/** Theses product are manually update to add waitFor... */
// DEACTIVATED FOR NOW
PRODUCT_VERSION_EXPORT: new Set([
'',
// 'baremetal/v1',
// This product is fully rewritten
'instance/v1',
// K8s export a protected function
'k8s/v1',
// Manual
'payment/v1',
'billing/v1',
]),
}

// const snakeToSlug = (str: string) => str.split('_').join('-')
const upperFirst = (str: string) =>
str.slice(0, 1).toUpperCase() + str.slice(1, str.length)
const snakeToPascal = (str: string) =>
str
.split('_')
.map(s => upperFirst(s.split('/').map(upperFirst).join('/')))
.join('')

const exportProductVersions = (productDir: string) => {
const fullPath = path.join(INPUT_PATH_DIR, productDir, SOURCE_DIR)
const versionDirs = fs.readdirSync(fullPath)

const pathFile = `${fullPath}/${DEFAULT_GENERATED_EXPORT_PATH}` as const

fs.writeFileSync(pathFile, AUTO_GENERATE_MESSAGE)

for (const versionDir of versionDirs) {
const pathVersion = `${fullPath}/${versionDir}`

if (fs.statSync(pathVersion).isDirectory()) {
const exportPath = CUSTOM.PRODUCT_VERSION_EXPORT.has(
`${productDir}/${versionDir}`,
)
? `./${versionDir}/index`
: `./${versionDir}/index.gen`

fs.appendFileSync(
pathFile,
`\nexport * as ${snakeToPascal(productDir)}${versionDir} from '${exportPath}'`,
)
}
}
}

/**
* This function will an index.ts with an export of all product. Std is a custom
* export as it's only serve for types.
*/
const exportProducts = () => {
const productsDirs = fs.readdirSync(INPUT_PATH_DIR)
const productExports = []

for (const productDir of productsDirs) {
const fullPath = path.join(INPUT_PATH_DIR, productDir)

if (fs.statSync(fullPath).isDirectory()) {
if (!CUSTOM.PRODUCT_EXPORT.has(productDir)) {
exportProductVersions(productDir)
}

productExports.push(snakeToPascal(productDir))
}
}
}

exportProducts()
28 changes: 28 additions & 0 deletions formatting/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "formatting",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"type": "module",
"packageManager": "pnpm@10.7.0",
"engines": {
"yarn": "1.22.x",
"node": ">=18.x",
"pnpm": ">=9.x"
},
"scripts": {
"format": "pnpm biome check --linter-enabled=false --write ."
},
"devDependencies": {
"@biomejs/biome": "2.0.6",
"@typescript-eslint/eslint-plugin": "7.18.0",
"@typescript-eslint/parser": "8.26.1",
"@types/node": "20.17.24",
"eslint": "8.57.1",
"eslint-import-resolver-typescript": "3.8.7",
"eslint-plugin-import": "2.31.0",
"eslint-plugin-unused-imports": "3.2.0",
"typescript": "5.8.2",
"tsx": "4.19.3"
}
}
Loading
Loading