forked from siteworxcarlos/slush-atom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slushfile.js
112 lines (100 loc) · 3.7 KB
/
slushfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* slush-sample
* https://github.com/siteworxcarlos/slush-atom
*
* Copyright (c) 2016, Carlos
* Licensed under the MIT license.
*/
'use strict';
var gulp = require('gulp'),
install = require('gulp-install'),
conflict = require('gulp-conflict'),
template = require('gulp-template'),
replace = require('gulp-replace'),
rename = require('gulp-rename'),
_ = require('underscore.string'),
inquirer = require('inquirer'),
path = require('path');
function format(string) {
var username = string.toLowerCase();
return username.replace(/\s/g, '');
}
var defaults = (function () {
var workingDirName = path.basename(process.cwd()),
homeDir, osUserName, configFile, user;
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';
}
configFile = path.join(homeDir, '.gitconfig');
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', function (done) {
var prompts = [{
name: 'appName',
message: 'What is the name of your atom?',
default: defaults.appName
}];
//Ask
inquirer.prompt(prompts,
function (answers) {
answers.appNameSlug = _.slugify(answers.appName);
//output mustache file in project directory
gulp.src(__dirname + '/templates/*.mustache')
.pipe(template(answers))
.pipe(rename(function(file) {
file.basename = answers.appName;
}))
.pipe(conflict('./'))
.pipe(gulp.dest('source/_patterns/00-atoms/00-'+answers.appName))
.pipe(install())
.on('end', function() {
done();
});
//output scss file in project directory
gulp.src(__dirname + '/templates/app-sm.scss')
.pipe(template(answers))
.pipe(rename(function(file) {
file.basename = '_'+answers.appName + "-sm";
}))
.pipe(conflict('./'))
.pipe(gulp.dest('source/css/scss/modules/'+answers.appName))
.pipe(install())
.on('end', function() {
done();
});
gulp.src(__dirname + '/templates/app-lg.scss')
.pipe(template(answers))
.pipe(rename(function(file) {
file.basename = '_'+answers.appName + "-lg";
}))
.pipe(conflict('./'))
.pipe(gulp.dest('source/css/scss/modules/'+answers.appName))
.pipe(install())
.on('end', function() {
done();
});
//update scss file
gulp.src('source/css/*.scss')
.pipe(replace('//scaffold-mobile','@import "scss/modules/'+answers.appName+'/'+answers.appName+'-sm";\n//scaffold-mobile'))
.pipe(replace('//scaffold-desktop','@import "scss/modules/'+answers.appName+'/'+answers.appName+'-lg";\n//scaffold-desktop'))
.pipe(gulp.dest('source/css/'))
.pipe(install())
.on('end', function() {
done();
});
});
});