-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from tswayne/cli
Cli
- Loading branch information
Showing
7 changed files
with
191 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const reactHelper = require('react-helper'); | ||
|
||
/** Register your components in this file **/ | ||
//const SomeComponent = require('./path/to/a/component'); | ||
//reactHelper.register({SomeComponent}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict' | ||
var webpack = require('webpack') | ||
var isProdEnvironment = (process.env.NODE_ENV === 'production') | ||
var path = require('path'); | ||
|
||
module.exports = { | ||
cache: true, | ||
devtool: isProdEnvironment ? 'source-map' : 'cheap-module-eval-source-map', | ||
context: __dirname, | ||
entry: [ | ||
'babel-polyfill', | ||
'ENTRY_FILE_PATH', | ||
], | ||
output: { | ||
filename: 'OUTPUT_FILENAME', | ||
path: path.join(__dirname, 'OUTPUT_FILE_PATH'), | ||
}, | ||
resolve: { | ||
extensions: ['.js', '.jsx'], | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.jsx?$/, | ||
use: [{ | ||
loader: 'babel-loader', | ||
options: { | ||
presets: [ | ||
"es2015", | ||
"es2016", | ||
"react" | ||
] | ||
} | ||
}], | ||
exclude: /node_modules/, | ||
}, | ||
], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"presets": [ | ||
"es2015", | ||
"es2016", | ||
"react" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
var program = require('commander'); | ||
var exec = require('child_process').exec; | ||
var fs = require('fs'); | ||
var async = require('async'); | ||
var path = require('path'); | ||
|
||
program | ||
.version('cli version 1.0.0') | ||
|
||
program | ||
.command('init') | ||
.description('add react to your app') | ||
.option('-p, --bundle-path <bundlePath>', 'Bundle path', './public/javascript') | ||
.option('-n, --bundle-name <bundleName>', 'Bundle name', 'bundle.js') | ||
.option('-c, --client-dir <clientDir>', 'React app directory', './client') | ||
.option('-w, --webpack', 'Add webpack and generate config', false) | ||
.action(function(options) { | ||
async.series([ | ||
function(callback){ | ||
console.log('Adding react-helper to app...') | ||
exec('npm install react-helper --save', function(err, stdout, stderr) { | ||
console.log(stdout); | ||
callback(err); | ||
}) | ||
}, | ||
function(callback){ | ||
console.log(`Creating react app directory at ${options.clientDir}`) | ||
exec(`mkdir ${options.clientDir}`, function(err, stdout, stderr) { | ||
console.log(stdout); | ||
callback(err); | ||
}) | ||
}, | ||
function(callback){ | ||
var registrationFilePath = path.resolve(__dirname, 'files/registration-file.js'); | ||
console.log(`Creating component registry ${options.clientDir}/registry.js`) | ||
exec(`cp ${registrationFilePath} ${options.clientDir}/registry.js`, function(err, stdout, stderr) { | ||
console.log(stdout); | ||
callback(err); | ||
}) | ||
}, | ||
function(callback) { | ||
if (options.webpack) { | ||
var entry = `${options.clientDir}/registry.js`; | ||
var bundlePath = options.bundlePath; | ||
if (!entry.includes('./')) { | ||
entry = './' + entry; | ||
} | ||
if (!bundlePath.includes('./')) { | ||
bundlePath = './' + bundlePath; | ||
} | ||
|
||
var filePath = path.resolve(__dirname, 'files/webpack.config.js'); | ||
console.log('Adding webpack to app...') | ||
exec('npm install webpack babel-polyfill babel-loader babel-preset-es2015 babel-preset-es2016 babel-preset-react --save-dev', function (err, stdout, stderr) { | ||
console.log(stdout); | ||
console.log(`Creating webpack config`); | ||
fs.readFile(filePath, 'utf-8', function (err, data) { | ||
if (err) throw err; | ||
var config = data.replace('ENTRY_FILE_PATH', entry) | ||
.replace('OUTPUT_FILENAME', options.bundleName) | ||
.replace('OUTPUT_FILE_PATH', bundlePath); | ||
|
||
fs.writeFile('./webpack.config.js', config, 'utf-8', function (err) { | ||
if (err) throw err; | ||
console.log('webpack config created'); | ||
console.log('to build your bundle run: node_modules/.bin/webpack'); | ||
callback(); | ||
}); | ||
}); | ||
}); | ||
} | ||
} | ||
], function(err, results) { | ||
if (err) { | ||
console.log(err) | ||
} else { | ||
console.log('Done!') | ||
} | ||
}) | ||
}) | ||
|
||
|
||
program.parse(process.argv); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters