This repository has been archived by the owner on Feb 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathinit.js
78 lines (74 loc) · 2.48 KB
/
init.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
"use strict";
/**
* Archetype `init` configuration.
*
* See: https://github.com/FormidableLabs/builder-init/blob/master/README.md#archetype-data
* for structuring this configuration file.
*/
module.exports = {
// Destination directory to write files to.
//
// This field is deep merged and added _last_ to the prompts so that archetype
// authors can add `default` values or override the default message. You
// could further override the `validate` function, but we suggest using the
// existing default as it checks the directory does not already exist (which
// is enforced later in code).
destination: {
default: function (data) {
return data.packageName;
}
},
// Prompts are Inquirer question objects.
// https://github.com/SBoudrias/Inquirer.js#question
//
// `builder-init` accepts:
// - an array of question objects (with a `name` property)
// - an object of question objects (keyed by `name`)
//
prompts: {
// See: https://github.com/npm/validate-npm-package-name
packageName: {
message: "Package / GitHub project name (e.g., 'whiz-bang-component')",
validate: function (val) {
return /^([a-z0-9]+\-?)+$/.test(val.trim()) || "Must be lower + dash-cased string";
}
},
packageGitHubOrg: {
message: "GitHub organization name (e.g., 'AcmeCorp')",
validate: function (val) {
return /^([^\s])*$/.test(val) || "Must be GitHub-valid organization username";
}
},
packageDescription: {
message: "Package description"
},
licenseDate: {
message: "License date",
default: (new Date()).getFullYear().toString()
},
licenseOrg: {
message: "License organization (e.g., you or your company)",
default: function (data) {
return data.packageGitHubOrg;
},
validate: function (val) {
return !!val.trim() || "Must enter a license organization";
}
}
},
// Derived fields are asynchronous functions that are given the previous user
// input data of the form: `function (data, cb)`. They callback with:
// `(err, value)`.
derived: {
componentPath: function (data, cb) { cb(null, data.packageName); },
componentName: function (data, cb) {
// PascalCase (with first character capitalized).
var name = data.packageName
.replace(/^\s+|\s+$/g, "")
.replace(/(^|[-_ ])+(.)/g, function (match, first, second) {
return second.toUpperCase();
});
cb(null, name);
}
}
};