This repository has been archived by the owner on Jan 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
/
template.js
108 lines (92 loc) · 3.32 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
/**
* grunt-wp-theme
* https://github.com/10up/grunt-wp-theme
*
* Copyright (c) 2013 Eric Mann, 10up
* Licensed under the MIT License
*/
'use strict';
// Basic template description
exports.description = 'Create a WordPress theme.';
// Template-specific notes to be displayed before question prompts.
exports.notes = '';
// Template-specific notes to be displayed after the question prompts.
exports.after = '';
// Any existing file or directory matching this wildcard will cause a warning.
exports.warnOn = '*';
// The actual init template
exports.template = function( grunt, init, done ) {
init.process( {}, [
// Prompt for these values.
init.prompt( 'title', 'WP Theme' ),
{
name : 'prefix',
message: 'PHP function prefix (alpha and underscore characters only)',
default: 'wptheme'
},
init.prompt( 'description', 'The best WordPress theme ever made!' ),
init.prompt( 'homepage', 'http://wordpress.org/themes' ),
init.prompt( 'author_name' ),
init.prompt( 'author_email' ),
init.prompt( 'author_url' ),
{
name: 'css_type',
message: 'CSS Preprocessor: Will you use "Sass", "LESS", or "none" for CSS with this project?',
default: 'Sass'
}
], function( err, props ) {
props.keywords = [];
props.version = '0.1.0';
props.devDependencies = {
'grunt': '~0.4.5',
'matchdep': '~0.1.2',
'grunt-contrib-concat': '~0.5.0',
'grunt-contrib-uglify': '~0.6.0',
'grunt-contrib-cssmin': '~0.10.0',
'grunt-contrib-jshint': '~0.10.0',
'grunt-contrib-nodeunit': '~0.4.1',
'grunt-contrib-watch': '~0.6.1',
};
// 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');
// 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 );
switch( props.css_type.toLowerCase()[0] ) {
case 'l':
delete files[ 'assets/css/sass/' + props.js_safe_name + '.scss'];
delete files[ 'assets/css/src/' + props.js_safe_name + '.css' ];
props.devDependencies["grunt-contrib-less"] = "~0.11.2";
props.css_type = 'less';
break;
case 'n':
case undefined:
delete files[ 'assets/css/less/' + props.js_safe_name + '.less'];
delete files[ 'assets/css/sass/' + props.js_safe_name + '.scss'];
props.css_type = 'none';
break;
// SASS is the default
default:
delete files[ 'assets/css/less/' + props.js_safe_name + '.less'];
delete files[ 'assets/css/src/' + props.js_safe_name + '.css' ];
props.devDependencies["grunt-contrib-sass"] = "~0.8.0";
props.css_type = 'sass';
break;
}
console.log( files );
// Actually copy and process files
init.copyAndProcess( files, props );
// Generate package.json file
init.writePackageJSON( 'package.json', props );
// Done!
done();
});
};