-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a0d978
commit a8c48ab
Showing
27 changed files
with
1,243 additions
and
268 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Add files here to ignore them from prettier formatting | ||
/dist | ||
/coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"singleQuote": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,5 @@ | ||
import { getJestProjects } from '@nx/jest'; | ||
|
||
const projects = getJestProjects() | ||
.filter(project => !(project.includes('vibrant-core') || project.includes('vibrant-icons'))) | ||
.concat( | ||
'packages/vibrant-core/jest.config.web.ts', | ||
'packages/vibrant-core/jest.config.native.ts', | ||
'packages/vibrant-icons/jest.config.web.ts', | ||
'packages/vibrant-icons/jest.config.native.ts' | ||
); | ||
|
||
export default { | ||
projects, | ||
projects: getJestProjects(), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"extends": ["plugin:@nx/react", "../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*", "**/__testfixtures__/**"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"jsc": { | ||
"target": "es2016", | ||
"parser": { | ||
"syntax": "typescript", | ||
"decorators": true, | ||
"dynamicImport": true | ||
}, | ||
"transform": { | ||
"decoratorMetadata": true, | ||
"legacyDecorator": true | ||
}, | ||
"keepClassNames": true, | ||
"externalHelpers": true, | ||
"loose": true | ||
}, | ||
"module": { | ||
"type": "commonjs", | ||
"strict": true, | ||
"noInterop": true | ||
}, | ||
"sourceMaps": true, | ||
"exclude": [ | ||
"jest.config.ts", | ||
".*\\.spec.tsx?$", | ||
".*\\.test.tsx?$", | ||
"./src/jest-setup.ts$", | ||
"./**/jest-setup.ts$", | ||
".*.js$" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# vibrant-migrator | ||
|
||
This library was generated with [Nx](https://nx.dev). | ||
|
||
## Building | ||
|
||
Run `nx build vibrant-migrator` to build the library. | ||
|
||
## Running unit tests | ||
|
||
Run `nx test vibrant-migrator` to execute the unit tests via [Jest](https://jestjs.io). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* eslint-disable no-console */ | ||
|
||
const path = require('node:path'); | ||
const { run: jscodeshift } = require('jscodeshift/src/Runner'); | ||
const [, , transformer, target] = process.argv; | ||
const transformPath = path.resolve(__dirname, `../src/lib/${transformer}.js`); | ||
const paths = [target]; | ||
const options = { | ||
print: true, | ||
verbose: 1, | ||
parser: 'tsx', | ||
}; | ||
|
||
(async () => { | ||
const res = await jscodeshift(transformPath, paths, options); | ||
|
||
console.log(res); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
|
||
require('./codemod.js'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* eslint-disable */ | ||
import { readFileSync } from 'fs'; | ||
|
||
// Reading the SWC compilation config and remove the "exclude" | ||
// for the test files to be compiled by SWC | ||
const { exclude: _, ...swcJestConfig } = JSON.parse( | ||
readFileSync(`${__dirname}/.swcrc`, 'utf-8') | ||
); | ||
|
||
// disable .swcrc look-up by SWC core because we're passing in swcJestConfig ourselves. | ||
// If we do not disable this, SWC Core will read .swcrc and won't transform our test files due to "exclude" | ||
if (swcJestConfig.swcrc === undefined) { | ||
swcJestConfig.swcrc = false; | ||
} | ||
|
||
// Uncomment if using global setup/teardown files being transformed via swc | ||
// https://nx.dev/packages/jest/documents/overview#global-setup/teardown-with-nx-libraries | ||
// jest needs EsModule Interop to find the default exported setup/teardown functions | ||
// swcJestConfig.module.noInterop = false; | ||
|
||
export default { | ||
displayName: 'vibrant-migrator', | ||
preset: '../../jest.preset.js', | ||
transform: { | ||
'^.+\\.[tj]s$': ['@swc/jest', swcJestConfig], | ||
}, | ||
moduleFileExtensions: ['ts', 'js', 'html'], | ||
runner: 'jest-runner', | ||
testEnvironment: 'node', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "@vibrant-ui/migrator", | ||
"version": "0.0.1", | ||
"type": "commonjs", | ||
"bin": { | ||
"vibrant-migrator": "./bin/codemod.js" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
{ | ||
"name": "vibrant-migrator", | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "packages/vibrant-migrator/src", | ||
"projectType": "library", | ||
"targets": { | ||
"build": { | ||
"executor": "@nx/js:swc", | ||
"outputs": ["{options.outputPath}"], | ||
"options": { | ||
"outputPath": "dist/packages/vibrant-migrator", | ||
"main": "packages/vibrant-migrator/src/index.ts", | ||
"tsConfig": "packages/vibrant-migrator/tsconfig.lib.json", | ||
"assets": ["packages/vibrant-migrator/*.md", "packages/vibrant-migrator/bin/*"] | ||
} | ||
}, | ||
"typecheck": { | ||
"executor": "nx:run-commands", | ||
"options": { | ||
"commands": ["yarn tsc --project ./packages/vibrant-migrator/tsconfig.lib.json"] | ||
} | ||
}, | ||
"lint": { | ||
"executor": "@nx/linter:eslint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": ["packages/vibrant-migrator/**/*.ts"] | ||
} | ||
}, | ||
"test": { | ||
"executor": "@nx/jest:jest", | ||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"], | ||
"options": { | ||
"jestConfig": "packages/vibrant-migrator/jest.config.ts", | ||
"passWithNoTests": true | ||
}, | ||
"configurations": { | ||
"ci": { | ||
"ci": true, | ||
"codeCoverage": true | ||
} | ||
} | ||
}, | ||
"version": { | ||
"executor": "@jscutlery/semver:version", | ||
"dependsOn": ["build-native"], | ||
"options": { | ||
"preset": "conventional", | ||
"skipCommit": true, | ||
"trackDeps": true, | ||
"postTargets": ["vibrant-migrator:github", "vibrant-migrator:deploy"] | ||
} | ||
}, | ||
"github": { | ||
"executor": "@jscutlery/semver:github", | ||
"options": { | ||
"tag": "${tag}", | ||
"notes": "${notes}" | ||
} | ||
}, | ||
"deploy": { | ||
"executor": "ngx-deploy-npm:deploy", | ||
"options": { | ||
"access": "public" | ||
} | ||
} | ||
}, | ||
"tags": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import './lib/ui-system/title-replace'; |
3 changes: 3 additions & 0 deletions
3
packages/vibrant-migrator/src/lib/ui-system/__testfixtures__/title-replace/basic.input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { Title, Body } from "@class101/ui-system"; | ||
|
||
export const Hello = () => <Title>hello</Title>; |
4 changes: 4 additions & 0 deletions
4
packages/vibrant-migrator/src/lib/ui-system/__testfixtures__/title-replace/basic.output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { Body } from "@class101/ui-system"; | ||
import { Title } from "@vibrant-ui/components"; | ||
|
||
export const Hello = () => <Title>hello</Title>; |
5 changes: 5 additions & 0 deletions
5
packages/vibrant-migrator/src/lib/ui-system/__tests__/title-replace.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { defineTest } from 'jscodeshift/src/testUtils'; | ||
|
||
describe('Migrate Title Component', () => { | ||
defineTest(__dirname, './title-replace', null, 'title-replace/basic', { parser: 'babel' }); | ||
}); |
23 changes: 23 additions & 0 deletions
23
packages/vibrant-migrator/src/lib/ui-system/title-replace.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { API, FileInfo } from 'jscodeshift'; | ||
import { addImportVariable } from '../utils/addImportVariable'; | ||
import { findImportDeclarations } from '../utils/findImportDeclarations'; | ||
import { removeImportVariable } from '../utils/removeImportVariable'; | ||
|
||
export default function transformer(file: FileInfo, { jscodeshift }: API) { | ||
const root = jscodeshift(file.source); | ||
|
||
const uiSystemImports = findImportDeclarations({ root, importPackage: '@class101/ui-system', jscodeshift }); | ||
|
||
uiSystemImports.forEach(path => { | ||
removeImportVariable({ importPath: path, variableName: 'Title', jscodeshift }); | ||
|
||
addImportVariable({ | ||
importPath: path, | ||
variableName: 'Title', | ||
packageName: '@vibrant-ui/components', | ||
jscodeshift, | ||
}); | ||
}); | ||
|
||
return root.toSource(); | ||
} |
20 changes: 20 additions & 0 deletions
20
packages/vibrant-migrator/src/lib/utils/addImportVariable.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { API, ASTPath, ImportDeclaration } from 'jscodeshift'; | ||
|
||
type AddImportVariableParams = { | ||
importPath: ASTPath<ImportDeclaration>; | ||
variableName: string; | ||
packageName: string; | ||
jscodeshift: API['jscodeshift']; | ||
}; | ||
|
||
export function addImportVariable({ importPath, variableName, packageName, jscodeshift }: AddImportVariableParams) { | ||
try { | ||
jscodeshift(importPath).insertAfter( | ||
jscodeshift.importDeclaration( | ||
[jscodeshift.importSpecifier(jscodeshift.identifier(variableName))], | ||
jscodeshift.literal(packageName) | ||
) | ||
); | ||
// eslint-disable-next-line no-empty | ||
} catch {} | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/vibrant-migrator/src/lib/utils/findImportDeclarations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { API, Collection } from 'jscodeshift'; | ||
import { ImportDeclaration } from 'jscodeshift'; | ||
|
||
type FindImportDeclarationsParams = { | ||
root: Collection; | ||
importPackage: string; | ||
jscodeshift: API['jscodeshift']; | ||
}; | ||
|
||
export function findImportDeclarations({ root, importPackage }: FindImportDeclarationsParams) { | ||
return root.find(ImportDeclaration, node => node.type === 'ImportDeclaration' && node.source.value === importPackage); | ||
} |
22 changes: 22 additions & 0 deletions
22
packages/vibrant-migrator/src/lib/utils/removeImportVariable.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import type { API, ASTPath, ImportDeclaration } from 'jscodeshift'; | ||
|
||
type RemoveImportVariableParams = { | ||
importPath: ASTPath<ImportDeclaration>; | ||
variableName: string; | ||
jscodeshift: API['jscodeshift']; | ||
}; | ||
|
||
export function removeImportVariable({ importPath, variableName, jscodeshift }: RemoveImportVariableParams) { | ||
const importDeclaration = importPath.node; | ||
const importVariables = (importDeclaration.specifiers ?? []).filter( | ||
specifier => specifier.type !== 'ImportSpecifier' || specifier.imported.name !== variableName | ||
); | ||
|
||
if (importVariables.length === 0) { | ||
jscodeshift(importDeclaration.source).remove(); | ||
|
||
return; | ||
} | ||
|
||
jscodeshift(importPath).replaceWith(jscodeshift.importDeclaration(importVariables, importDeclaration.source)); | ||
} |
Oops, something went wrong.