From 0d8d96831746b15c7b81f69c7992541bca194b49 Mon Sep 17 00:00:00 2001 From: Vildan Softic Date: Fri, 2 Nov 2018 08:17:14 +0100 Subject: [PATCH] chore(build): fix lint issues --- build/args.ts | 45 +++++++++--------- build/build.ts | 92 ++++++++++++++++++------------------ build/shared.ts | 122 ++++++++++++++++++++++++------------------------ 3 files changed, 130 insertions(+), 129 deletions(-) diff --git a/build/args.ts b/build/args.ts index ba85d4f..1676247 100644 --- a/build/args.ts +++ b/build/args.ts @@ -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; diff --git a/build/build.ts b/build/build.ts index dc52361..0f1513f 100644 --- a/build/build.ts +++ b/build/build.ts @@ -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); + }); diff --git a/build/shared.ts b/build/shared.ts index fe25e32..eed5b32 100644 --- a/build/shared.ts +++ b/build/shared.ts @@ -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 { - 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 { - console.log('\n==============\nCleaning dist folder...\n=============='); - return new Promise(resolve => { - rimraf('dist', (error) => { - if (error) { - throw error; - } - resolve(); - }); - }); -} - -export async function generateDts(): Promise { - console.log('\n==============\nGenerating dts bundle...\n=============='); - return new Promise(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 { + 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 { + console.log("\n==============\nCleaning dist folder...\n=============="); + return new Promise(resolve => { + rimraf("dist", (error) => { + if (error) { + throw error; + } + resolve(); + }); + }); +} + +export async function generateDts(): Promise { + console.log("\n==============\nGenerating dts bundle...\n=============="); + return new Promise(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(); + }); + }); +};