Skip to content

Commit

Permalink
style: Add auto-format command using Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
krjordan authored and MikeRyanDev committed Jul 13, 2017
1 parent 9b82b3a commit 48a2381
Show file tree
Hide file tree
Showing 115 changed files with 1,695 additions and 1,132 deletions.
27 changes: 13 additions & 14 deletions build/builder.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import * as tasks from './tasks';
import { createBuilder } from './util';


export default createBuilder([
[ 'Removing "./dist" Folder', tasks.removeDistFolder ],
[ 'Compiling packages with NGC', tasks.compilePackagesWithNgc ],
[ 'Bundling FESMs', tasks.bundleFesms ],
[ 'Down-leveling FESMs to ES5', tasks.downLevelFesmsToES5 ],
[ 'Creating UMD Bundles', tasks.createUmdBundles ],
[ 'Renaming package entry files', tasks.renamePackageEntryFiles ],
[ 'Cleaning TypeScript files', tasks.cleanTypeScriptFiles ],
[ 'Removing remaining sourcemap files', tasks.removeRemainingSourceMapFiles ],
[ 'Copying type definition files', tasks.copyTypeDefinitionFiles ],
[ 'Minifying UMD bundles', tasks.minifyUmdBundles ],
[ 'Copying documents', tasks.copyDocs ],
[ 'Copying package.json files', tasks.copyPackageJsonFiles ],
[ 'Removing "./dist/packages" Folder', tasks.removePackagesFolder ],
['Removing "./dist" Folder', tasks.removeDistFolder],
['Compiling packages with NGC', tasks.compilePackagesWithNgc],
['Bundling FESMs', tasks.bundleFesms],
['Down-leveling FESMs to ES5', tasks.downLevelFesmsToES5],
['Creating UMD Bundles', tasks.createUmdBundles],
['Renaming package entry files', tasks.renamePackageEntryFiles],
['Cleaning TypeScript files', tasks.cleanTypeScriptFiles],
['Removing remaining sourcemap files', tasks.removeRemainingSourceMapFiles],
['Copying type definition files', tasks.copyTypeDefinitionFiles],
['Minifying UMD bundles', tasks.minifyUmdBundles],
['Copying documents', tasks.copyDocs],
['Copying package.json files', tasks.copyPackageJsonFiles],
['Removing "./dist/packages" Folder', tasks.removePackagesFolder],
]);
4 changes: 2 additions & 2 deletions build/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export interface PackageDescription {
name: string,
hasTestingModule: boolean,
name: string;
hasTestingModule: boolean;
}

export interface Config {
Expand Down
7 changes: 2 additions & 5 deletions build/deploy-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ import * as tasks from './tasks';
import { createBuilder } from './util';
import { packages } from './config';


const deploy = createBuilder([
[ 'Deploy builds', tasks.publishToRepo ]
]);
const deploy = createBuilder([['Deploy builds', tasks.publishToRepo]]);

deploy({
scope: '@ngrx',
packages
packages,
}).catch(err => {
console.error(err);
process.exit(1);
Expand Down
3 changes: 1 addition & 2 deletions build/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import build from './builder';
import { packages } from './config';


build({
scope: '@ngrx',
packages
packages,
}).catch(err => {
console.error(err);
process.exit(1);
Expand Down
83 changes: 33 additions & 50 deletions build/tasks.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import { Config } from './config';
import * as util from './util';


/**
* Cleans the top level dist folder. All npm-ready packages are created
* in the dist folder.
*/
export async function removeDistFolder(config: Config) {
const args = [
'./dist'
];
const args = ['./dist'];

return await util.exec('rimraf', args);
}


/**
* Uses the 'tsconfig-build.json' file in each package directory to produce
* AOT and Closure compatible JavaScript
Expand All @@ -31,9 +27,7 @@ export async function compilePackagesWithNgc(config: Config) {
}

async function _compilePackagesWithNgc(pkg: string) {
await util.exec('ngc', [
`-p ./modules/${pkg}/tsconfig-build.json`
]);
await util.exec('ngc', [`-p ./modules/${pkg}/tsconfig-build.json`]);

const entryTypeDefinition = `export * from './${pkg}/index';`;
const entryMetadata = `{"__symbolic":"module","version":3,"metadata":{},"exports":[{"from":"./${pkg}/index"}]}`;
Expand All @@ -42,15 +36,14 @@ async function _compilePackagesWithNgc(pkg: string) {
util.writeFile(`./dist/packages/${pkg}.metadata.json`, entryMetadata);
}


/**
* Uses Rollup to bundle the JavaScript into a single flat file called
* a FESM (Flat Ecma Script Module)
*/
export async function bundleFesms(config: Config) {
const pkgs = util.getAllPackages(config);

await mapPackages(pkgs, async (pkg) => {
await mapPackages(pkgs, async pkg => {
const topLevelName = util.getTopLevelName(pkg);

await util.exec('rollup', [
Expand All @@ -63,56 +56,47 @@ export async function bundleFesms(config: Config) {
});
}


/**
* Copies each FESM into a TS file then uses TypeScript to downlevel
* the FESM into ES5 with ESM modules
*/
export async function downLevelFesmsToES5(config: Config) {
const packages = util.getAllPackages(config);
const tscArgs = [
'--target es5',
'--module es2015',
'--noLib',
'--sourceMap',
];

await mapPackages(packages, async (pkg) => {
const tscArgs = ['--target es5', '--module es2015', '--noLib', '--sourceMap'];

await mapPackages(packages, async pkg => {
const topLevelName = util.getTopLevelName(pkg);

const file = `./dist/${topLevelName}/${config.scope}/${pkg}.js`;
const target = `./dist/${topLevelName}/${config.scope}/${pkg}.es5.ts`;

util.copy(file, target);

await util.ignoreErrors(util.exec('tsc', [ target, ...tscArgs ]));
await util.ignoreErrors(util.exec('tsc', [target, ...tscArgs]));
await util.mapSources(target.replace('.ts', '.js'));
await util.remove(target);
});

await util.removeRecursively(`./dist/**/*/${config.scope}/*.ts`);
}


/**
* Re-runs Rollup on the downleveled ES5 to produce a UMD bundle
*/
export async function createUmdBundles(config: Config) {
await mapPackages(util.getAllPackages(config), async (pkg) => {
await mapPackages(util.getAllPackages(config), async pkg => {
const topLevelName = util.getTopLevelName(pkg);
const destinationName = util.getDestinationName(pkg);

const rollupArgs = [
`-c ./modules/${pkg}/rollup.config.js`,
`--sourcemap`,
];
const rollupArgs = [`-c ./modules/${pkg}/rollup.config.js`, `--sourcemap`];

await util.exec('rollup', rollupArgs);
await util.mapSources(`./dist/${topLevelName}/bundles/${destinationName}.umd.js`);
await util.mapSources(
`./dist/${topLevelName}/bundles/${destinationName}.umd.js`
);
});
}


/**
* Removes any leftover TypeScript files from previous compilation steps,
* leaving any type definition files in place
Expand All @@ -127,13 +111,12 @@ export async function cleanTypeScriptFiles(config: Config) {
}
}


/**
* Renames the index files in each package to the name
* of the package.
*/
export async function renamePackageEntryFiles(config: Config) {
await mapPackages(util.getAllPackages(config), async (pkg) => {
await mapPackages(util.getAllPackages(config), async pkg => {
const bottomLevelName = util.getBottomLevelName(pkg);

const files = await util.getListOfFiles(`./dist/packages/${pkg}/index.**`);
Expand All @@ -146,24 +129,26 @@ export async function renamePackageEntryFiles(config: Config) {
});
}


/**
* Removes any remaining source map files from running NGC
*/
export async function removeRemainingSourceMapFiles(config: Config) {
const packages = util.getTopLevelPackages(config);

await util.removeRecursively(`./dist/packages/?(${packages.join('|')})/**/*.map`);
await util.removeRecursively(
`./dist/packages/?(${packages.join('|')})/**/*.map`
);
}


/**
* Copies the type definition files and NGC metadata files to
* the root of the distribution
*/
export async function copyTypeDefinitionFiles(config: Config) {
const packages = util.getTopLevelPackages(config);
const files = await util.getListOfFiles(`./dist/packages/?(${packages.join('|')})/**/*`);
const files = await util.getListOfFiles(
`./dist/packages/?(${packages.join('|')})/**/*`
);

for (let file of files) {
const target = file.replace('packages/', '');
Expand All @@ -173,19 +158,13 @@ export async function copyTypeDefinitionFiles(config: Config) {
await util.removeRecursively(`./dist/packages/?(${packages.join('|')})`);
}


/**
* Creates minified copies of each UMD bundle
*/
export async function minifyUmdBundles(config: Config) {
const uglifyArgs = [
'-c',
'-m',
'--screw-ie8',
'--comments',
];

await mapPackages(util.getAllPackages(config), async (pkg) => {
const uglifyArgs = ['-c', '-m', '--screw-ie8', '--comments'];

await mapPackages(util.getAllPackages(config), async pkg => {
const topLevelName = util.getTopLevelName(pkg);
const destinationName = util.getDestinationName(pkg);
const file = `./dist/${topLevelName}/bundles/${destinationName}.umd.js`;
Expand All @@ -196,12 +175,11 @@ export async function minifyUmdBundles(config: Config) {
`-o ${out}`,
`--source-map ${out}.map`,
`--source-map-include-sources ${file}`,
`--in-source-map ${file}.map`
`--in-source-map ${file}.map`,
]);
});
}


/**
* Copies the README.md, LICENSE, and package.json files into
* each package
Expand Down Expand Up @@ -229,15 +207,13 @@ export async function copyPackageJsonFiles(config: Config) {
}
}


/**
* Removes the packages folder
*/
export async function removePackagesFolder(config: Config) {
await util.removeRecursively('./dist/packages');
}


/**
* Deploy build artifacts to repos
*/
Expand All @@ -248,8 +224,12 @@ export async function publishToRepo(config: Config) {
const REPO_DIR = `./tmp/${pkg}`;
const SHA = await util.git([`rev-parse HEAD`]);
const SHORT_SHA = await util.git([`rev-parse --short HEAD`]);
const COMMITTER_USER_NAME = await util.git([`--no-pager show -s --format='%cN' HEAD`]);
const COMMITTER_USER_EMAIL = await util.git([`--no-pager show -s --format='%cE' HEAD`]);
const COMMITTER_USER_NAME = await util.git([
`--no-pager show -s --format='%cN' HEAD`,
]);
const COMMITTER_USER_EMAIL = await util.git([
`--no-pager show -s --format='%cE' HEAD`,
]);

await util.cmd('rm -rf', [`${REPO_DIR}`]);
await util.cmd('mkdir ', [`-p ${REPO_DIR}`]);
Expand All @@ -274,6 +254,9 @@ export async function publishToRepo(config: Config) {
}
}

export function mapPackages(packages: string[], mapFn: (pkg: string, i: number) => Promise<any>) {
export function mapPackages(
packages: string[],
mapFn: (pkg: string, i: number) => Promise<any>
) {
return Promise.all(packages.map(mapFn));
}
Loading

0 comments on commit 48a2381

Please sign in to comment.