Preconfigures a new npm based project via script
- Add
.editorconfig
if not existing - Set indent size 3
- Add prettier + config
.prettierrc.json
- Add
.gitignore
- Add
normalize.css
- Manually needs to add
@import "~normalize.css/normalize.css";
- Manually needs to add
#!/usr/bin/env bash
function log() {
message=
tput setaf 2
echo ${message}
tput sgr0
}
function logWarn() {
message=
tput setaf 3
echo ${message}
tput sgr0
}
function logError() {
message=
tput setaf 1
echo ${message}
tput sgr0
}
if [ ! -f "./package.json" ]
then
logError "package.json not found!"
logWarn "The project needs to be an npm project. You can init npm using the command:"
log "npm init"
exit 1
fi
backupPath=$(pwd)
baseDir=$(dirname $0)
cd ${baseDir}
# Update indent size
if [ -f "./.editorconfig" ]
then
log "Updating .editorconfig"
log "Set indent size to 3"
sed -i -e 's/indent_size = 4/indent_size = 3/g' ./.editorconfig
sed -i -e 's/indent_size = 2/indent_size = 3/g' ./.editorconfig
else
log "Creating .editorconfig file"
echo "# Editor configuration, see http://editorconfig.org
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 3
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
max_line_length = off
trim_trailing_whitespace = false
" >> ./.editorconfig
fi
# Add prettier
log "Install prettier and add config"
npm install --save-dev prettier
echo "{
\"printWidth\": 130,
\"tabWidth\": 3,
\"singleQuote\": true,
\"insertPragma\": false
}
" >> ./.prettierrc.json
# Add gitignore if not exists
if [ ! -f "./.gitignore" ]
then
log "Create .gitignore"
echo "# Specifies intentionally untracked files to ignore when using Git
# http://git-scm.com/docs/gitignore
*~
*.sw[mnpcod]
*.log
*.tmp
*.tmp.*
log.txt
*.sublime-project
*.sublime-workspace
.vscode/
npm-debug.log*
.idea/
.sourcemaps/
.sass-cache/
.tmp/
.versions/
coverage/
dist/
node_modules/
tmp/
temp/
hooks/
platforms/
plugins/
plugins/android.json
plugins/ios.json
www/
$RECYCLE.BIN/
.DS_Store
Thumbs.db
UserInterfaceState.xcuserstate
" >> ./.gitignore
fi
# Add normalize.css
log "Install normalize.css"
npm install --save normalize.css
logError "1 manual step to to:"
logWarn "Add line to your root CSS/SASS file:"
log "@import \"~normalize.css/normalize.css\";"
# Set CL path to initial
cd ${backupPath}
exit 0