-
Notifications
You must be signed in to change notification settings - Fork 1
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
af73567
commit 1f29b81
Showing
4 changed files
with
107 additions
and
23 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
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,57 @@ | ||
import { CAC } from 'cac'; | ||
import fs from 'fs-extra'; | ||
import enquirer from 'enquirer'; | ||
import chalk from 'chalk'; | ||
import { CLIUtils } from './utils'; | ||
import consola from 'consola'; | ||
import path from 'path'; | ||
|
||
// raw, renamed | ||
type Raw2RenamedTuple = [string, string]; | ||
|
||
export default function useRenameWorkspacePackage(cli: CAC) { | ||
cli | ||
.command('rename', 'pick starters and rename them', { | ||
allowUnknownOptions: true, | ||
}) | ||
.action(async () => { | ||
const chosedStarters = await CLIUtils.createPackageMultiSelector( | ||
'chosedStarters', | ||
'Pick starters to rename them', | ||
true | ||
); | ||
|
||
const tasks: Array<Raw2RenamedTuple> = []; | ||
|
||
for (const pkg of chosedStarters) { | ||
const { renamed } = await enquirer.prompt<{ renamed: string }>({ | ||
type: 'input', | ||
name: 'renamed', | ||
message: `Rename package ${chalk.bold.green(pkg)}`, | ||
}); | ||
|
||
tasks.push([pkg, renamed]); | ||
} | ||
|
||
if (!tasks.length) { | ||
consola.error('No copy tasks available.'); | ||
} | ||
|
||
for (const [raw, renamed] of tasks) { | ||
const rawDir = CLIUtils.resolvePackageDir(raw); | ||
const dest = CLIUtils.resolvePackageDir(renamed); | ||
|
||
console.info( | ||
`Rename template ${chalk.bold.yellow(raw)} to ${chalk.bold.green( | ||
renamed | ||
)}` | ||
); | ||
|
||
fs.renameSync(rawDir, dest); | ||
|
||
const destPkgJsonPath = path.join(dest, 'package.json'); | ||
|
||
CLIUtils.modifyPackageJSON(destPkgJsonPath, 'name', renamed); | ||
} | ||
}); | ||
} |
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