-
Notifications
You must be signed in to change notification settings - Fork 0
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 KateKate/dev
Refactoring slashfile inline with ES6
- Loading branch information
Showing
4 changed files
with
150 additions
and
137 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 |
---|---|---|
@@ -1,43 +1,46 @@ | ||
{ | ||
"name": "slush-spa", | ||
"description": "SPA creation", | ||
"version": "0.0.0", | ||
"homepage": "https://github.com/KateKate/slush-spa", | ||
"author": { | ||
"name": "Kate Anishkina", | ||
"email": "[email protected]" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/KateKate/slush-spa.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/KateKate/slush-spa/issues" | ||
}, | ||
"licenses": [{ | ||
"type": "MIT", | ||
"url": "https://github.com/KateKate/slush-spa/blob/master/LICENSE" | ||
}], | ||
"main": "slushfile.js", | ||
"engines": { | ||
"node": ">= 0.10.26", | ||
"npm": ">=1.4.3" | ||
}, | ||
"scripts": { | ||
"test": "echo \"No tests\"" | ||
}, | ||
"dependencies": { | ||
"slush": ">=1.0.0", | ||
"gulp": "^3.6.2", | ||
"gulp-template": "^0.1.1", | ||
"gulp-install": "^0.1.4", | ||
"gulp-conflict": "^0.1.1", | ||
"gulp-rename": "^1.2.0", | ||
"underscore.string": "^2.3.3", | ||
"inquirer": "^0.8.0", | ||
"iniparser": "^1.0.5" | ||
}, | ||
"keywords": [ | ||
"slushgenerator" | ||
] | ||
"name": "slush-spa", | ||
"description": "SPA creation", | ||
"version": "0.1.0", | ||
"homepage": "https://github.com/KateKate/slush-spa", | ||
"author": { | ||
"name": "Kate Anishkina", | ||
"email": "[email protected]" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/KateKate/slush-spa.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/KateKate/slush-spa/issues" | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "https://github.com/KateKate/slush-spa/blob/master/LICENSE" | ||
} | ||
], | ||
"main": "slushfile.js", | ||
"engines": { | ||
"node": ">= 0.10.26", | ||
"npm": ">=1.4.3" | ||
}, | ||
"scripts": { | ||
"test": "echo \"No tests\"" | ||
}, | ||
"dependencies": { | ||
"babel": "^5.8.23", | ||
"gulp": "^3.6.2", | ||
"gulp-conflict": "^0.1.1", | ||
"gulp-install": "^0.1.4", | ||
"gulp-rename": "^1.2.0", | ||
"gulp-template": "^0.1.1", | ||
"iniparser": "^1.0.5", | ||
"inquirer": "^0.8.0", | ||
"slush": ">=1.0.0", | ||
"underscore.string": "^2.3.3" | ||
}, | ||
"keywords": [ | ||
"slushgenerator" | ||
] | ||
} |
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,94 @@ | ||
import gulp from 'gulp'; | ||
import install from 'gulp-install'; | ||
import conflict from 'gulp-conflict'; | ||
import template from 'gulp-template'; | ||
import rename from 'gulp-rename'; | ||
import inquirer from 'inquirer'; | ||
import path from 'path'; | ||
|
||
const _ = require('underscore.string'); | ||
|
||
function format(string) { | ||
const username = string.toLowerCase(); | ||
return username.replace(/\s/g, ''); | ||
} | ||
|
||
const defaults = (() => { | ||
const workingDirName = path.basename(process.cwd()); | ||
|
||
let homeDir, osUserName; | ||
if (process.platform === 'win32') { | ||
homeDir = process.env.USERPROFILE; | ||
osUserName = process.env.USERNAME || path.basename(homeDir).toLowerCase(); | ||
} | ||
else { | ||
homeDir = process.env.HOME || process.env.HOMEPATH; | ||
osUserName = homeDir && homeDir.split('/').pop() || 'root'; | ||
} | ||
|
||
const configFile = path.join(homeDir, '.gitconfig'); | ||
let user = {}; | ||
|
||
if (require('fs').existsSync(configFile)) { | ||
user = require('iniparser').parseSync(configFile).user; | ||
} | ||
|
||
return { | ||
appName: workingDirName, | ||
userName: osUserName || format(user.name || ''), | ||
authorName: user.name || '', | ||
authorEmail: user.email || '' | ||
}; | ||
|
||
})(); | ||
|
||
gulp.task('default', (done) => { | ||
const prompts = [{ | ||
name: 'appName', | ||
message: 'What is the name of your project?', | ||
default: defaults.appName | ||
}, { | ||
name: 'appDescription', | ||
message: 'What is the description?' | ||
}, { | ||
name: 'appVersion', | ||
message: 'What is the version of your project?', | ||
default: '0.1.0' | ||
}, { | ||
name: 'authorName', | ||
message: 'What is the author name?', | ||
default: defaults.authorName | ||
}, { | ||
name: 'authorEmail', | ||
message: 'What is the author email?', | ||
default: defaults.authorEmail | ||
}, { | ||
name: 'userName', | ||
message: 'What is the github username?', | ||
default: defaults.userName | ||
}, { | ||
type: 'confirm', | ||
name: 'moveon', | ||
message: 'Continue?' | ||
}]; | ||
|
||
inquirer.prompt(prompts, (answers) => { | ||
if (!answers.moveon) { | ||
return done(); | ||
} | ||
answers.appNameSlug = _.slugify(answers.appName); | ||
gulp.src(__dirname + '/templates/**') | ||
.pipe(template(answers)) | ||
.pipe(rename( (file) => { | ||
if (file.basename[0] === '_') { | ||
file.basename = '.' + file.basename.slice(1); | ||
} | ||
})) | ||
.pipe(conflict('./')) | ||
.pipe(gulp.dest('./')) | ||
.pipe(install()) | ||
.on('end', () => { | ||
done(); | ||
}); | ||
}); | ||
}); |