mirror of
https://github.com/mdgriffith/elm-optimize-level-2.git
synced 2024-11-29 12:46:32 +03:00
Throw an error if JS is empty
This commit is contained in:
parent
89100d5ae9
commit
5d43f746a1
45
src/run.ts
45
src/run.ts
@ -87,27 +87,30 @@ export async function run(
|
|||||||
} else {
|
} else {
|
||||||
throw new Error(`Please provide a path to an Elm file.\n${helpInformation}`.trim());
|
throw new Error(`Please provide a path to an Elm file.\n${helpInformation}`.trim());
|
||||||
}
|
}
|
||||||
if (jsSource != '') {
|
|
||||||
const transformed = await Transform.transform(
|
|
||||||
dirname,
|
|
||||||
jsSource,
|
|
||||||
elmFilePath,
|
|
||||||
options.verbose,
|
|
||||||
toolDefaults(o3Enabled, replacements),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Make sure all the folders up to the output file exist, if not create them.
|
if (jsSource == '') {
|
||||||
// This mirrors elm make behavior.
|
throw new Error('Target JS file is empty.');
|
||||||
const outputDirectory = path.dirname(options.outputFilePath);
|
|
||||||
if (!fs.existsSync(outputDirectory)) {
|
|
||||||
fs.mkdirSync(outputDirectory, { recursive: true });
|
|
||||||
}
|
|
||||||
fs.writeFileSync(options.outputFilePath, transformed);
|
|
||||||
const fileName = path.basename(inputFilePath);
|
|
||||||
log('Success!');
|
|
||||||
log('');
|
|
||||||
log(` ${fileName} ───> ${options.outputFilePath}`);
|
|
||||||
log('');
|
|
||||||
return options.outputFilePath;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const transformed = await Transform.transform(
|
||||||
|
dirname,
|
||||||
|
jsSource,
|
||||||
|
elmFilePath,
|
||||||
|
options.verbose,
|
||||||
|
toolDefaults(o3Enabled, replacements),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Make sure all the folders up to the output file exist, if not create them.
|
||||||
|
// This mirrors elm make behavior.
|
||||||
|
const outputDirectory = path.dirname(options.outputFilePath);
|
||||||
|
if (!fs.existsSync(outputDirectory)) {
|
||||||
|
fs.mkdirSync(outputDirectory, { recursive: true });
|
||||||
|
}
|
||||||
|
fs.writeFileSync(options.outputFilePath, transformed);
|
||||||
|
const fileName = path.basename(inputFilePath);
|
||||||
|
log('Success!');
|
||||||
|
log('');
|
||||||
|
log(` ${fileName} ───> ${options.outputFilePath}`);
|
||||||
|
log('');
|
||||||
|
return options.outputFilePath;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user