forked from 10up/grunt-wp-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.js
110 lines (94 loc) · 3.44 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
/**
* grunt-wp-plugin
* https://github.com/10up/grunt-wp-plugin
*
* Copyright (c) 2013 Eric Mann, 10up
* Licensed under the MIT License
*/
'use strict';
// Basic template description
exports.description = 'Create a WordPress plugin.';
// 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 Plugin' ),
{
name : 'prefix',
message: 'PHP function prefix (alpha and underscore characters only)',
default: 'wpplugin'
},
init.prompt( 'description', 'The best WordPress extension ever made!' ),
init.prompt( 'homepage', 'http://wordpress.org/plugins' ),
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.1',
'grunt-contrib-concat': '~0.1.2',
'grunt-contrib-uglify': '~0.1.1',
'grunt-contrib-cssmin': '~0.6.0',
'grunt-contrib-jshint': '~0.1.1',
'grunt-contrib-nodeunit': '~0.1.2',
'grunt-contrib-watch': '~0.2.0',
'grunt-contrib-clean': '~0.5.0',
'grunt-contrib-copy': '~0.4.1',
'grunt-contrib-compress': '~0.5.2'
};
// 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.5.0";
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.2.2";
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();
});
};