Last active
December 28, 2019 05:44
-
-
Save potato4d/a6c53924f7efda99bbf83ecf8daffadd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import { promises as fs } from 'fs' | |
import { execSync } from 'child_process' | |
const camelToKebab = require('camel-to-kebab') | |
function getFileNames(scope: string, opt: string): string[] { | |
return execSync(`git ls-files ${scope} | grep ${opt}`) | |
.toString() | |
.split('\n') | |
.filter(v => v) | |
} | |
async function run() { | |
const componentList = getFileNames('src/components/', `'.vue'`).map(path => { | |
return { | |
kebabName: camelToKebab(path.split('/')[path.split('/').length - 1].replace('.vue', '')), | |
pascalName: path.split('/')[path.split('/').length - 1].replace('.vue', ''), | |
path | |
} | |
}) | |
const targetList = getFileNames('.', `'.vue'`) | |
await Promise.all([ | |
targetList.map(async t => { | |
let f = await fs.readFile(t, { encoding: 'utf8' }) | |
const base = f | |
componentList.forEach(component => { | |
f = f.replace( | |
new RegExp(`<(\/?)(${component.kebabName})`, 'g'), | |
`<$1${component.pascalName}` | |
) | |
}) | |
if (base !== f) { | |
console.log(t) | |
await fs.writeFile(t, f, { encoding: 'utf8' }) | |
} | |
}) | |
]) | |
} | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment