Skip to content

Commit

Permalink
chore(build): fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
zewa666 committed Nov 2, 2018
1 parent b8fbd87 commit 0d8d968
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 129 deletions.
45 changes: 23 additions & 22 deletions build/args.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import yargs from 'yargs';
import { IBuildTargetFormat } from './shared';

export interface IArguments {
target: string;
format: IBuildTargetFormat[];
}

export const args: IArguments = yargs
.options(
'target',
{
alias: 't',
description: 'target module dir to copy build results into (eg. "--target ../other-module" to copy build results into "../other-module/node_modules/this-module/dist/…" whenever they change)'
}
)
.options('format', {
alias: 'f',
array: true,
description: 'format to compile to (eg. "es2015", "commonjs", …). Can be set muliple times to compile to multiple formats. Default is all formats.'
})
.argv as any;
import yargs from "yargs";
import { IBuildTargetFormat } from "./shared";

// tslint:disable-next-line:interface-name
export interface IArguments {
target: string;
format: IBuildTargetFormat[];
}

export const args: IArguments = yargs
.options(
"target",
{
alias: "t",
description: "target module dir to copy build results into (eg. \"--target ../other-module\" to copy build results into \"../other-module/node_modules/this-module/dist/…\" whenever they change)"
}
)
.options("format", {
alias: "f",
array: true,
description: "format to compile to (eg. \"es2015\", \"commonjs\", …). Can be set muliple times to compile to multiple formats. Default is all formats."
})
.argv as any;
92 changes: 46 additions & 46 deletions build/build.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
import rollup from 'rollup';
import { build, generateDts, IBuildTargetFormat } from "./shared";
import { args } from "./args";
import packageJson from '../package.json';

const LIB_NAME = 'aurelia-store';
const ENTRY_PATH = 'src/aurelia-store.ts';
const EXTERNAL_LIBS = Object
.keys({ ...packageJson.dependencies, ...packageJson.devDependencies })
.filter(dev => /^(?:aurelia|rxjs)/.test(dev))
// rxjs/operators is considered a different module
// and cannot be resolved by rollup. Add this to avoid warning
.concat('rxjs/operators');
const configs = {
es2017: {
input: ENTRY_PATH,
outputs: [
{ file: 'dist/es2017/index.js', format: 'es' }
]
},
es2015: {
input: ENTRY_PATH,
outputs: [
{ file: 'dist/es2015/index.js', format: 'es' }
]
},
es5: {
input: ENTRY_PATH,
outputs: [
{ file: 'dist/commonjs/index.js', format: 'cjs' },
{ file: 'dist/amd/index.js', format: 'amd', amd: { id: LIB_NAME } },
{ file: 'dist/native-modules/index.js', format: 'es' }
]
}
}

const targetFormats: IBuildTargetFormat[] = args.format || ['es5', 'es2015', 'es2017'];
Promise
.all(targetFormats.map(target => {
const { outputs, ...options } = configs[target];
return build(target, { ...options, external: EXTERNAL_LIBS }, outputs as rollup.OutputOptionsFile[]);
}))
.then(() => generateDts())
.catch(ex => {
console.log(ex);
});
import rollup from "rollup";
import { build, generateDts, IBuildTargetFormat } from "./shared";
import { args } from "./args";
import packageJson from "../package.json";

const LIB_NAME = "aurelia-store";
const ENTRY_PATH = "src/aurelia-store.ts";
const EXTERNAL_LIBS = Object
.keys({ ...packageJson.dependencies, ...packageJson.devDependencies })
.filter(dev => /^(?:aurelia|rxjs)/.test(dev))
// rxjs/operators is considered a different module
// and cannot be resolved by rollup. Add this to avoid warning
.concat("rxjs/operators");
const configs = {
es2017: {
input: ENTRY_PATH,
outputs: [
{ file: "dist/es2017/index.js", format: "es" }
]
},
es2015: {
input: ENTRY_PATH,
outputs: [
{ file: "dist/es2015/index.js", format: "es" }
]
},
es5: {
input: ENTRY_PATH,
outputs: [
{ file: "dist/commonjs/index.js", format: "cjs" },
{ file: "dist/amd/index.js", format: "amd", amd: { id: LIB_NAME } },
{ file: "dist/native-modules/index.js", format: "es" }
]
}
}

const targetFormats: IBuildTargetFormat[] = args.format || ["es5", "es2015", "es2017"];
Promise
.all(targetFormats.map(target => {
const { outputs, ...options } = configs[target];
return build(target, { ...options, external: EXTERNAL_LIBS }, outputs as rollup.OutputOptionsFile[]);
}))
.then(() => generateDts())
.catch(ex => {
console.log(ex);
});
122 changes: 61 additions & 61 deletions build/shared.ts
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
import * as rollup from 'rollup';
import typescript from 'rollup-plugin-typescript2';
import rimraf from 'rimraf';
import ChildProcess from 'child_process';


export type IBuildTargetFormat = 'es5' | 'es2015' | 'es2017';

export async function build(
target: IBuildTargetFormat,
options: rollup.RollupFileOptions,
outputs: rollup.OutputOptionsFile[]
): Promise<void> {
return rollup
.rollup({
...options,
plugins: [
typescript({
tsconfigOverride: {
compilerOptions: {
target: target
}
},
cacheRoot: '.rollupcache'
}) as rollup.Plugin,
...(options.plugins || []),
]
})
.then(bundle => Promise.all(outputs.map(output => bundle.write(output))))
.then(() => {
console.log(`Built [${target}] successfully.`);
});
}

export async function clean(): Promise<void> {
console.log('\n==============\nCleaning dist folder...\n==============');
return new Promise<void>(resolve => {
rimraf('dist', (error) => {
if (error) {
throw error;
}
resolve();
});
});
}

export async function generateDts(): Promise<void> {
console.log('\n==============\nGenerating dts bundle...\n==============');
return new Promise<void>(resolve => {
ChildProcess.exec('npm run bundle-dts', (err, stdout, stderr) => {
if (err || stderr) {
console.log('Generating dts error:');
console.log(stderr);
} else {
console.log('Generated dts bundle successfully');
console.log(stdout);
}
resolve();
});
});
};
import * as rollup from "rollup";
import typescript from "rollup-plugin-typescript2";
import rimraf from "rimraf";
import ChildProcess from "child_process";


export type IBuildTargetFormat = "es5" | "es2015" | "es2017";

export async function build(
target: IBuildTargetFormat,
options: rollup.RollupFileOptions,
outputs: rollup.OutputOptionsFile[]
): Promise<void> {
return rollup
.rollup({
...options,
plugins: [
typescript({
tsconfigOverride: {
compilerOptions: {
target: target
}
},
cacheRoot: ".rollupcache"
}) as rollup.Plugin,
...(options.plugins || []),
]
})
.then(bundle => Promise.all(outputs.map(output => bundle.write(output))))
.then(() => {
console.log(`Built [${target}] successfully.`);
});
}

export async function clean(): Promise<void> {
console.log("\n==============\nCleaning dist folder...\n==============");
return new Promise<void>(resolve => {
rimraf("dist", (error) => {
if (error) {
throw error;
}
resolve();
});
});
}

export async function generateDts(): Promise<void> {
console.log("\n==============\nGenerating dts bundle...\n==============");
return new Promise<void>(resolve => {
ChildProcess.exec("npm run bundle-dts", (err, stdout, stderr) => {
if (err || stderr) {
console.log("Generating dts error:");
console.log(stderr);
} else {
console.log("Generated dts bundle successfully");
console.log(stdout);
}
resolve();
});
});
};

0 comments on commit 0d8d968

Please sign in to comment.