mirror of
https://github.com/mdgriffith/elm-optimize-level-2.git
synced 2024-11-25 22:50:42 +03:00
Use function wrapper replacements by default.
This commit is contained in:
parent
27871e4e7c
commit
b76f3718b3
27
src/fs_util.ts
Normal file
27
src/fs_util.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
export function readFilesSync(dir: string): {[key: string]: string} | null {
|
||||
let foundAnything = false
|
||||
const files: {[key: string]: string} = {};
|
||||
|
||||
fs.readdirSync(dir).forEach(filename => {
|
||||
const name = path.parse(filename).name;
|
||||
const filepath = path.resolve(dir, filename);
|
||||
const stat = fs.statSync(filepath);
|
||||
const isFile = stat.isFile();
|
||||
|
||||
if (isFile) {
|
||||
const content = fs.readFileSync(path.join(dir, filename))
|
||||
files[name] = content.toString()
|
||||
foundAnything = true
|
||||
}
|
||||
});
|
||||
|
||||
if (foundAnything) {
|
||||
return files;
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
|
||||
}
|
33
src/index.ts
33
src/index.ts
@ -10,6 +10,7 @@ const { version } = require('../package.json');
|
||||
import * as BenchInit from './benchmark/init'
|
||||
import * as Benchmark from './benchmark/benchmark';
|
||||
import * as Reporting from './benchmark/reporting';
|
||||
import { readFilesSync } from './fs_util';
|
||||
|
||||
program
|
||||
.version(version)
|
||||
@ -38,8 +39,12 @@ async function run(inputFilePath: string | undefined) {
|
||||
|
||||
const replacementDir = hasReplacements(process.argv)
|
||||
let replacements = null
|
||||
if (replacementDir){
|
||||
if (replacementDir) {
|
||||
replacements = readFilesSync(replacementDir)
|
||||
} else if (program.benchmark) {
|
||||
replacements = benchmarkDefaults.replacements;
|
||||
} else {
|
||||
replacements = toolDefaults.replacements;
|
||||
}
|
||||
|
||||
if (program.initBenchmark) {
|
||||
@ -147,30 +152,4 @@ function hasReplacements(args: string[]){
|
||||
return dir
|
||||
}
|
||||
|
||||
|
||||
function readFilesSync(dir: string): {[key: string]: string} | null {
|
||||
let foundAnything = false
|
||||
const files: {[key: string]: string} = {};
|
||||
|
||||
fs.readdirSync(dir).forEach(filename => {
|
||||
const name = path.parse(filename).name;
|
||||
const ext = path.parse(filename).ext;
|
||||
const filepath = path.resolve(dir, filename);
|
||||
const stat = fs.statSync(filepath);
|
||||
const isFile = stat.isFile();
|
||||
|
||||
if (isFile) {
|
||||
const content = fs.readFileSync(path.join(dir, filename))
|
||||
files[name] = content.toString()
|
||||
foundAnything = true
|
||||
}
|
||||
});
|
||||
if (foundAnything) {
|
||||
return files;
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
run(program.args[0]).catch((e) => console.error(e));
|
||||
|
@ -1,3 +1,5 @@
|
||||
import { readFilesSync } from './fs_util';
|
||||
|
||||
export enum Mode {
|
||||
Prod = 'prod',
|
||||
Dev = 'dev',
|
||||
@ -87,7 +89,7 @@ export const toolDefaults: Transforms = {
|
||||
replaceStringFunctions: false,
|
||||
recordUpdates: false,
|
||||
v8Analysis: false,
|
||||
replacements: null
|
||||
replacements: readFilesSync(__dirname + '/replacements/faster-function-wrappers')
|
||||
};
|
||||
|
||||
|
||||
@ -107,5 +109,5 @@ export const benchmarkDefaults: Transforms = {
|
||||
replaceStringFunctions: true,
|
||||
recordUpdates: false,
|
||||
v8Analysis: true,
|
||||
replacements: null
|
||||
replacements: readFilesSync(__dirname + '/replacements/faster-function-wrappers')
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user