1- import { projectRoot } from '../webpack/helpers' ;
2- const commander = require ( 'commander' ) ;
3- const fs = require ( 'fs' ) ;
4- const JSON5 = require ( 'json5' ) ;
5- const _cliProgress = require ( 'cli-progress' ) ;
6- const _ = require ( 'lodash' ) ;
1+ import {
2+ existsSync ,
3+ lstatSync ,
4+ readdirSync ,
5+ readFileSync ,
6+ writeFileSync ,
7+ } from 'node:fs' ;
78
8- const program = new commander . Command ( ) ;
9+ import {
10+ Presets ,
11+ SingleBar ,
12+ } from 'cli-progress' ;
13+ import { Command } from 'commander' ;
14+ import {
15+ parse ,
16+ stringify ,
17+ } from 'json5' ;
18+
19+ import { projectRoot } from '../webpack/helpers' ;
20+
21+ const program = new Command ( ) ;
922program . version ( '1.0.0' , '-v, --version' ) ;
1023
1124const LANGUAGE_FILES_LOCATION = 'src/assets/i18n' ;
@@ -46,26 +59,26 @@ function parseCliInput() {
4659 const destination = program . opts ( ) . outputDir ;
4760
4861 if ( destination && source ) {
49- if ( ! fs . existsSync ( destination ) || ! fs . lstatSync ( destination ) . isDirectory ( ) ) {
62+ if ( ! existsSync ( destination ) || ! lstatSync ( destination ) . isDirectory ( ) ) {
5063 console . error ( 'Output does not exist or is not a directory.' ) ;
51- console . log ( program . outputHelp ( ) ) ;
64+ console . info ( program . outputHelp ( ) ) ;
5265 process . exit ( 1 ) ;
5366 }
54- if ( ! fs . existsSync ( source ) || ! fs . lstatSync ( source ) . isDirectory ( ) ) {
67+ if ( ! existsSync ( source ) || ! lstatSync ( source ) . isDirectory ( ) ) {
5568 console . error ( 'Source does not exist or is not a directory.' ) ;
56- console . log ( program . outputHelp ( ) ) ;
69+ console . info ( program . outputHelp ( ) ) ;
5770 process . exit ( 1 ) ;
5871 }
5972
60- fs . readdirSync ( projectRoot ( source ) ) . forEach ( file => {
61- if ( fs . existsSync ( destination + '/' + file ) ) {
62- console . log ( 'Merging: ' + destination + '/' + file + ' with ' + source + '/' + file ) ;
73+ readdirSync ( projectRoot ( source ) ) . forEach ( file => {
74+ if ( existsSync ( destination + '/' + file ) ) {
75+ console . info ( 'Merging: ' + destination + '/' + file + ' with ' + source + '/' + file ) ;
6376 mergeFileWithSource ( source + '/' + file , destination + '/' + file ) ;
6477 }
6578 } ) ;
6679 } else {
6780 console . error ( 'Source or Output parameter is missing.' ) ;
68- console . log ( program . outputHelp ( ) ) ;
81+ console . info ( program . outputHelp ( ) ) ;
6982 process . exit ( 1 ) ;
7083 }
7184}
@@ -79,24 +92,24 @@ function parseCliInput() {
7992 * @param pathToOutputFile Valid path to merge and write output
8093 */
8194function mergeFileWithSource ( pathToSourceFile , pathToOutputFile ) {
82- const progressBar = new _cliProgress . SingleBar ( { } , _cliProgress . Presets . shades_classic ) ;
95+ const progressBar = new SingleBar ( { } , Presets . shades_classic ) ;
8396 progressBar . start ( 100 , 0 ) ;
8497
85- const sourceFile = fs . readFileSync ( pathToSourceFile , 'utf8' ) ;
98+ const sourceFile = readFileSync ( pathToSourceFile , 'utf8' ) ;
8699 progressBar . update ( 10 ) ;
87- const outputFile = fs . readFileSync ( pathToOutputFile , 'utf8' ) ;
100+ const outputFile = readFileSync ( pathToOutputFile , 'utf8' ) ;
88101 progressBar . update ( 20 ) ;
89102
90- const parsedSource = JSON5 . parse ( sourceFile ) ;
103+ const parsedSource = parse ( sourceFile ) ;
91104 progressBar . update ( 30 ) ;
92- const parsedOutput = JSON5 . parse ( outputFile ) ;
105+ const parsedOutput = parse ( outputFile ) ;
93106 progressBar . update ( 40 ) ;
94107
95108 for ( const key of Object . keys ( parsedSource ) ) {
96109 parsedOutput [ key ] = parsedSource [ key ] ;
97110 }
98111 progressBar . update ( 80 ) ;
99- fs . writeFileSync ( pathToOutputFile , JSON5 . stringify ( parsedOutput , { space :'\n ' , quote : '"' } ) , { encoding :'utf8' } ) ;
112+ writeFileSync ( pathToOutputFile , stringify ( parsedOutput , { space :'\n ' , quote : '"' } ) , { encoding :'utf8' } ) ;
100113
101114 progressBar . update ( 100 ) ;
102115 progressBar . stop ( ) ;
0 commit comments