diff --git a/src/bin.ts b/src/bin.ts index 92cd0ee..5a34005 100644 --- a/src/bin.ts +++ b/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)); diff --git a/src/index.ts b/src/index.ts index 64ee023..e0f9cad 100644 --- a/src/index.ts +++ b/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] ') - .option('--output ', 'the javascript file to create.', 'elm.js') - .option('-O3, --optimize-speed', 'Enable optimizations that likely increases asset size', false) - // .option('--init-benchmark ', 'Generate some files to help run benchmarks') - // .option('--benchmark ', 'Run the benchmark in the given directory.') - // .option('--replacements ', '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));