generated from divlook/ts-library-starter
-
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.
feat: Implement output log according to conversion results
- Loading branch information
1 parent
f2f12e8
commit 463308f
Showing
1 changed file
with
32 additions
and
12 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 |
---|---|---|
@@ -1,26 +1,46 @@ | ||
import { format } from 'prettier'; | ||
import { scrapRawScript, writeFormattedScript } from '~/helpers/reader'; | ||
import plugin from './plugin'; | ||
import chalk from 'chalk'; | ||
|
||
export default (async () => { | ||
const args = process.argv.slice(2); | ||
|
||
if (args[0] === '--target') { | ||
const rawScript = await scrapRawScript(args[1]); | ||
try { | ||
const filePath = args[1]; | ||
const rawScript = await scrapRawScript(filePath); | ||
|
||
const formattedScript = format(rawScript, { | ||
plugins: [plugin], | ||
}); | ||
const formattedScript = format(rawScript, { | ||
plugins: [plugin], | ||
}); | ||
|
||
const writeDirectory = args[1].split('/'); | ||
const fileName = writeDirectory.pop(); | ||
const writeDirectory = args[1].split('/'); | ||
const originFileName = writeDirectory.pop(); | ||
|
||
if (fileName) { | ||
const split = fileName.split('.'); | ||
const directory = `${writeDirectory.join('/')}/${split[0]}.tailwind.${ | ||
split[1] | ||
}`; | ||
await writeFormattedScript(directory, formattedScript); | ||
if (originFileName) { | ||
const split = originFileName.split('.'); | ||
const fileExtension = split.pop(); | ||
const tailwindFileName = [...split, 'tailwind'].join('.'); | ||
|
||
const directory = `${writeDirectory.join( | ||
'/', | ||
)}/${tailwindFileName}.${fileExtension}`; | ||
await writeFormattedScript(directory, formattedScript); | ||
|
||
console.log( | ||
chalk.green( | ||
`tailwind-converter: Conversion Completed!, Please check ${directory}`, | ||
), | ||
); | ||
} | ||
} catch (e) { | ||
console.log( | ||
chalk.red(`tailwind-converter: Conversion Fail!, Please check error.`), | ||
); | ||
console.log(e); | ||
} finally { | ||
console.log(chalk.green('Done!')); | ||
} | ||
} | ||
})(); |