Snippets

Mitch Allen Node Starter Script

Updated by Mitch Allen

File readme-starter.sh Deleted

  • Ignore whitespace
  • Hide word diff
-#!/bin/bash
-
-# called by node-starter.sh
-
-function buildReadme {
-
-
-if [$# -ne 3]; 
-    then echo "illegal number of parameters"
-    exit 1
-fi
-
-$NPM_SCOPE=$1
-$packageName=$2
-$BITBUCKET_USER=$3
-
-cat <<EOT >> README.md
-@${NPM_SCOPE}/${packageName}
-==
-PUT DESCRIPTION HERE
---
-* * *
-## Installation
-
-You must use __npm__ __2.7.0__ or higher because of the scoped package name.
-
-    $ npm init
-    $ npm install @${NPM_SCOPE}/${packageName} --save
-  
-* * *
-
-## Usage
-
-## Testing
-
-To test, go to the root folder and type (sans __$__):
-
-    $ npm test
-   
-* * *
- 
-## Repo(s)
-
-* [bitbucket.org/${BITBUCKET_USER}/${packageName}.git](https://bitbucket.org/${BITBUCKET_USER}/$packageName.git)
-
-* * *
-
-## Contributing
-
-In lieu of a formal style guide, take care to maintain the existing coding style.
-Add unit tests for any new or changed functionality. Lint and test your code.
-
-* * *
-
-## Version History
-
-#### Version 0.1.0 
-
-* initial release
-
-* * *
-
-EOT
-
-}
Updated by Mitch Allen

File node-starter.sh Modified

  • Ignore whitespace
  • Hide word diff
 git commit -m 'init commit'
 
 # Create Bitbucket Repo (THIS WILL BE PUBLIC BY DEFAULT)
-# Password retrieved from env var: BB_PASSWORD (TODO - use auth token instead)
-curl --user $BITBUCKET_USER:$BB_PASSWORD https://api.bitbucket.org/1.0/repositories --data name=$packageName
+# Will ask user for password
+echo "### Enter your BITBUCKET password at the prompt: "
+curl --user $BITBUCKET_USER https://api.bitbucket.org/1.0/repositories --data name=$packageName
 
 # Add remote
 git remote add origin git@bitbucket.org:$BITBUCKET_USER/$packageName.git
Updated by Mitch Allen

File readme-starter.sh Added

  • Ignore whitespace
  • Hide word diff
+#!/bin/bash
+
+# called by node-starter.sh
+
+function buildReadme {
+
+
+if [$# -ne 3]; 
+    then echo "illegal number of parameters"
+    exit 1
+fi
+
+$NPM_SCOPE=$1
+$packageName=$2
+$BITBUCKET_USER=$3
+
+cat <<EOT >> README.md
+@${NPM_SCOPE}/${packageName}
+==
+PUT DESCRIPTION HERE
+--
+* * *
+## Installation
+
+You must use __npm__ __2.7.0__ or higher because of the scoped package name.
+
+    $ npm init
+    $ npm install @${NPM_SCOPE}/${packageName} --save
+  
+* * *
+
+## Usage
+
+## Testing
+
+To test, go to the root folder and type (sans __$__):
+
+    $ npm test
+   
+* * *
+ 
+## Repo(s)
+
+* [bitbucket.org/${BITBUCKET_USER}/${packageName}.git](https://bitbucket.org/${BITBUCKET_USER}/$packageName.git)
+
+* * *
+
+## Contributing
+
+In lieu of a formal style guide, take care to maintain the existing coding style.
+Add unit tests for any new or changed functionality. Lint and test your code.
+
+* * *
+
+## Version History
+
+#### Version 0.1.0 
+
+* initial release
+
+* * *
+
+EOT
+
+}
Created by Mitch Allen

File node-starter.sh Added

  • Ignore whitespace
  • Hide word diff
+#!/bin/bash
+
+# Child Scripts
+# put before calles to cd
+# child scripts must be marked as chmod +x
+source ./readme-starter.sh
+
+# Requires: [sudo] npm install -g json
+
+if [[ $# -eq 0 ]]; then
+	echo "Usage: node-starter.sh package-name"
+	exit 1
+fi
+
+# Setup package folder
+
+packageName=$1
+
+printf 'PACKAGE NAME: %s\n' "$packageName"
+
+if [ -d $packageName ]; then
+	echo "ERROR: folder ${packageName} already exists"
+	exit 1
+else
+	echo "Folder ${packageName} does not exist"
+	mkdir $packageName 
+fi
+
+# Initialize Variables
+
+BITBUCKET_USER=mitchallen
+GITHUB_USER=mitchallen
+NPM_SCOPE=mitchallen
+AUTHOR_NAME='Mitch Allen'
+AUTHOR_EMAIL='npm@mitchallen.com'
+AUTHOR_URL='http://mitchallen.com'
+npmAuthor="$AUTHOR_NAME <$AUTHOR_EMAIL> ($AUTHOR_URL)"
+
+
+# Change to the package folder
+
+cd $packageName
+
+# Setup test folder
+
+mkdir test
+touch test/smoke-test.js
+
+# Setup examples folder
+
+mkdir examples
+
+# Init: README.md
+
+buildReadme $NPM_SCOPE $packageName $BITBUCKET_USER
+
+# Init: index.js
+
+echo "//  Author: Mitch Allen" >> index.js
+echo "// Package: @${NPM_SCOPE}/${packageName}" >> index.js
+
+# Clone my public Gruntfile.js starter file
+
+gruntStarter="starter-gruntfile"
+
+# Note, you can change starter to anything - that's what the folder will be called
+git clone git@bitbucket.org:snippets/mitchallen/n48z6/${gruntStarter}.git
+cp $gruntStarter/Gruntfile.js .
+rm -rf $gruntStarter
+
+# Clone my public package.json starter file
+
+packageStarter="starter-package-json"
+# Note, you can change starter to anything - that's what the folder will be called
+git clone git@bitbucket.org:snippets/mitchallen/qjMg8/${packageStarter}.git
+cp $packageStarter/package.json .
+rm -rf $packageStarter
+
+json -I -f package.json -e "this.name='@${NPM_SCOPE}/${packageName}'"
+json -I -f package.json -e "this.author='${npmAuthor}'"
+json -I -f package.json -e "this.repository.url='https://bitbucket.org/$BITBUCKET_USER/${packageName}.git'"
+
+cat package.json
+
+# Initialize NPM
+
+npm install
+
+# Init git
+
+git init
+git add .
+git commit -m 'init commit'
+
+# Create Bitbucket Repo (THIS WILL BE PUBLIC BY DEFAULT)
+# Password retrieved from env var: BB_PASSWORD (TODO - use auth token instead)
+curl --user $BITBUCKET_USER:$BB_PASSWORD https://api.bitbucket.org/1.0/repositories --data name=$packageName
+
+# Add remote
+git remote add origin git@bitbucket.org:$BITBUCKET_USER/$packageName.git
+
+# Reference: http://blog.kevinlee.io/2013/03/11/git-push-to-pull-from-both-github-and-bitbucket/
+
+# TODO - append GITHUB to Origina
+# git remote set-url origin --add git@bitbucket.org:$GITHUB_USER/$packagename.git 
+
+git remote -v show
+
+git push -u origin --all # pushes up the repo and its refs for the first time
+git push origin --tags # pushes up any tags
+
+# Run grunt (to do a lint check)
+grunt
+
+# Verify testing is setup
+
+npm test
+
+# Inform User
+
+echo "========================================================================"
+echo "*"
+echo "*   New starter project created in $packageName"
+echo "*"
+echo "*   Created PUBLIC $packageName on Bitbucket"
+echo "*"
+echo "========================================================================"
  1. 1
  2. 2
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.