mirror of
https://github.com/mdgriffith/elm-optimize-level-2.git
synced 2024-11-29 12:46:32 +03:00
Add console.log argument
This commit is contained in:
parent
2099900839
commit
37aefb39e9
20
src/index.ts
20
src/index.ts
@ -37,6 +37,14 @@ async function run(options: {
|
|||||||
outputFilePath: string | null,
|
outputFilePath: string | null,
|
||||||
optimizeSpeed: boolean
|
optimizeSpeed: boolean
|
||||||
}) {
|
}) {
|
||||||
|
return runWithLogger(options, console.log.bind(console));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function runWithLogger(options: {
|
||||||
|
inputFilePath: string | undefined,
|
||||||
|
outputFilePath: string | null,
|
||||||
|
optimizeSpeed: boolean
|
||||||
|
}, log: (message?: any, ...optionalParams: any[]) => void) {
|
||||||
const dirname = process.cwd();
|
const dirname = process.cwd();
|
||||||
let jsSource: string = '';
|
let jsSource: string = '';
|
||||||
let elmFilePath = undefined;
|
let elmFilePath = undefined;
|
||||||
@ -80,7 +88,7 @@ async function run(options: {
|
|||||||
|
|
||||||
if (inputFilePath && inputFilePath.endsWith('.js')) {
|
if (inputFilePath && inputFilePath.endsWith('.js')) {
|
||||||
jsSource = fs.readFileSync(inputFilePath, 'utf8');
|
jsSource = fs.readFileSync(inputFilePath, 'utf8');
|
||||||
console.log('Optimizing existing JS...');
|
log('Optimizing existing JS...');
|
||||||
} else if (inputFilePath && inputFilePath.endsWith('.elm')) {
|
} else if (inputFilePath && inputFilePath.endsWith('.elm')) {
|
||||||
elmFilePath = inputFilePath;
|
elmFilePath = inputFilePath;
|
||||||
jsSource = compileToStringSync([inputFilePath], {
|
jsSource = compileToStringSync([inputFilePath], {
|
||||||
@ -94,7 +102,7 @@ async function run(options: {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (jsSource != '') {
|
if (jsSource != '') {
|
||||||
console.log('Compiled, optimizing JS...');
|
log('Compiled, optimizing JS...');
|
||||||
} else {
|
} else {
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
@ -120,10 +128,10 @@ async function run(options: {
|
|||||||
}
|
}
|
||||||
fs.writeFileSync(program.output, transformed);
|
fs.writeFileSync(program.output, transformed);
|
||||||
const fileName = path.basename(inputFilePath);
|
const fileName = path.basename(inputFilePath);
|
||||||
console.log('Success!');
|
log('Success!');
|
||||||
console.log('');
|
log('');
|
||||||
console.log(` ${fileName} ───> ${program.output}`);
|
log(` ${fileName} ───> ${program.output}`);
|
||||||
console.log('');
|
log('');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user