mirror of
https://github.com/mdgriffith/elm-optimize-level-2.git
synced 2024-11-29 12:46:32 +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 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 chalk from 'chalk';
|
||||||
|
import { run } from './index';
|
||||||
const { version } = require('../package.json');
|
const { version } = require('../package.json');
|
||||||
// import * as BenchInit from './benchmark/init'
|
// import * as BenchInit from './benchmark/init'
|
||||||
// import * as Benchmark from './benchmark/benchmark';
|
// 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);
|
.parse(process.argv);
|
||||||
|
|
||||||
const { output, optimizeSpeed } = program.opts();
|
const { output, optimizeSpeed } = program.opts();
|
||||||
console.log(program.opts());
|
run({
|
||||||
// run({
|
inputFilePath: program.args[0],
|
||||||
// inputFilePath: program.args[0],
|
outputFilePath: output,
|
||||||
// outputFilePath: output,
|
optimizeSpeed
|
||||||
// optimizeSpeed
|
}).catch((e) => console.error(e));
|
||||||
// }).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 { toolDefaults } from './types';
|
||||||
import { compileToStringSync } from 'node-elm-compiler';
|
import { compileToStringSync } from 'node-elm-compiler';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import chalk from 'chalk';
|
|
||||||
const { version } = require('../package.json');
|
|
||||||
// import * as BenchInit from './benchmark/init'
|
// import * as BenchInit from './benchmark/init'
|
||||||
// import * as Benchmark from './benchmark/benchmark';
|
// import * as Benchmark from './benchmark/benchmark';
|
||||||
// import * as Reporting from './benchmark/reporting';
|
// 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: {
|
export async function run(options: {
|
||||||
inputFilePath: string | undefined,
|
inputFilePath: string | undefined,
|
||||||
outputFilePath: string | null,
|
outputFilePath: string | null,
|
||||||
@ -65,32 +42,32 @@ async function runWithLogger(
|
|||||||
// process.exit(0)
|
// process.exit(0)
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// if (program.benchmark) {
|
// if (program.benchmark) {
|
||||||
// const options = {
|
// const options = {
|
||||||
// compile: true,
|
// compile: true,
|
||||||
// gzip: true,
|
// gzip: true,
|
||||||
// minify: true,
|
// minify: true,
|
||||||
// verbose: true,
|
// verbose: true,
|
||||||
// assetSizes: true,
|
// assetSizes: true,
|
||||||
// runBenchmark: [
|
// runBenchmark: [
|
||||||
// {
|
// {
|
||||||
// browser: Browser.Chrome,
|
// browser: Browser.Chrome,
|
||||||
// headless: true,
|
// headless: true,
|
||||||
// }
|
// }
|
||||||
// ],
|
// ],
|
||||||
// transforms: benchmarkDefaults(o3Enabled, replacements),
|
// transforms: benchmarkDefaults(o3Enabled, replacements),
|
||||||
// };
|
// };
|
||||||
// const report = await Benchmark.run(options, [
|
// const report = await Benchmark.run(options, [
|
||||||
// {
|
// {
|
||||||
// name: 'Benchmark',
|
// name: 'Benchmark',
|
||||||
// dir: program.benchmark,
|
// dir: program.benchmark,
|
||||||
// elmFile: 'V8/Benchmark.elm',
|
// elmFile: 'V8/Benchmark.elm',
|
||||||
// }
|
// }
|
||||||
// ]);
|
// ]);
|
||||||
// console.log(Reporting.terminal(report));
|
// console.log(Reporting.terminal(report));
|
||||||
// // fs.writeFileSync('./results.markdown', Reporting.markdownTable(result));
|
// // fs.writeFileSync('./results.markdown', Reporting.markdownTable(result));
|
||||||
// process.exit(0)
|
// process.exit(0)
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if (inputFilePath && inputFilePath.endsWith('.js')) {
|
if (inputFilePath && inputFilePath.endsWith('.js')) {
|
||||||
jsSource = fs.readFileSync(inputFilePath, 'utf8');
|
jsSource = fs.readFileSync(inputFilePath, 'utf8');
|
||||||
@ -102,10 +79,10 @@ async function runWithLogger(
|
|||||||
cwd: dirname,
|
cwd: dirname,
|
||||||
optimize: true,
|
optimize: true,
|
||||||
processOpts:
|
processOpts:
|
||||||
// ignore stdout
|
// ignore stdout
|
||||||
{
|
{
|
||||||
stdio: ['inherit', 'ignore', 'inherit'],
|
stdio: ['inherit', 'ignore', 'inherit'],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (jsSource != '') {
|
if (jsSource != '') {
|
||||||
log('Compiled, optimizing JS...');
|
log('Compiled, optimizing JS...');
|
||||||
@ -140,10 +117,3 @@ async function runWithLogger(
|
|||||||
log('');
|
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