Skip to content
Browse files

chore: add init-dev-env for easy workspace setup

  • Loading branch information...
1 parent 5fcbcc1 commit 2784b72a09f9190169d87547ea9e6134771a507b @rgaskill rgaskill committed with vojtajina Apr 6, 2013
Showing with 128 additions and 6 deletions.
  1. +1 −0 .gitignore
  2. +5 −0 Gruntfile.coffee
  3. +3 −6 docs/dev/02-contributing.md
  4. +1 −0 init-dev-env.bat
  5. +118 −0 init-dev-env.js
View
1 .gitignore
@@ -1,6 +1,7 @@
node_modules
static/karma.js
.idea/*
+*.iml
tmp/*
docs/_build
*.swp
View
5 Gruntfile.coffee
@@ -21,6 +21,7 @@ module.exports = (grunt) ->
server: ['lib/**/*.js']
client: ['static/karma.src.js']
grunt: ['grunt.js', 'tasks/**/*.js']
+ init: ['init-dev-env.js']
build:
client: '<%= files.client %>'
@@ -58,6 +59,10 @@ module.exports = (grunt) ->
files:
src: '<%= files.grunt %>'
options: JSHINT_NODE
+ init:
+ files:
+ src: '<%= files.init %>'
+ options: JSHINT_NODE
client:
files:
src: '<%= files.client %>'
View
9 docs/dev/02-contributing.md
@@ -12,15 +12,12 @@ are some tips to get you started.
## Making Changes
* Clone your fork
-* Install dependencies via
+* Init your workspace
- ```bash
- $ npm install
- ```
-* Install global dependencies via
```bash
-$ npm install grunt-cli -g
+$ ./init-dev-env.js
```
+
* Checkout a new branch (usually based on `master`) and name it accordingly to what
you intend to do
* Features get the prefix `feature-`
View
1 init-dev-env.bat
@@ -0,0 +1 @@
+node init-dev-env.js
View
118 init-dev-env.js
@@ -0,0 +1,118 @@
+#!/usr/bin/env node
+'use strict';
+
+var fs = require('fs');
+var exec = require('child_process').exec;
+
+var isWin = !!process.platform.match(/^win/);
+
+var validateCommitPath = '../../tasks/lib/validate-commit-msg.js';
+var gitHookPath = '.git/hooks/commit-msg';
+
+var nodeModulesPath = 'node_modules';
+var karmaPath = '..';
+var nmKarmaPath = 'node_modules/karma';
+
+//Add Hook "validate-commit-msg"
+var gitHookSetup = function(){
+ if (fs.existsSync(gitHookPath)) {
+ fs.unlinkSync(gitHookPath);
+ console.log('Existing link removed:', gitHookPath);
+ }
+
+ console.log('Adding symbolic link: %s linked to %s', validateCommitPath, gitHookPath);
+ fs.symlinkSync(validateCommitPath, gitHookPath, 'file');
+};
+
+var selfLinkSetup = function() {
+ if (!fs.existsSync(nodeModulesPath)) {
+ fs.mkdirSync(nodeModulesPath);
+ }
+
+ if (fs.existsSync(nmKarmaPath)) {
+ fs.unlinkSync(nmKarmaPath);
+ console.log('Existing link removed:', nmKarmaPath);
+ }
+
+ console.log('Adding symbolic link: %s linked to %s', karmaPath, nmKarmaPath);
+ fs.symlinkSync(karmaPath, nmKarmaPath, 'dir');
+};
+
+// Check for gurnt-cli
+var installGruntCli = function(callback) {
+
+ console.log('Installing grunt-cli...');
+
+ var gcli = exec('npm install -g grunt-cli', function (error) {
+
+ if (error !== null) {
+ console.error('error installing grunt-cli: ' + error);
+ } else {
+ callback();
+ }
+
+ });
+
+ gcli.stdout.pipe(process.stdout);
+ gcli.stderr.pipe(process.stderr);
+
+};
+
+var checkForGruntCli = function(callback) {
+
+ console.log('Checking for grunt-cli...');
+
+ exec('grunt --version', function (error, stdout) {
+
+ if ( error ) {
+ installGruntCli(callback);
+ } else {
+ console.log('grunt-cli is already installed:');
+ console.log(stdout);
+ callback();
+ }
+
+ });
+};
+
+var installDependencies = function() {
+
+ console.log('Installing dependencies...');
+
+ var install = exec('npm install', function (error) {
+
+ if (error !== null) {
+ console.error('Error installing karma dependencies: ' + error);
+ }
+
+ });
+
+ install.stdout.pipe(process.stdout);
+ install.stderr.pipe(process.stderr);
+
+};
+
+var runInit = function() {
+
+ gitHookSetup();
+ selfLinkSetup();
+ checkForGruntCli(function cb() {
+ installDependencies();
+ });
+
+};
+
+if ( isWin ){
+
+ exec('whoami /priv', function(err, o) {
+ if (err || o.indexOf('SeCreateSymbolicLinkPrivilege') === -1) {
+ console.log('You do not appear to have symlink privileges. Exiting init script.');
+ console.log('Windows requires admin privileges to create symlinks.');
+ } else {
+ runInit();
+ }
+ });
+
+} else {
+ runInit();
+}

0 comments on commit 2784b72

Please sign in to comment.
Something went wrong with that request. Please try again.