Skip to content

Add initial code to support NPM plugin module configuration lookups; … #894

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"connect-history-api-fallback": "^1.2.0",
"connect-livereload": "^0.5.3",
"cssnano": "^3.5.2",
"deep-extend": "^0.4.1",
"doiuse": "^2.3.0",
"event-stream": "^3.3.2",
"express": "~4.13.4",
Expand Down
4 changes: 4 additions & 0 deletions tools/config/project.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@ export class ProjectConfig extends SeedConfig {
const seedDependencies = this.NPM_DEPENDENCIES;

this.NPM_DEPENDENCIES = seedDependencies.concat(additional_deps);

/* Add to or override NPM module configurations: */
//this.mergeObject( this.PLUGIN_CONFIGS['browser-sync'], { ghostMode: false } );

}
}
61 changes: 44 additions & 17 deletions tools/config/seed.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,27 +379,54 @@ export class SeedConfig {
];

/**
* The BrowserSync configuration of the application.
* The default open behavior is to open the browser. To prevent the browser from opening use the `--b` flag when
* running `npm start` (tested with serve.dev).
* Example: `npm start -- --b`
* @type {any}
*/
BROWSER_SYNC_CONFIG: any = {
middleware: [require('connect-history-api-fallback')({ index: `${this.APP_BASE}index.html` })],
port: this.PORT,
startPath: this.APP_BASE,
open: argv['b'] ? false : true,
server: {
baseDir: `${this.DIST_DIR}/empty/`,
routes: {
[`${this.APP_BASE}${this.APP_DEST}`]: this.APP_DEST,
[`${this.APP_BASE}node_modules`]: 'node_modules',
[`${this.APP_BASE.replace(/\/$/, '')}`]: this.APP_DEST
* Configurations for NPM module configurations. Add to or override in project.config.ts.
* If you like, use the mergeObject() method to assist with this.
*/
PLUGIN_CONFIGS: any = {
/**
* The BrowserSync configuration of the application.
* The default open behavior is to open the browser. To prevent the browser from opening use the `--b` flag when
* running `npm start` (tested with serve.dev).
* Example: `npm start -- --b`
* @type {any}
*/
'browser-sync': {
middleware: [require('connect-history-api-fallback')({ index: `${this.APP_BASE}index.html` })],
port: this.PORT,
startPath: this.APP_BASE,
open: argv['b'] ? false : true,
server: {
baseDir: `${this.DIST_DIR}/empty/`,
routes: {
[`${this.APP_BASE}${this.APP_DEST}`]: this.APP_DEST,
[`${this.APP_BASE}node_modules`]: 'node_modules',
[`${this.APP_BASE.replace(/\/$/, '')}`]: this.APP_DEST
}
}
}
};

/**
* Recursively merge source onto target.
* @param {any} target The target object (to receive values from source)
* @param {any} source The source object (to be merged onto target)
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A parameter documentation would be nice :) like:

/**
 * Recursively merge source onto target.
 * @param {any} target <short description of target>
 * @param {any} source <short description of source>
 */

mergeObject(target: any, source: any) {
const deepExtend = require('deep-extend');
deepExtend(target, source);
}

/**
* Locate a plugin configuration object by plugin key.
* @param {any} pluginKey The object key to look up in PLUGIN_CONFIGS.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A parameter documentation would be nice :) like:

/**
 * Recursively merge source onto target.
 * @param {string} pluginKey <short description of pluginKey>
 */

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. And both titles are identical, they should not :-)

getPluginConfig(pluginKey: string): any {
if (this.PLUGIN_CONFIGS[ pluginKey ]) {
return this.PLUGIN_CONFIGS[pluginKey];
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces inside ( ) and [ ] don't follow the general coding seed style (though not enforced).

return null;
}

}

/**
Expand Down
4 changes: 2 additions & 2 deletions tools/tasks/seed/build.html_css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as gulpLoadPlugins from 'gulp-load-plugins';
import * as merge from 'merge-stream';
import { join } from 'path';

import { APP_DEST, APP_SRC, BROWSER_LIST, CSS_DEST, CSS_PROD_BUNDLE, DEPENDENCIES, ENV, TMP_DIR } from '../../config';
import { APP_DEST, APP_SRC, BROWSER_LIST, CSS_DEST, CSS_PROD_BUNDLE, DEPENDENCIES, ENV, getPluginConfig, TMP_DIR } from '../../config';

const plugins = <any>gulpLoadPlugins();
const cleanCss = require('gulp-clean-css');
Expand Down Expand Up @@ -55,7 +55,7 @@ function processExternalCss() {
return gulp.src(getExternalCss().map(r => r.src))
.pipe(isProd ? plugins.cached('process-external-css') : plugins.util.noop())
.pipe(plugins.postcss(processors))
.pipe(isProd ? plugins.concatCss(CSS_PROD_BUNDLE) : plugins.util.noop())
.pipe(isProd ? plugins.concatCss(CSS_PROD_BUNDLE, getPluginConfig('gulp-concat-css')) : plugins.util.noop())
.pipe(isProd ? cleanCss() : plugins.util.noop())
.pipe(gulp.dest(CSS_DEST));
}
Expand Down
4 changes: 2 additions & 2 deletions tools/utils/seed/code_change_tools.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as browserSync from 'browser-sync';
import * as path from 'path';

import { BROWSER_SYNC_CONFIG } from '../../config';
import { getPluginConfig } from '../../config';

/**
* Initialises BrowserSync with the configuration defined in seed.config.ts (or if overriden: project.config.ts).
*/
let runServer = () => {
browserSync.init(BROWSER_SYNC_CONFIG);
browserSync.init(getPluginConfig('browser-sync'));
};

/**
Expand Down