-
Notifications
You must be signed in to change notification settings - Fork 6
/
template.js
129 lines (118 loc) · 4.88 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
120
121
122
123
124
125
126
127
128
129
/**
* Copyright 2014 Francesco Camarlinghi
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
// Basic template description.
exports.description = 'Create a Creative Cloud extension project.';
// Template-specific notes to be displayed before question prompts.
exports.notes = '';
// Template-specific notes to be displayed after question prompts.
exports.after = 'Please refer to documentation to start developing the extension.';
// Any existing file or directory matching this wildcard will cause a warning.
exports.warnOn = '*';
// The actual init template.
exports.template = function (grunt, init, done)
{
var path = require('path'),
supported_products = ['photoshop', 'illustrator', 'indesign', 'flash', 'premiere', 'prelude', 'aftereffects', 'dreamweaver', 'incopy'],
sanitize_products = function (products, supported)
{
products = products.toLowerCase().split(/\s*,+\s*/);
products = products.reduce(function (reduced, item)
{
// Remove empty values, duplicates and check if product is valid
if (item !== '' && reduced.indexOf(item) < 0 && supported.indexOf(item) > -1)
reduced.push(item);
return reduced;
}, []);
return products;
};
init.process({}, [
// Prompt for these values
init.prompt('name'),
{
name: 'id',
message: 'Project Identifier (unique)',
validator: /^[a-zA-Z][\.a-zA-Z0-9]*$/,
warning: 'Can only contain letters, numbers, and periods. Must start with a letter.',
default: function (value, data, done)
{
// Copied from grunt-init 'Project name'
var types = ['javascript', 'js'];
if (data.type) { types.push(data.type); }
var type = '(?:' + types.join('|') + ')';
// This regexp matches:
// leading type- type. type_
// trailing -type .type _type and/or -js .js _js
var re = new RegExp('^' + type + '[\\-\\._]?|(?:[\\-\\._]?' + type + ')?(?:[\\-\\._]?js)?$', 'ig');
// Strip the above stuff from the current dirname.
var name = path.basename(process.cwd()).replace(re, '');
// Remove anything not a letter, number, dash, dot or underscore.
name = name.replace(/[^\w\-\.]/g, '');
// Replace dashes with dots
name = name.replace(/\-/g, '.');
done(null, 'com.' + name);
}
},
init.prompt('description'),
init.prompt('version'),
{
name: 'author_name',
message: 'Author Name',
validator: /^[a-zA-Z0-9\s\.]+$/,
warning: 'Can only contain letters, numbers, periods and spaces.',
default: function (value, data, done)
{
// Attempt to pull the data from the user's git config.
grunt.util.spawn({
cmd: 'git',
args: ['config', '--get', 'user.name'],
fallback: 'none'
}, done);
}
},
{
name: 'products',
message: 'Supported Creative Cloud Products',
validator: function (value)
{
var items = sanitize_products(value, supported_products);
return items.length > 0;
},
sanitize: function (value, data, done)
{
var items = sanitize_products(value, supported_products);
done(JSON.stringify(items));
},
warning: 'Please list (comma-separated). Options: ' + supported_products.join(', ') + '.',
default: 'photoshop'
},
],
function (err, props)
{
// Add other properties
props.year = (new Date()).getFullYear();
props.basename = props.name.replace(/[\s]+/g, '-').toLowerCase();
props.devDependencies = {
'grunt-cep': '~0.2.0',
};
// Files to copy (and process)
var files = init.filesToCopy(props);
// Actually copy (and process) files
init.copyAndProcess(files, props, { noProcess: ['bundle/*.png', 'bundle/*.xml', 'bundle/*.mxi', 'src/js/lib/**', 'src/icons/**'] });
// All done!
done();
});
};