@mux/mux-elements-codemod
Advanced tools
Comparing version 1.0.1-canary.1-4980706 to 1.0.1-canary.2-2686be8
{ | ||
"name": "@mux/mux-elements-codemod", | ||
"version": "1.0.1-canary.1-4980706", | ||
"version": "1.0.1-canary.2-2686be8", | ||
"description": "A codemod to transform @mux-elments scope imports into @mux scope imports", | ||
@@ -5,0 +5,0 @@ "bin": "./dist/index.mjs", |
@@ -15,3 +15,3 @@ #!/usr/bin/env node | ||
default: { | ||
extensions: 'js ts jsx tsx json html mjs cjs', | ||
extensions: 'js ts jsx tsx html mjs cjs', | ||
imports: false, | ||
@@ -55,3 +55,3 @@ force: false, | ||
-e --extensions specifiy the specific file extensions to use as a space separated string | ||
default is "js ts jsx tsx json html mjs cjs" | ||
default is "js ts jsx tsx html mjs cjs" | ||
-f --force by default, this does a dry run, run with --force to replace the text inline | ||
@@ -91,8 +91,26 @@ -h --help show this help | ||
const imports = () => { | ||
const files = getFiles(paths, ignoresArray, exts, (file: string | ShellString) => | ||
sh.cat(file).includes('@mux-elements') | ||
); | ||
const linesFileMap = new Map(); | ||
const files = getFiles(paths, ignoresArray, exts, (file: string | ShellString) => { | ||
const fileText = sh.cat(file); | ||
const includesMuxElements = fileText.includes('@mux-elements'); | ||
// if in dry-run, store unchanges lines here for use below | ||
if (!force && includesMuxElements) { | ||
const lineNumbers: number[] = []; | ||
const lines = fileText.split('\n').filter((line, i) => { | ||
const included = line.includes('@mux-elements'); | ||
if (included) { | ||
lineNumbers.push(i); | ||
} | ||
return included; | ||
}); | ||
linesFileMap.set(file, [lineNumbers, lines]); | ||
} | ||
return includesMuxElements; | ||
}); | ||
if (force) { | ||
sh.echo('Modifying the following files to replace `@mux-elements/` scope with `@mux`:'); | ||
sh.echo('Modifying the following files to replace `@mux-elements/` scope with `@mux/`:'); | ||
} else { | ||
@@ -103,3 +121,4 @@ sh.echo('Running in dry run mode. The following files will be modified:'); | ||
files.forEach((file) => { | ||
const sedOptions: [string, string, string] | [string, string, string, string] = ['@mux-elements/', '@mux/', file]; | ||
type SedOptions = [string, string, string] | [string, string, string, string]; | ||
const sedOptions: SedOptions = ['@mux-elements/', '@mux/', file]; | ||
if (force) { | ||
@@ -111,19 +130,14 @@ sedOptions.unshift('-i'); | ||
sh.echo(`${chalk.green(file)}`); | ||
if (!force) { | ||
const lineNumbers: number[] = []; | ||
const lines = sedFile.split('\n').filter((line, i) => { | ||
const included = line.includes('@mux'); | ||
if (included) { | ||
lineNumbers.push(i); | ||
} | ||
return included; | ||
}); | ||
const [lineNumbers, beforeLines] = linesFileMap.get(file) as [number[], string[]]; | ||
const lines = sedFile.split('\n'); | ||
sh.echo('Before:'); | ||
lines.forEach((line, i) => { | ||
sh.echo(`\t${chalk.yellow(lineNumbers[i])}:${line.replace('@mux/', '@mux-elements/')}`); | ||
beforeLines.forEach((beforeLine, i) => { | ||
sh.echo(`\t${chalk.yellow(lineNumbers[i])}:${beforeLine}`); | ||
}); | ||
sh.echo('After:'); | ||
lines.forEach((line, i) => { | ||
sh.echo(`\t${chalk.yellow(lineNumbers[i])}:${line}`); | ||
lineNumbers.forEach((lineNumber) => { | ||
sh.echo(`\t${chalk.yellow(lineNumber)}:${lines[lineNumber]}`); | ||
}); | ||
@@ -130,0 +144,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30864
265