UNPKG

1.54 kBJavaScriptView Raw
1
2const {join, resolve} = require('path');
3const process = require('process');
4const {safeLoad} = require('js-yaml');
5const {readFileSync} = require('fs');
6
7const SetEnv = (node_env, rails_env)=>{
8 let env = node_env || rails_env;
9 switch (env){
10 case undefined:
11 return 'development';
12 case 'staging':
13 return 'production';
14 default:
15 return env;
16 }
17};
18
19const {NODE_ENV, RAILS_ENV} = process.env;
20process.env.NODE_ENV = SetEnv(NODE_ENV, RAILS_ENV);
21const env = process.env;
22
23const configPath = resolve('config', 'webpack');
24const loadersDir = join(__dirname, 'loaders');
25const paths = safeLoad(readFileSync(join(configPath, 'paths.yml'), 'utf8'));
26const devServer = safeLoad(readFileSync(join(configPath, 'development.server.yml'), 'utf8'));
27
28let amazonS3;
29try {
30 amazonS3 = safeLoad(readFileSync(join(configPath, 'amazons3.yml'), 'utf8'));
31} catch (e){
32 amazonS3 = false;
33}
34
35const date = new Date();
36const timeStamp = date.getTime();
37const basePath = `${paths.entry}/${timeStamp}`;
38
39const publicPathCheck = (node_env, ds, aws)=>{
40 if (node_env === 'development' && ds.enabled){
41 return `http://${devServer.host}:${devServer.port}/`;
42 } else if (aws){
43 let cloudfront = aws[node_env].cloudfront;
44 let baseDir = aws[node_env].baseDir;
45 return `${cloudfront}/${baseDir}/${basePath}/`;
46 }
47
48 return `/${paths.entry}/`;
49};
50
51const publicPath = publicPathCheck(env.RAILS_ENV, devServer, amazonS3);
52
53module.exports = {
54 amazonS3
55 , basePath
56 , devServer
57 , env
58 , paths
59 , loadersDir
60 , publicPath
61};