-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
145 lines (111 loc) · 3.4 KB
/
index.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
/**
* This is a "partial" sub-generator that generates a very basic and generic
* `package.json` file for the project.
*
* @partial
* @promptsFor projectName, projectDesc, projectVersion, fullName
* @promptsFor emailAddress, githubOwner, gitRepoName
* @example
* $ yo luke:package
*
* @author Luke Chavers <[email protected]>
* @created 2016-12-14
*/
var yeoman = require( "yeoman-generator" );
var baseGenerator = require( "../_BaseGenerator" );
var _ = require( "lodash" );
module.exports = baseGenerator.extend(
{
prompting : function() {
// Locals
var me = this;
// Initialize the base generator
me._initBase();
// Show user prompts
me._showPrompts(
// Prompts from the base generator
[ "projectName", "projectDesc", "projectVersion", "fullName", "emailAddress", "githubOwner", "gitRepoName" ],
// Additional, custom, prompts
[],
// Callback function
me.async()
);
},
// Note: This generator intentionally uses the "conflicts" priority,
// instead of the typical "writing" priority, so that it is executed
// and its files are created AFTER all or most of the others, since
// generators executed along side this one may need to influence the
// package.json content.
// - See: http://yeoman.io/authoring/running-context.html
conflicts : {
createPartialFiles : function() {
var me = this;
var licenseString = "UNLICENSED";
var dependencyMapping = [
{
objectType: "npm-dependency",
packageProperty: "dependencies"
},{
objectType: "npm-dev-dependency",
packageProperty: "devDependencies"
}
];
// Determine License
if( me._isIncluded("luke:mit-license") ) {
licenseString = "MIT";
}
// Build package.json
var pkg = {
name : me.props.parsedProject,
version : me.props.projectVersion,
description : me.props.projectDesc,
main : "lib/index.js",
license : licenseString,
repository : "https://github.com/" + me.props.parsedGitHubOwner + "/" + me.props.parsedRepoName,
author : {
name : me.props.fullName,
email : me.props.emailAddress,
url : ""
},
contributors : [
{
name : me.props.fullName,
email : me.props.emailAddress,
url : ""
}
],
publishConfig : {
registry : "https://registry.npmjs.org/"
},
keywords : []
};
// Check to see if this composition includes "scripts"
if( me._isIncluded("luke:scripts") ) {
// Iterate over each NPM script meta-object
_.each( me._getSharedObjects("script"), function( obj ) {
var cfg = obj.config;
if( pkg.scripts === undefined ) {
pkg.scripts = {};
}
pkg.scripts[ cfg.name ] = "./" + cfg.dest;
});
}
// Handle deps and dev-deps
_.each( dependencyMapping, function( depInfo ) {
var objType = depInfo.objectType;
var pkgProp = depInfo.packageProperty;
// Iterate over each NPM dependency meta-object
_.each( me._getSharedObjects( objType ), function( obj ) {
var cfg = obj.config;
if( pkg[ pkgProp ] === undefined ) {
pkg[ pkgProp ] = {};
}
pkg[ pkgProp ][ cfg.module ] = cfg.version;
});
});
/** @creates generated:package.json **/
me.fs.writeJSON( me.destinationPath( "package.json" ), pkg, null, "\t" );
}
}
}
);