-
Notifications
You must be signed in to change notification settings - Fork 15
/
template.js
119 lines (107 loc) · 4.06 KB
/
template.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
113
114
115
116
117
118
119
/**
* iemoto
* https://github.com/megumiteam/iemoto/blob/master/template.js
*
* Licensed under the GPLv2
*/
'use strict';
exports.description = 'Create a WordPress theme based on Automattic\'s _s starter theme.';
exports.notes = '';
exports.after = '';
exports.warnOn = '*';
// The actual init template
exports.template = function( grunt, init, done ) {
init.process( {}, [
// Prompt for these values.
init.prompt( 'title', 'Iemoto' ),
{
name : 'prefix',
message: 'PHP function prefix (alpha and underscore characters only)',
default: 'iemoto'
},
init.prompt( 'description', 'Megumi theme based on Underscores' ),
init.prompt( 'homepage', 'https://www.digitalcube.jp/' ),
init.prompt( 'author_name', 'DigitalCube Co.,Ltd' ),
init.prompt( 'author_url', 'https://www.digitalcube.jp/' ),
{
name: 'gulp',
message: 'Use gulp?',
default: 'y/N'
}
], function( err, props ) {
props.keywords = [];
props.version = '0.1.0';
// Use gulp or grunt
if ( props.gulp == 'y' ) {
props.devDependencies = {
"gulp": "^3.9.0",
"gulp-compass": "^2.1.0",
"gulp-jshint": "^2.0.0",
"gulp-load-plugins": "^1.5.0",
"gulp-notify": "^3.0.0",
"gulp-plumber": "^1.1.0",
"gulp-replace": "^0.5.0",
"gulp-replace": "^0.5.0",
"jshint": "^2.9.4",
"run-sequence": "^1.2.0"
};
} else {
props.devDependencies = {
"grunt": "^1.0.0",
"grunt-contrib-compass": "^1.1.0",
"grunt-contrib-jshint": "^1.0.0",
"grunt-contrib-watch": "^1.0.0",
"grunt-text-replace": "^0.4.0",
"load-grunt-tasks": "^3.5.0"
};
}
// Sanitize names where we need to for PHP/JS
props.name = props.title.replace( /\s+/g, '-' ).toLowerCase();
// Development prefix (i.e. to prefix PHP function names, variables)
props.prefix = props.prefix.replace('/[^a-z_]/i', '').toLowerCase();
// Development prefix in all caps (e.g. for constants)
props.prefix_caps = props.prefix.toUpperCase();
// An additional value, safe to use as a JavaScript identifier.
props.js_safe_name = props.name.replace(/[\W_]+/g, '_').replace(/^(\d)/, '_$1');
props.file_name = props.js_safe_name.replace(/_/g, '-');
// An additional value that won't conflict with NodeUnit unit tests.
props.js_test_safe_name = props.js_safe_name === 'test' ? 'myTest' : props.js_safe_name;
props.js_safe_name_caps = props.js_safe_name.toUpperCase();
// Files to copy and process
var files = init.filesToCopy( props );
console.log( files );
// Actually copy and process files
init.copyAndProcess( files, props, {noProcess: ['screenshot.png', 'languages/*.mo']} );
// Generate package.json file
init.writePackageJSON( 'package.json', props );
var path = require('path');
var fs = require('fs');
fs.stat(path.resolve('css'), function(err, stats){
if (err) {
fs.mkdir(path.resolve('css'));
}
});
fs.stat(path.resolve('images'), function(err, stats){
if (err) {
fs.mkdir(path.resolve('images'));
}
});
fs.renameSync(
path.resolve('js')+'/iemoto.js',
path.resolve('js')+'/'+props.file_name+'.js'
);
fs.renameSync(
path.resolve('languages')+'/_s.pot',
path.resolve('languages')+'/'+props.prefix+'.pot'
);
if ( props.gulp == 'y' ) {
fs.unlinkSync('Gruntfile.js')
console.log('Deleted Gruntfile.js');
} else {
fs.unlinkSync('gulpfile.js')
console.log('Deleted gulpfile.js');
}
// Done!
done();
});
};