Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(codemod): Introduce codemod package #1287

Merged
merged 1 commit into from
Feb 20, 2024
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
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = {
'packages/web-react',
'packages/web',
'packages/form-validations',
'packages/codemods',
'exporters/scss',
'exporters/js',
],
Expand Down
18 changes: 18 additions & 0 deletions packages/codemods/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# .eslintignore

node_modules

# NOTE:
# The following directives are only relevant when linting the whole
# project directory, ie. running `eslint .` ⚠️

# If you compile JavaScript into some output folder, exclude it here
dist
build

# Highly recommended to re-include JavaScript dotfiles to lint them
# (This will cause .eslintrc.js to be linted by ESLint 🤘)
!.*.js

# Some tools use this pattern for their configuration files. Lint them!
!*.config.js
46 changes: 46 additions & 0 deletions packages/codemods/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module.exports = {
extends: [
'../../.eslintrc',
'plugin:@typescript-eslint/recommended',
'prettier',
'plugin:prettier/recommended',
'@lmc-eu/eslint-config-jest',
],

parser: '@typescript-eslint/parser', // the TypeScript parser we installed earlier

parserOptions: {
ecmaVersion: 'latest',
project: './config/tsconfig.eslint.json',
},

settings: {
'import/resolver': {
node: {
extensions: ['.js', '.ts'],
},
},
},

plugins: ['promise', '@typescript-eslint', 'prettier'],
rules: {
// disable for `scripts` and `config`
'@typescript-eslint/no-var-requires': 'off',
// allow ++ in for loops
'no-plusplus': ['error', { allowForLoopAfterthoughts: true }],
// disabled due to typescript
'no-shadow': 'off',
'@typescript-eslint/no-shadow': ['error', { allow: ['resolve', 'reject', 'done', 'next', 'error'] }],
// disabled due to typescript
'no-use-before-define': 'off',
'@typescript-eslint/no-use-before-define': 'warn',
// We are using typescript, disable jsdoc rules
'jsdoc/require-jsdoc': 'off',
'jsdoc/require-returns': 'off',
'jsdoc/require-param-type': 'off',
// allow reassign in properties
'no-param-reassign': ['warn', { props: false }],
// support monorepos
'import/no-extraneous-dependencies': ['error', { packageDir: ['./', '../../'] }],
},
};
11 changes: 11 additions & 0 deletions packages/codemods/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Dependency directory
node_modules

# Caches
.cache

# Log files
*.log

# Code coverage
.coverage
Empty file.
21 changes: 21 additions & 0 deletions packages/codemods/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 LMC s.r.o.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
5 changes: 5 additions & 0 deletions packages/codemods/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# @lmc-eu/spirit-codemods

## Install

## Usage
49 changes: 49 additions & 0 deletions packages/codemods/config/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const config = {
// The root directory that Jest should scan for tests and modules within.
// https://jestjs.io/docs/configuration#rootdir-string
rootDir: '../',

// This option tells Jest that all imported modules in your tests should be mocked automatically.
// https://jestjs.io/docs/configuration#automock-boolean
automock: false,

// Indicates whether each individual test should be reported during the run.
// https://jestjs.io/docs/configuration#verbose-boolean
verbose: false,

// A map from regular expressions to paths to transformers
// https://jestjs.io/docs/configuration#transform-objectstring-pathtotransformer--pathtotransformer-object
transform: {
'^.+\\.(t|j)s?$': ['<rootDir>/../../node_modules/@swc/jest'],
},

// An array of regexp pattern strings that are matched against all test paths before executing the test
// https://jestjs.io/docs/configuration#testpathignorepatterns-arraystring
testPathIgnorePatterns: ['<rootDir>/dist/', '<rootDir>/node_modules/', '.*__tests__/.*DataProvider.ts'],

// The directory where Jest should output its coverage files.
// https://jestjs.io/docs/configuration#coveragedirectory-string
coverageDirectory: './.coverage',

// An array of glob patterns indicating a set of files for which coverage information should be collected.
// https://jestjs.io/docs/configuration#collectcoveragefrom-array
collectCoverageFrom: ['<rootDir>/src/**/*.{js,ts}', '!<rootDir>/src/**/*.d.ts'],

// An array of regexp pattern strings that are matched against all file paths before executing the test.
// https://jestjs.io/docs/configuration#coveragepathignorepatterns-arraystring
coveragePathIgnorePatterns: ['__fixtures__', '__testfixtures__', 'bin'],

// A list of reporter names that Jest uses when writing coverage reports. Any istanbul reporter can be used.
// https://jestjs.io/docs/configuration#coveragereporters-arraystring--string-options
coverageReporters: ['text', 'text-summary', ['lcov', { projectRoot: '../../' }]],

// An array of regexp pattern strings that are matched against all source file paths before transformation.
// https://jestjs.io/docs/configuration#transformignorepatterns-arraystring
transformIgnorePatterns: ['<rootDir>/../../node_modules/zx'],

// An array of regexp pattern strings that are matched against all module paths before those paths are 'visible' to the loader.
// https://jestjs.io/docs/configuration#modulepathignorepatterns-arraystring
modulePathIgnorePatterns: ['<rootDir>/dist/'],
};

export default config;
4 changes: 4 additions & 0 deletions packages/codemods/config/tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../tsconfig.json",
"include": ["../", "../.eslintrc.cjs"]
}
7 changes: 7 additions & 0 deletions packages/codemods/config/tsconfig.prod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"noEmit": false
},
"exclude": ["../docs/**/*", "../src/**/__tests__/**/*"]
}
9 changes: 9 additions & 0 deletions packages/codemods/config/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from 'tsup';

export default defineConfig({
entry: ['src/index.ts'],
format: ['esm', 'cjs'],
dts: true,
splitting: true,
clean: true,
});
58 changes: 58 additions & 0 deletions packages/codemods/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"name": "@lmc-eu/spirit-codemods",
"version": "0.0.0",
"description": "Codemods scripts for Spirit Design System packages",
"license": "MIT",
"keywords": [
"spirit",
"codemods",
"design-system"
],
"repository": {
"type": "git",
"url": "https://github.com/lmc-eu/spirit-design-system.git",
"directory": "packages/codemods"
},
"publishConfig": {
"access": "public",
"directory": "dist"
},
"main": "./index.cjs",
"module": "./index.js",
"types": "./index.d.ts",
"bin": "./bin/spirit-codemods.js",
"type": "module",
"exports": {
".": {
"import": "./index.js",
"require": "./index.cjs"
},
"./package.json": "./package.json"
},
"scripts": {
"prebuild": "shx rm -rf dist && shx mkdir -p dist",
"build": "tsup --config ./config/tsup.config.ts",
"postbuild": "shx cp -r package.json README.md src/bin dist/",
"start": "tsup src/index.ts --watch",
"types": "tsc",
"lint": "eslint ./",
"lint:fix": "yarn lint --fix",
"test": "npm-run-all --serial lint test:unit:coverage types",
"test:unit": "jest --passWithNoTests --config ./config/jest.config.js",
pavelklibani marked this conversation as resolved.
Show resolved Hide resolved
"test:unit:watch": "yarn test:unit --watchAll",
"test:unit:coverage": "yarn test:unit --coverage"
},
"dependencies": {
"jscodeshift": "^0.15.1"
},
"devDependencies": {
"@lmc-eu/eslint-config-jest": "3.0.2",
"@types/jest": "29.5.11",
"@types/node": "20.10.7",
"@typescript-eslint/eslint-plugin": "6.18.0",
"@typescript-eslint/parser": "6.18.0",
"jest": "29.7.0",
"shx": "0.3.4",
"tsup": "7.2.0"
}
}
3 changes: 3 additions & 0 deletions packages/codemods/src/bin/spirit-codemod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// TODO: will be removed in next issue: https://jira.almacareer.tech/browse/DS-1142
// eslint-disable-next-line no-console
console.log('spirit-codemods');
pavelklibani marked this conversation as resolved.
Show resolved Hide resolved
Empty file.
32 changes: 32 additions & 0 deletions packages/codemods/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"compileOnSave": true,
"compilerOptions": {
"moduleResolution": "node",
"baseUrl": ".",
"sourceMap": true,
"declaration": true,
"noEmit": true,
"removeComments": true,
"noEmitOnError": true,
"forceConsistentCasingInFileNames": true,
"strictNullChecks": true,
"strictPropertyInitialization": true,
"strictFunctionTypes": true,
"resolveJsonModule": true,
"allowUnreachableCode": false,
"allowSyntheticDefaultImports": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noImplicitReturns": true,
"noUnusedParameters": false,
"noUnusedLocals": true,
"noImplicitAny": true,
"esModuleInterop": true,
"skipLibCheck": true,
"typeRoots": ["../../node_modules/@types"],
"types": ["node", "jest"],
"module": "es2020"
},
"include": ["./", "./.eslintrc.js"],
"exclude": ["./node_modules"]
}
Loading