mirror of
https://github.com/mdgriffith/elm-optimize-level-2.git
synced 2024-11-25 22:50:42 +03:00
Remove binary related things from index.js, start execution from bin.js
This commit is contained in:
parent
aca18d1433
commit
84e9c0f95d
18
src/bin.ts
18
src/bin.ts
@ -1,11 +1,6 @@
|
||||
// tslint:disable-next-line no-require-imports no-var-requires
|
||||
import program from 'commander';
|
||||
import * as path from 'path';
|
||||
import * as Transform from './transform';
|
||||
import { toolDefaults } from './types';
|
||||
import { compileToStringSync } from 'node-elm-compiler';
|
||||
import * as fs from 'fs';
|
||||
import chalk from 'chalk';
|
||||
import { run } from './index';
|
||||
const { version } = require('../package.json');
|
||||
// import * as BenchInit from './benchmark/init'
|
||||
// import * as Benchmark from './benchmark/benchmark';
|
||||
@ -33,9 +28,8 @@ Give me an Elm file, I'll compile it behind the scenes using Elm 0.19.1, and the
|
||||
.parse(process.argv);
|
||||
|
||||
const { output, optimizeSpeed } = program.opts();
|
||||
console.log(program.opts());
|
||||
// run({
|
||||
// inputFilePath: program.args[0],
|
||||
// outputFilePath: output,
|
||||
// optimizeSpeed
|
||||
// }).catch((e) => console.error(e));
|
||||
run({
|
||||
inputFilePath: program.args[0],
|
||||
outputFilePath: output,
|
||||
optimizeSpeed
|
||||
}).catch((e) => console.error(e));
|
||||
|
90
src/index.ts
90
src/index.ts
@ -5,33 +5,10 @@ import * as Transform from './transform';
|
||||
import { toolDefaults } from './types';
|
||||
import { compileToStringSync } from 'node-elm-compiler';
|
||||
import * as fs from 'fs';
|
||||
import chalk from 'chalk';
|
||||
const { version } = require('../package.json');
|
||||
// import * as BenchInit from './benchmark/init'
|
||||
// import * as Benchmark from './benchmark/benchmark';
|
||||
// import * as Reporting from './benchmark/reporting';
|
||||
|
||||
program
|
||||
.version(version)
|
||||
.description(
|
||||
`${chalk.yellow('Elm Optimize Level 2!')}
|
||||
|
||||
This applies a second level of optimization to the javascript that Elm creates.
|
||||
|
||||
Make sure you're familiar with Elm's built-in optimization first: ${chalk.cyan(
|
||||
'https://guide.elm-lang.org/optimization/asset_size.html'
|
||||
)}
|
||||
|
||||
Give me an Elm file, I'll compile it behind the scenes using Elm 0.19.1, and then I'll make some more optimizations!`
|
||||
)
|
||||
.usage('[options] <src/Main.elm>')
|
||||
.option('--output <output>', 'the javascript file to create.', 'elm.js')
|
||||
.option('-O3, --optimize-speed', 'Enable optimizations that likely increases asset size', false)
|
||||
// .option('--init-benchmark <dir>', 'Generate some files to help run benchmarks')
|
||||
// .option('--benchmark <dir>', 'Run the benchmark in the given directory.')
|
||||
// .option('--replacements <dir>', 'Replace stuff')
|
||||
.parse(process.argv);
|
||||
|
||||
export async function run(options: {
|
||||
inputFilePath: string | undefined,
|
||||
outputFilePath: string | null,
|
||||
@ -65,32 +42,32 @@ async function runWithLogger(
|
||||
// process.exit(0)
|
||||
// }
|
||||
|
||||
// if (program.benchmark) {
|
||||
// const options = {
|
||||
// compile: true,
|
||||
// gzip: true,
|
||||
// minify: true,
|
||||
// verbose: true,
|
||||
// assetSizes: true,
|
||||
// runBenchmark: [
|
||||
// {
|
||||
// browser: Browser.Chrome,
|
||||
// headless: true,
|
||||
// }
|
||||
// ],
|
||||
// transforms: benchmarkDefaults(o3Enabled, replacements),
|
||||
// };
|
||||
// const report = await Benchmark.run(options, [
|
||||
// {
|
||||
// name: 'Benchmark',
|
||||
// dir: program.benchmark,
|
||||
// elmFile: 'V8/Benchmark.elm',
|
||||
// }
|
||||
// ]);
|
||||
// console.log(Reporting.terminal(report));
|
||||
// // fs.writeFileSync('./results.markdown', Reporting.markdownTable(result));
|
||||
// process.exit(0)
|
||||
// }
|
||||
// if (program.benchmark) {
|
||||
// const options = {
|
||||
// compile: true,
|
||||
// gzip: true,
|
||||
// minify: true,
|
||||
// verbose: true,
|
||||
// assetSizes: true,
|
||||
// runBenchmark: [
|
||||
// {
|
||||
// browser: Browser.Chrome,
|
||||
// headless: true,
|
||||
// }
|
||||
// ],
|
||||
// transforms: benchmarkDefaults(o3Enabled, replacements),
|
||||
// };
|
||||
// const report = await Benchmark.run(options, [
|
||||
// {
|
||||
// name: 'Benchmark',
|
||||
// dir: program.benchmark,
|
||||
// elmFile: 'V8/Benchmark.elm',
|
||||
// }
|
||||
// ]);
|
||||
// console.log(Reporting.terminal(report));
|
||||
// // fs.writeFileSync('./results.markdown', Reporting.markdownTable(result));
|
||||
// process.exit(0)
|
||||
// }
|
||||
|
||||
if (inputFilePath && inputFilePath.endsWith('.js')) {
|
||||
jsSource = fs.readFileSync(inputFilePath, 'utf8');
|
||||
@ -102,10 +79,10 @@ async function runWithLogger(
|
||||
cwd: dirname,
|
||||
optimize: true,
|
||||
processOpts:
|
||||
// ignore stdout
|
||||
{
|
||||
stdio: ['inherit', 'ignore', 'inherit'],
|
||||
},
|
||||
// ignore stdout
|
||||
{
|
||||
stdio: ['inherit', 'ignore', 'inherit'],
|
||||
},
|
||||
});
|
||||
if (jsSource != '') {
|
||||
log('Compiled, optimizing JS...');
|
||||
@ -140,10 +117,3 @@ async function runWithLogger(
|
||||
log('');
|
||||
}
|
||||
}
|
||||
|
||||
const { output, optimizeSpeed } = program.opts();
|
||||
run({
|
||||
inputFilePath: program.args[0],
|
||||
outputFilePath: output,
|
||||
optimizeSpeed
|
||||
}).catch((e) => console.error(e));
|
||||
|
Loading…
Reference in New Issue
Block a user