Skip to content

Commit

Permalink
feat(project-types): updated project types to have latest eslint and …
Browse files Browse the repository at this point in the history
…typedoc configurations

ESLint now uses version 9.0 and the configuration files were updated to use a flat config file. The
TypeDoc documentation now uses a custom thme and and fixes some bugs.

BREAKING CHANGE: The task copy now has different arguments expected.

fix #7
  • Loading branch information
alanrodas committed Sep 4, 2024
1 parent f07a82f commit 35cf4ba
Show file tree
Hide file tree
Showing 44 changed files with 434 additions and 331 deletions.
10 changes: 6 additions & 4 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@ echo ""
echo "\nAdd license text to code files\n"
npx --no -- nps license

# Run changelog
echo "\nRun changelog\n"
if git-log &> /dev/null; then
npx --no -- nps changelog
fi

# Run prettify
echo "Run prettify\n"
npx --no -- nps prettify

# Run changelog
echo "\nRun changelog\n"
npx --no -- nps changelog

# Add all generated files
echo "\nAdd generated files to commit\n"
git add --all
Expand Down
24 changes: 22 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
## <small>0.9.1 (2024-08-19)</small>
## <small>0.9.1 (2024-09-04)</small>

- feat(project-types): updated project types to have latest eslint and typedoc configurations ([761676d](https://github.com/gobstones/gobstones-scripts/commit/761676d)), closes [#7](https://github.com/gobstones/gobstones-scripts/issues/7)
- fix(cli): fix a bug preventing the use of package.json config when using CLI ([f07a82f](https://github.com/gobstones/gobstones-scripts/commit/f07a82f))

### BREAKING CHANGE

- The task copy now has different arguments expected.

## <small>0.9.1 (2024-09-03)</small>

* fix(cli): fix a bug preventing the use of package.json config when using CLI ([00698dd](https://github.com/gobstones/gobstones-scripts/commit/00698dd))
- feat(project-types): updated project types to have latest eslint and typedoc configurations ([5e9e91f](https://github.com/gobstones/gobstones-scripts/commit/5e9e91f)), closes [#7](https://github.com/gobstones/gobstones-scripts/issues/7)
- fix(cli): fix a bug preventing the use of package.json config when using CLI ([f07a82f](https://github.com/gobstones/gobstones-scripts/commit/f07a82f))

### BREAKING CHANGE

- The task copy now has different arguments expected.

## <small>0.9.1 (2024-08-27)</small>

- fix(cli): fix a bug preventing the use of package.json config when using CLI ([f07a82f](https://github.com/gobstones/gobstones-scripts/commit/f07a82f))

## <small>0.9.1 (2024-08-19)</small>

- fix(cli): fix a bug preventing the use of package.json config when using CLI ([00698dd](https://github.com/gobstones/gobstones-scripts/commit/00698dd))

## <small>0.9.1 (2024-08-18)</small>

Expand Down
60 changes: 23 additions & 37 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path';
import { fileURLToPath } from 'url';

import { fixupPluginRules, includeIgnoreFile } from '@eslint/compat';
import { includeIgnoreFile } from '@eslint/compat';
import { FlatCompat } from '@eslint/eslintrc';
import eslintJs from '@eslint/js';
import eslintPluginNoNull from 'eslint-plugin-no-null';
Expand All @@ -10,61 +10,47 @@ import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended'
import globals from 'globals';
import eslintTs from 'typescript-eslint';

const tsConfigPath = './tsconfig.json';
const baseUrl = path.resolve(path.dirname(fileURLToPath(import.meta.url)));

// eslint-disable-next-line no-unused-vars
const _jsFiles = ['src/**/*.js', 'src/**/*.jsx', 'src/**/*.mjs', 'src/**/*.cjs'];
const _tsFiles = ['src/**/*.ts', 'src/**/*.tsx', 'src/**/*.mts', 'src/**/*.cts'];
const tsConfigPath = path.join(baseUrl, 'tsconfig.json');
const gitignorePath = path.join(baseUrl, '.gitignore');

const compat = new FlatCompat({
baseDirectory: baseUrl,
recommendedConfig: eslintJs.configs.recommended
});

const withFilesOnly = (config, files) =>
config.map((e) => {
e.files = files;
return e;
});

// region Compatibility with old plugins section
const compat = new FlatCompat({
baseDirectory: path.dirname(fileURLToPath(import.meta.url)),
recommendedConfig: eslintJs.configs.recommended
});

/**
* @param {string} name the plugin name
* @param {string} alias the plugin alias
* @returns {import("eslint").ESLint.Plugin}
*/
// eslint-disable-next-line no-unused-vars
const legacyPlugin = (name, alias = name) => {
const plugin = compat.plugins(name)[0]?.plugins?.[alias];

if (!plugin) {
throw new Error(`Unable to resolve plugin ${name} and/or alias ${alias}`);
}

return fixupPluginRules(plugin);
};

const gitignorePath = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '.gitignore');
// #endregion Compatibility with old plugins section

// recommended configuration only for ts files
const _jsFiles = ['src/**/*.js', 'src/**/*.jsx', 'src/**/*.mjs', 'src/**/*.cjs'];
const _tsFiles = ['src/**/*.ts', 'src/**/*.tsx', 'src/**/*.mts', 'src/**/*.cts'];
const _codeFiles = [..._jsFiles, ..._tsFiles];

const config = eslintTs.config(
// Add all .gitignore files to the ignore path
includeIgnoreFile(gitignorePath),
// Asure oackage-scripts as CJS, to avoid no-undef issues
{ files: ['**/package-scripts.js'], languageOptions: { globals: globals.node } },
// Recommended settings from ESLint for JS
eslintJs.configs.recommended,
// Prettier plugin usage
eslintPluginPrettierRecommended,
// Import default settings. Import is not yet ESLint 9 compatible
...compat.extends(
'plugin:import/recommended',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript'
...withFilesOnly(
compat.extends(
'plugin:import/recommended',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript'
),
_codeFiles
),
// Custom settings and rules for all JS and TS files
{
files: _codeFiles,
linterOptions: {
reportUnusedDisableDirectives: true
},
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"packageManager": "[email protected]",
"scripts": {
"prepare": "husky",
"prepack": "npm start build",
"start": "nps"
},
"dependencies": {
Expand Down Expand Up @@ -75,6 +76,7 @@
"@storybook/react": "^8.2.8",
"@storybook/react-vite": "^8.2.8",
"@storybook/theming": "^8.2.8",
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.4.8",
"@testing-library/react": "^16.0.0",
"@types/command-exists": "^1.2.3",
Expand Down Expand Up @@ -135,7 +137,6 @@
"tsconfig.js": "^3.0.0",
"tsx": "^4.17.0",
"typedoc": "^0.26.5",
"typedoc-plugin-mdn-links": "^3.2.7",
"typescript": "^5.5.4",
"typescript-eslint": "^8.0.1",
"vite": "^5.4.0"
Expand Down
8 changes: 4 additions & 4 deletions project-types/CLILibrary/package-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ const defaultConfiguration = {
},

changelog: {
script: tasks.npx('conventional-changelog -p angular -i CHANGELOG.md -s'),
script: tasks.changelog(),
description: 'Generate changelog based on commits',
hiddenFromHelp: true,
scratch: {
script: tasks.npx('conventional-changelog -p angular -i CHANGELOG.md -s -r 0'),
script: tasks.changelog({ scratch: true }),
description: 'Generate changelog based on tags, starting from scratch',
hiddenFromHelp: true
}
},
hiddenFromHelp: true
},

license: {
Expand Down
4 changes: 4 additions & 0 deletions project-types/CLILibrary/src/@i18n/en/cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"version": "Display the version",
"help": "Display the help"
},
"commands": {
"awesome": "The awesome command",
"notcool": "The not cool command"
},
"errors": {
"file": "File does not exist",
"language": "Locale does not exist"
Expand Down
42 changes: 11 additions & 31 deletions project-types/CLILibrary/src/@i18n/es/cli.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,18 @@
{
"descriptions": {
"commands": {
"create": "crea un nuevo proyecto en la carpeta con el nombre del mismo",
"init": "inicializa un proyecto en la carpeta actual",
"update": "actualiza los archivos de la raíz del proyecto",
"eject": "extrae y presenta los archivos de configuración en la raíz del proyecto",
"run": "ejecuta un comando con nps con la configuración de gobstones-scrips"
},
"args": {
"config": "muestra la configuración de la herramienta",
"type": "el tipo de proyecto a crear, alguno de {{options}}\"",
"packageManager": "el manejador de proyectos a utilizar, alguno de {{options}}",
"silent": "correr silenciosamente, sin mostrar la cabecera de la herramienta",
"debug": "correr en modo de depuración, imprimiendo toda la traza de ejecución del código",
"test": "correr usando verdaccio como registro",
"useLocalTsconfigJson": "usar el archivo de configuración tsconfig.json de la raíz del proyecto"
}
"language": "El idioma en el que corre la herramienta",
"in": "El archivo de entrada",
"out": "El archivo de salida",
"tool": "La herraminta mas asombrosa",
"version": "Muestra la versión",
"help": "Muestra la ayuda"
},
"messages": {
"welcome": "Bienvenido a gobstones-scripts versión {{version}}",
"creatingProject": "Creando un proyecto con el nombre '{{projectName}}' del tipo '{{projectType}}' usando el manejador '{{packageManager}}'.",
"initializingProject": "Inicializando un proyecto en el directorio actual del tipo '{{projectType}}' usando el manejador '{{packageManager}}'.",
"updatingFiles": "Actualizando archivos del proyecto actual del tipo '{{projectType}}' usando el manejador '{{packageManager}}'. Archivos a actualizar: {{files}}",
"ejectingFiles": "Eyectando archivos del proyecto actual del tipo '{{projectType}}' usando el manejador '{{packageManager}}'. Archivos a eyectar: {{files}}",
"presentingCommands": "Mostranso todos los comandos para el proyecto del tipo '{{projectType}}' usando el manejador '{{packageManager}}'.",
"executingCommands": "Ejecutando comando '{{command}}' en proyecto del tipo '{{projectType}}' usando el manejador '{{packageManager}}'.",
"configuration": "La configuración del proyecto es:\n\n\tTipo de proyecto: {{projectType}}\n\tManejador de proyecto: {{projectManager}}\n\tCorriendo en modo test: {{isTestMode}}\n\tCorriendo en modo depuración: {{isDebugMode}}\n\tUsando el archivo tsconfig.json: {{usingLocalTsConfig}}\n\tUsando rutas completas: {{usingFullPaths}}\n",
"folders": "La carpeta raíz detectada es:\n\t{{- rootFolder}}\n\nLa carpeta raíz de gobstones-scripts es:\n\t{{- gobstonesScriptsFolder}}\n",
"files": "Los archivos {{pathType}} para usar como configuración son:"
"commands": {
"awesome": "El comando awesome",
"notcool": "El comando notCool"
},
"errors": {
"invalidOption": "El valor '{{optionValue}}' no es una opción válida para el argumento '{{optionName}}'\nPor favor, seleccione alguno de los siguientes: {{options}}",
"unexpected": "Ocurrió un error inesperado. Ejecuta la herramienta en modo de depuración para ver el mensaje completo de error.",
"emptyFolder": "La carpeta objetivo debe estar vacía (la carpeta actual en caso de init, o la del mismo nombre del proyecto en caso de create), sin embargo contiene elementos.\nAseguresé de que la carpeta está vacía y vuelva a intentar.",
"undefinedTsConfig": "La configuración actual indica que se va a usar un archivo tsconfig.json en la raíz del proyecto, pero el archivo no existe."
"file": "El archivo no existe",
"language": "El idioma no existe"
}
}
11 changes: 5 additions & 6 deletions project-types/CLILibrary/src/@i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
* You may read the full license at https://gobstones.github.io/gobstones-guidelines/LICENSE.
* *****************************************************************************
*/
/* eslint-disable import/no-extraneous-dependencies */

/* eslint-disable import/no-extraneous-dependencies, import/export*/
/**
* ----------------------------------------------------
* @module i18n
Expand All @@ -27,25 +28,23 @@ import i18next from 'i18next';
import i18nextCLILanguageDetector from 'i18next-cli-language-detector';
import i18nextBackend from 'i18next-fs-backend';

function currentPath() {
const currentPath = (): string => {
const currentModuleDir = __dirname;
const translationsFolder = '@i18n';
let nextDir = currentModuleDir;
while (!fs.existsSync(path.join(nextDir, translationsFolder))) {
nextDir = path.dirname(nextDir);
}
// eslint-disable-next-line no-console
console.log(path.join(nextDir, translationsFolder));
return path.join(nextDir, translationsFolder);
}
};

void i18next
.use(i18nextCLILanguageDetector)
.use(i18nextBackend)
.init({
initImmediate: false,
fallbackLng: 'en',
ns: ['application', 'cli'],
ns: ['application'],
backend: {
loadPath: currentPath() + '/{{lng}}/{{ns}}.json'
}
Expand Down
5 changes: 3 additions & 2 deletions project-types/CLILibrary/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* You may read the full license at https://gobstones.github.io/gobstones-guidelines/LICENSE.
* *****************************************************************************
*/

/**
* This is the file that contains the CLI program.
* One built, you may run this file from the command line.
Expand Down Expand Up @@ -46,7 +47,7 @@ cli({
version: t('cli:descriptions.version')
}
})
.command('awesome [text] [text2]', t('application:class.awesome'), (cmd) => {
.command('awesome [text] [text2]', t('cli:commands.awesome'), (cmd) => {
cmd.input(t('cli:descriptions.in'), t('cli:errors.file'))
.output('cli:descriptions.out')
.action((app, _, _opts: CLIArguments) => {
Expand All @@ -57,7 +58,7 @@ cli({
app.write(output);
});
})
.command('notCool [text]', t('application:class.notCool'), (cmd) => {
.command('notCool [text]', t('cli:commands.notcool'), (cmd) => {
cmd.input(t('cli:descriptions.in'), t('cli:errors.file'))
.output(t('cli:descriptions.out'))
.action((app, _, _opts: CLIArguments) => {
Expand Down
3 changes: 2 additions & 1 deletion project-types/CLILibrary/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* You may read the full license at https://gobstones.github.io/gobstones-guidelines/LICENSE.
* *****************************************************************************
*/

/**
* This file is the one that runs when you perform a
* npm start dev. It just imports some classes and prints
Expand All @@ -27,6 +28,6 @@ import { MyClass } from './Models';
export * from './Models/MyClass';

// eslint-disable-next-line no-console
console.log(t('program.running'));
console.log(t('application:program.running'));
// eslint-disable-next-line no-console
console.log(new MyClass().awesome('hola'));
25 changes: 25 additions & 0 deletions project-types/CLILibrary/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"ts-node": {
"compilerOptions": {
"module": "commonjs"
}
},
"compilerOptions": {
"target": "es2015",
"rootDir": "./src",
"esModuleInterop": true,
"allowJs": true,
"sourceMap": true,
"declaration": true,
"declarationMap": true,
"declarationDir": "./dist/typings",
"moduleResolution": "node",
"resolveJsonModule": true,
"stripInternal": true,
"composite": false,
"skipLibCheck": true,
"jsx": "react",
"module": "ESNext"
},
"include": ["./src/**/*"]
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
export default {
extends: ['@commitlint/config-conventional']
};
20 changes: 10 additions & 10 deletions project-types/Common/editorconfig
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# http://editorconfig.org

root = true
root=true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true
charset=utf-8
end_of_line=lf
indent_style=space
indent_size=4
trim_trailing_whitespace=true
insert_final_newline=true

[*.md]
trim_trailing_whitespace = false
trim_trailing_whitespace=false

# Use 2 spaces since npm does not respect custom indentation settings
[package.json]
indent_style = space
indent_size = 2
indent_style=space
indent_size=2
Loading

0 comments on commit 35cf4ba

Please sign in to comment.