Last active
April 19, 2017 19:08
-
-
Save liperuf/f66fdbab5af51350cb1e29ec8e5d10eb to your computer and use it in GitHub Desktop.
Simple bootstrap for new webpack based feature
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
#!/bin/bash | |
# How do I parse command line arguments in Bash? | |
# http://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash | |
if [[ -n $1 ]]; then | |
echo "Creating project $1" | |
mkdir $1 | |
cd $1 | |
npm init -y | |
mkdir app | |
mkdir app/scripts app/styles app/images app/fonts app/fonts | |
touch app/styles/.gitkeep app/images/.gitkeep app/fonts/.gitkeep app/fonts/.gitkeep | |
echo "console.log('It works!')" >> app/scripts/main.js | |
echo "<h1>It works!</h1>" >> app/index.html | |
echo "<script type="text/javascript" src='main.js'></script>" >> app/index.html | |
curl https://gist.githubusercontent.com/liperuf/a867de74013fee8be3f1a12da7f8e999/raw/42a091170707654974fec2a84a3d8cf5420b17f6/webpack.config.js > webpack.config.js | |
npm i -D babel-core babel-loader babel-preset-env copy-webpack-plugin css-loader extract-text-webpack-plugin sass-loader style-loader webpack webpack-dev-server node-sass webpack-notifier | |
# change json file by bash script | |
# http://stackoverflow.com/questions/24942875/change-json-file-by-bash-script | |
jsonFile="package.json"; | |
node > ${jsonFile}.tmp <<EOF | |
//Read data | |
var data = require('./${jsonFile}'); | |
//Manipulate data | |
data.scripts = { | |
start: "webpack-dev-server --inline", | |
build: "webpack -p" | |
}; | |
// How can I pretty-print JSON? | |
// http://stackoverflow.com/questions/352098/how-can-i-pretty-print-json | |
//Output data | |
console.log(JSON.stringify(data, null, 2)); | |
EOF | |
mv ${jsonFile}.tmp ${jsonFile} | |
else | |
echo "Invalid argument. You must provide a project name." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment