-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtemplate.js
178 lines (156 loc) · 6.12 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
* grunt-init-amber
* https://amber-lang.net/
*
* Copyright (c) 2013 Manfred Kroehnert, contributors
* Licensed under the MIT license.
*/
'use strict';
// Basic template description.
exports.description = 'Create a web application based on Amber Smalltalk.';
// Template-specific notes to be displayed before question prompts.
exports.notes = ' _Project title_ should be a human-readable title.';
// Template-specific notes to be displayed after question prompts.
exports.after = 'You need to have these installed globally via npm:' +
' _amber-cli_; _grunt-cli_; _bower_.' +
' Now, install project dependencies with _bower install_,' +
' tool dependencies with _npm install_ and optionally, recompile with _grunt_.' +
' If you are running _amber init_, these three tasks are going to be performed for you now.' +
' Afterwards, start the development server with _amber serve_.' +
' Your application is then accessible via _http://localhost:4000/_';
// 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 remembered = {};
function rememberViaValidator(name) {
var oldValidator = init.prompts[name].validator || function (line) {
return true;
};
var newValidator;
switch (oldValidator.length) { //apply would not work, .length is used to call it differently
case 1:
newValidator = function (line) {
remembered[name] = line;
return oldValidator.call(this, line);
};
break;
case 2:
newValidator = function (line, next) {
remembered[name] = line;
return oldValidator.call(this, line, next);
};
break;
default:
throw new Error("Panic: " + oldValidator.length + "-argument validator for " + name + ".");
}
init.prompts[name].validator = newValidator;
}
function capitalize(string) {
return string[0].toUpperCase() + string.slice(1).toLowerCase();
}
init.prompts.name.message = 'Main class and package of Amber application.\nProject name is derived by lowercasing this.';
init.prompts.name.validator = function (line) {
return /^[A-Z][A-Za-z0-9]*$/.test(line)
};
init.prompts.name.warning = 'Must be a valid class name: only alphanumeric and starting with an uppercase letter!';
rememberViaValidator('name');
rememberViaValidator('title');
init.process({type: 'amber'}, [
// Prompt for these values.
init.prompt('title', 'Application or Library Title'),
init.prompt('name', function (value, data, done) {
var words = remembered.title.split(/\W/);
words = words.filter(function (x) {
return x && x !== "none";
}).map(capitalize);
value = words.length ? words.join('') : 'MysteriousApp';
done(null, value);
}),
init.prompt('description', 'The Application or The Library doing The Thing.'),
init.prompt('author_name'),
init.prompt('author_email'),
{
name: 'namespace',
message: 'Namespace of the new Amber package.',
altDefault: function (value, data, done) {
value = 'amber-' + remembered.name.toLowerCase();
done(null, value);
},
validator: /^[a-z][a-z0-9/\-]*$/,
warning: 'Only lowercase letters, numbers, and - are allowed in namespaces!'
},
init.prompt('version'),
init.prompt('repository'),
init.prompt('homepage'),
init.prompt('bugs'),
init.prompt('author_url'),
init.prompt('licenses', 'MIT')
], function (err, props) {
// Files to copy (and process).
var files = init.filesToCopy(props);
// Add properly-named license files.
init.addLicenseFiles(files, props.licenses);
// Actually copy (and process) files.
init.copyAndProcess(files, props, {noProcess: 'libs/**'});
// Clean up non-npm props.
delete props.namespace;
props.name = props.name.toLowerCase();
// A few additional properties.
props.keywords = ['Amber', 'Smalltalk'];
props.devDependencies = {
"amber-dev": "^0.8.2",
"grunt": "^0.4.5",
"grunt-contrib-clean": "^0.7.0",
"grunt-contrib-requirejs": "^0.4.4",
"grunt-execute": "^0.2.2",
"requirejs": "^2.1.15"
};
props.node_version = '0.10.x || 0.12.x || >=4.0.0';
props.scripts = {
"test": "grunt test"
};
// Generate package.json file, used by npm and grunt.
init.writePackageJSON('package.json', props);
// generate bower.json file
grunt.file.write('bower.json', JSON.stringify({
"name": props.name,
"description": props.description,
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"/*.js",
"/*.html",
"test",
"tests"
],
"authors": [
{
"name": props.author_name,
"email": props.author_email
}
],
"homepage": props.homepage,
"main": props.main,
"keywords": props.keywords,
"license": props.licenses,
"private": false,
"dependencies": {
"amber": "^0.15.0",
"amber-compat-es2015": "^0.1.0",
"amber-contrib-jquery": "^0.2.0",
"amber-contrib-web": "^0.3.0",
"domite": "^0.4.0",
"silk": "^0.2.0"
},
"devDependencies": {
"amber-contrib-legacy": "^0.3.0",
"amber-ide-starter-dialog": "^0.1.0",
"helios": "^0.6.0"
}
}, null, 4));
// All done!
done();
});
};