Skip to content

Commit

Permalink
all the configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
samouri committed Feb 11, 2017
1 parent c755d49 commit 949a25a
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 52 deletions.
8 changes: 2 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ RUN npm install --production || npm install --production
COPY . /calypso

# Build javascript bundles for each environment and change ownership
RUN CALYPSO_ENV=wpcalypso make build-wpcalypso && \
CALYPSO_ENV=horizon make build-horizon && \
CALYPSO_ENV=stage make build-stage && \
CALYPSO_ENV=production make build-production && \
chown -R nobody /calypso
RUN CALYPSO_ENV=production make build && chown -R nobody /calypso

USER nobody
CMD NODE_ENV=production node build/bundle-$CALYPSO_ENV.js
CMD NODE_ENV=production node build/bundle.js
25 changes: 6 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ COMPONENTS_PROPTYPE_FILES = $(shell \
-or -name 'example.jsx' \
-and -not -path '*/test/*' \
)
CLIENT_CONFIG_FILE := client/config/index.js

# variables
NODE_ENV ?= development
Expand All @@ -92,7 +91,7 @@ install: node_modules

# Simply running `make run` will spawn the Node.js server instance.
run: welcome githooks install build
@$(NODE) build/bundle-$(CALYPSO_ENV).js
@$(NODE) build/bundle.js

dashboard: install
@$(NODE_BIN)/webpack-dashboard -- make run
Expand Down Expand Up @@ -132,10 +131,6 @@ mixedindentlint: node_modules/mixedindentlint
.env: FORCE
@$(RECORD_ENV) $@

# generate the client-side `config` js file
$(CLIENT_CONFIG_FILE): .env config/$(CALYPSO_ENV).json config/client.json server/config/regenerate-client.js
@$(NODE) server/config/regenerate-client.js > $@

public/style.css: node_modules $(SASS_FILES)
@$(SASS) assets/stylesheets/style.scss $@
@$(AUTOPREFIXER) $@
Expand Down Expand Up @@ -168,32 +163,24 @@ build-server: install
@mkdir -p build
@CALYPSO_ENV=$(CALYPSO_ENV) $(NODE_BIN)/webpack --display-error-details --config webpack.config.node.js

build: install build-$(CALYPSO_ENV)
build: install build-server build-dll build-css server/devdocs/search-index.js server/devdocs/proptypes-index.json server/devdocs/components-usage-stats.json

build-css: public/style.css public/style-rtl.css public/style-debug.css public/editor.css

build-development: server/devdocs/proptypes-index.json server/devdocs/components-usage-stats.json build-server build-dll $(CLIENT_CONFIG_FILE) server/devdocs/search-index.js build-css

build-wpcalypso: server/devdocs/proptypes-index.json server/devdocs/components-usage-stats.json build-server build-dll $(CLIENT_CONFIG_FILE) server/devdocs/search-index.js build-css
@$(BUNDLER)

build-horizon build-stage build-production: build-server build-dll $(CLIENT_CONFIG_FILE) build-css
@$(BUNDLER)

build-desktop: build-server $(CLIENT_CONFIG_FILE) build-css
build-desktop: build-server build-css
@$(BUNDLER)

# the `clean` rule deletes all the files created from `make build`, but not
# those created by `make install`
clean:
@rm -rf public/style*.css public/style-debug.css.map public/*.js $(CLIENT_CONFIG_FILE) server/devdocs/search-index.js server/devdocs/proptypes-index.json server/devdocs/components-usage-stats.json public/editor.css build/* server/bundler/*.json .babel-cache
@rm -rf public/style*.css public/style-debug.css.map public/*.js server/devdocs/search-index.js server/devdocs/proptypes-index.json server/devdocs/components-usage-stats.json public/editor.css build/* server/bundler/*.json .babel-cache

# the `distclean` rule deletes all the files created from `make install`
distclean: clean
@rm -rf node_modules

# create list of translations, saved as `./calypso-strings.pot`
translate: node_modules $(CLIENT_CONFIG_FILE)
translate: node_modules
$(I18N_CALYPSO) --format pot --output-file ./calypso-strings.pot $(JS_FILES)

# install all git hooks
Expand Down Expand Up @@ -237,6 +224,6 @@ docker-run:
# rule that can be used as a prerequisite for other rules to force them to always run
FORCE:

.PHONY: build build-development build-server build-dll build-desktop build-horizon build-stage build-production build-wpcalypso
.PHONY: build build-dll build-desktop build-server
.PHONY: run install test clean distclean translate route node-version
.PHONY: githooks githooks-commit githooks-push analyze-bundles urn
13 changes: 10 additions & 3 deletions client/config/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
const config = window && window.config;
config.anyEnabled = window && window.anyEnabled;
config.isEnabled = window && window.isEnabled;
let config;
if ( typeof window !== 'undefined' ) {
config = window.config;
config.anyEnabled = window.anyEnabled;
config.isEnabled = window.isEnabled;
} else {
config = () => false;
config.isEnabled = () => false;
config.anyEnabled = () => false;
}

export default config;
4 changes: 1 addition & 3 deletions server/bundler/assets.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/***** WARNING: ES5 code only here. Not transpiled! *****/

var CALYPSO_ENV = process.env.CALYPSO_ENV || 'development';

function middleware( app ) {
var assets = require( './assets-' + CALYPSO_ENV + '.json' );
var assets = require( './assets.json' );
app.use( function( request, response, next ) {
app.set( 'assets', assets );
next();
Expand Down
2 changes: 1 addition & 1 deletion server/bundler/bin/bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ webpack( webpackConfig, function( error, stats ) {
files = assets.map( function( chunk ) {
return path.join( process.cwd(), 'public', chunk.file );
} );
files.push( path.join( process.cwd(), 'public', 'vendor.' + bundleEnv + '.js' ) );
files.push( path.join( process.cwd(), 'public', 'vendor.js' ) );

minify( files );
});
10 changes: 0 additions & 10 deletions server/config/regenerate-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,6 @@ keys.forEach( function( key ) {
}
} );

// console.log( '/* This file is automatically generated. Do not edit manually. */' );
// console.log();
// console.log( 'var data = %s;', JSON.stringify( obj, null, 2 ) );
// console.log( config.toString() );
// console.log( config.isEnabled.toString() );
// console.log( config.anyEnabled.toString() );
// console.log( 'module.exports = config;' );
// console.log( 'module.exports.isEnabled = isEnabled;' );
// console.log( 'module.exports.anyEnabled = anyEnabled;' );
//
var exp = template(
'/* This file is automatically generated. Do not edit manually. */' +
'var data = <%= data %>;' +
Expand Down
4 changes: 2 additions & 2 deletions server/pages/index.jade
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ html(lang=lang, dir=isRTL ? 'rtl' : 'ltr', class=isFluidWidth ? 'is-fluid-width'
if 'development' === env || isDebug
script(src=urls[ 'manifest' ])
script(src=urls[ 'vendor' ])
script(src=urls[ jsFile + '-' + env ])
script(src=urls[ jsFile ])
if chunk
script(src=urls[ '_commons' ])
script(src=urls[ chunk ])
else
script(src=urls[ 'manifest-min' ])
script(src=urls[ 'vendor-min' ])
script(src=urls[ jsFile + '-' + env + '-min' ])
script(src=urls[ jsFile + '-min' ])
if chunk
script(src=urls[ '_commons-min' ])
script(src=urls[ chunk + '-min' ])
Expand Down
4 changes: 2 additions & 2 deletions server/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const staticFiles = [
{ path: 'tinymce/skins/wordpress/wp-content.css' },
{ path: 'style-debug.css' },
{ path: 'style-rtl.css' },
{ path: 'vendor.' + config( 'env' ) + '.js' }
{ path: 'vendor.js' }
];

let sections = sectionsModule.get();
Expand Down Expand Up @@ -82,7 +82,7 @@ function generateStaticUrls( request ) {
} );

// vendor dll
urls.vendor = urls[ 'vendor.' + config( 'env' ) + '.js' ];
urls.vendor = urls[ 'vendor.js' ];
urls[ 'vendor-min' ] = urls.vendor.replace( '.js', '.m.js' );

const assets = request.app.get( 'assets' );
Expand Down
4 changes: 2 additions & 2 deletions webpack-dll.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ module.exports = {
output: {
path: path.join( __dirname, 'public' ),
publicPath: '/calypso/',
filename: '[name].' + bundleEnv + '.js',
filename: '[name].js',
library: '[name]',
devtoolModuleFilenameTemplate: 'app:///[resource-path]'
},
plugins: [
new webpack.DllPlugin( {
path: path.join( __dirname, 'build', 'dll', '[name].' + bundleEnv + '-manifest.json' ),
path: path.join( __dirname, 'build', 'dll', '[name]-manifest.json' ),
name: '[name]',
context: path.resolve( __dirname, 'client' )
} ),
Expand Down
6 changes: 3 additions & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ if ( CALYPSO_ENV === 'desktop' ) {
webpackConfig.plugins.push(
new webpack.DllReferencePlugin( {
context: path.join( __dirname, 'client' ),
manifest: require( './build/dll/vendor.' + bundleEnv + '-manifest.json' )
manifest: require( './build/dll/vendor-manifest.json' )
} )
);

Expand Down Expand Up @@ -169,7 +169,7 @@ if ( CALYPSO_ENV === 'development' ) {
const DashboardPlugin = require( 'webpack-dashboard/plugin' );
webpackConfig.plugins.splice( 0, 0, new DashboardPlugin() );
webpackConfig.plugins.push( new webpack.HotModuleReplacementPlugin() );
webpackConfig.entry[ 'build-' + CALYPSO_ENV ] = [
webpackConfig.entry.build = [
'webpack-dev-server/client?/',
'webpack/hot/only-dev-server',
path.join( __dirname, 'client', 'boot' )
Expand All @@ -189,7 +189,7 @@ if ( CALYPSO_ENV === 'development' ) {
jsLoader.loaders = [ 'react-hot' ].concat( jsLoader.loaders );
}
} else {
webpackConfig.entry[ 'build-' + CALYPSO_ENV ] = path.join( __dirname, 'client', 'boot' );
webpackConfig.entry.build = path.join( __dirname, 'client', 'boot' );
webpackConfig.debug = false;
webpackConfig.devtool = false;
}
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var webpackConfig = {
target: 'node',
output: {
path: path.join( __dirname, 'build' ),
filename: 'bundle-' + ( process.env.CALYPSO_ENV || 'development' ) + '.js',
filename: 'bundle.js',
},
module: {
loaders: [
Expand Down

0 comments on commit 949a25a

Please sign in to comment.