Skip to content

Commit 1a4b919

Browse files
committed
Add yeoman template for new libraries
1 parent 25283b5 commit 1a4b919

File tree

10 files changed

+2443
-91
lines changed

10 files changed

+2443
-91
lines changed

_new/index.js

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/* eslint-env node*/
2+
'use strict';
3+
const path = require('path');
4+
const Generator = require('yeoman-generator');
5+
const chalk = require('chalk');
6+
const yosay = require('yosay');
7+
const inquirer = require('inquirer');
8+
const packageJson = require('package-json');
9+
const globby = require('globby');
10+
11+
module.exports = class extends Generator {
12+
prompting() {
13+
// Have Yeoman greet the user.
14+
this.log(
15+
yosay(
16+
chalk`Welcome to the superb {red DNN JavaScript Library} generator!`
17+
)
18+
);
19+
20+
const prompts = [
21+
{
22+
type: 'input',
23+
name: 'libraryName',
24+
message: "What is the npm module's name?",
25+
},
26+
{
27+
type: 'input',
28+
name: 'friendlyName',
29+
message: "What is the library's friendly name?",
30+
default: answers =>
31+
packageJson(answers.libraryName, {
32+
fullMetadata: true,
33+
}).then(pkg => {
34+
answers.pkg = pkg;
35+
if (pkg.repository && pkg.repository.url) {
36+
answers.githubUrl = pkg.repository.url
37+
.replace(/^git(?:\+https?)?:/, 'https:')
38+
.replace(/\.git$/, '');
39+
}
40+
41+
return pkg.name;
42+
}),
43+
},
44+
{
45+
type: 'input',
46+
name: 'licenseUrl',
47+
message: "What is the URL to the library's license?",
48+
default: answers =>
49+
answers.githubUrl
50+
? `${answers.githubUrl}/blob/LICENSE`
51+
: answers.homepage,
52+
},
53+
{
54+
type: 'input',
55+
name: 'licenseName',
56+
message: 'What is the name of the license?',
57+
default: answers => answers.pkg.license,
58+
},
59+
{
60+
type: 'input',
61+
name: 'changelogUrl',
62+
message: "What is the URL to the library's changelog?",
63+
default: answers =>
64+
answers.githubUrl
65+
? `${answers.githubUrl}/releases`
66+
: answers.homepage,
67+
},
68+
{
69+
type: 'input',
70+
name: 'description',
71+
message: "What is the library's description?",
72+
default: answers => answers.pkg.description,
73+
},
74+
{
75+
type: 'list',
76+
name: 'relativePath',
77+
message: 'What is the main JavaScript file?',
78+
choices: answers => {
79+
console.log(
80+
'choices',
81+
`node_modules/${answers.libraryName}/**/*.js`
82+
);
83+
try {
84+
return globby
85+
.sync(`node_modules/${answers.libraryName}/**/*.js`)
86+
.map(file =>
87+
file.replace(
88+
`node_modules/${answers.libraryName}/`,
89+
''
90+
)
91+
)
92+
.map(path.normalize)
93+
.concat([new inquirer.Separator(), 'Other']);
94+
} catch (e) {
95+
console.error(e);
96+
}
97+
},
98+
default: answers =>
99+
path.normalize(answers.pkg.browser || answers.pkg.main),
100+
},
101+
{
102+
type: 'input',
103+
name: 'relativePath',
104+
message: 'What is the main JavaScript file?',
105+
when: answers => answers.relativePath === 'Other',
106+
},
107+
{
108+
type: 'list',
109+
name: 'preferredScriptLocation',
110+
message:
111+
'What is the preferred script location for the library?',
112+
choices: ['PageHead', 'BodyTop', 'BodyBottom'],
113+
default: 'BodyBottom',
114+
},
115+
{
116+
type: 'input',
117+
name: 'objectName',
118+
message:
119+
'What JavaScript object will be defined if the script loaded correctly?',
120+
},
121+
];
122+
123+
return this.prompt(prompts).then(props => {
124+
// To access props later use this.props.someAnswer;
125+
this.props = props;
126+
this.props.fileName = path.basename(props.relativePath);
127+
this.props.version = props.pkg.version;
128+
this.props.versionFolder = props.pkg.version
129+
.split('.')
130+
.map(n => n.padStart(2, '0'))
131+
.join('_');
132+
});
133+
}
134+
135+
writing() {
136+
const folder = `${this.props.libraryName}_${this.props.version}`;
137+
this.fs.copyTpl(
138+
this.templatePath('{libraryName}.dnn'),
139+
this.destinationPath(`${folder}/${this.props.libraryName}.dnn`),
140+
this.props
141+
);
142+
this.fs.copyTpl(
143+
this.templatePath('CHANGES.htm'),
144+
this.destinationPath(`${folder}/CHANGES.htm`),
145+
this.props
146+
);
147+
this.fs.copyTpl(
148+
this.templatePath('dnn-library.json'),
149+
this.destinationPath(`${folder}/dnn-library.json`),
150+
this.props
151+
);
152+
this.fs.copyTpl(
153+
this.templatePath('LICENSE.htm'),
154+
this.destinationPath(`${folder}/LICENSE.htm`),
155+
this.props
156+
);
157+
}
158+
};

_new/templates/CHANGES.htm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<p>See the
2+
<a href="<%=changelogUrl%>">
3+
<%=friendlyName%> changelog</a>
4+
</p>

_new/templates/LICENSE.htm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<p>
2+
<%=friendlyName%> is licensed under the
3+
<a href="<%=licenseUrl%>">
4+
<%=licenseName%> license</a>.</p>

_new/templates/dnn-library.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"files": ["node_modules/<%-libraryName%>/<%-relativePath%>"],
3+
"resources": []
4+
}

_new/templates/{libraryName}.dnn

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<dotnetnuke type="Package" version="5.0">
2+
<packages>
3+
<package name="<%=libraryName%>" type="JavaScript_Library" version="<%=version%>">
4+
<friendlyName><%=friendlyName%>
5+
</friendlyName>
6+
<description>
7+
<![CDATA[<%-description%>]]>
8+
</description>
9+
<owner>
10+
<name>Engage Software</name>
11+
<organization>Engage Software</organization>
12+
<url>https://engagesoftware.com/</url>
13+
<email>support@engagesoftware.com</email>
14+
</owner>
15+
<license src="LICENSE.htm" />
16+
<releaseNotes src="CHANGES.htm" />
17+
<azureCompatible>true</azureCompatible>
18+
<dependencies></dependencies>
19+
<components>
20+
<component type="JavaScript_Library">
21+
<javaScriptLibrary>
22+
<libraryName><%=libraryName%>
23+
</libraryName>
24+
<fileName><%=fileName%>
25+
</fileName>
26+
<preferredScriptLocation><%=preferredScriptLocation%>
27+
</preferredScriptLocation>
28+
<objectName><%=objectName%>
29+
</objectName>
30+
<cdnUrl>https://cdn.jsdelivr.net/npm/<%=libraryName%>@<%=version%><%=relativePath%>
31+
</cdnUrl>
32+
</javaScriptLibrary>
33+
</component>
34+
<component type="JavaScriptFile">
35+
<jsfiles>
36+
<libraryFolderName><%=libraryName%>
37+
</libraryFolderName>
38+
<jsfile>
39+
<name><%=fileName%>
40+
</name>
41+
</jsfile>
42+
</jsfiles>
43+
</component>
44+
<component type="ResourceFile">
45+
<resourceFiles>
46+
<basePath>Resources\Libraries\<%=libraryName%>\<%=versionFolder%>
47+
</basePath>
48+
<resourceFile>
49+
<name>Resources.zip</name>
50+
</resourceFile>
51+
</resourceFiles>
52+
</component>
53+
</components>
54+
</package>
55+
</packages>
56+
</dotnetnuke>

_template/CHANGES.htm

Lines changed: 0 additions & 1 deletion
This file was deleted.

_template/LICENSE.htm

Lines changed: 0 additions & 1 deletion
This file was deleted.

_template/library.dnn

Lines changed: 0 additions & 41 deletions
This file was deleted.

package.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
"name": "engage-dnn-javascript-libraries",
33
"version": "0.10.0",
44
"private": true,
5-
"file": ["_InstallPackages"],
5+
"file": [
6+
"_InstallPackages"
7+
],
68
"scripts": {
7-
"package": "gulp"
9+
"package": "gulp",
10+
"new": "yo ./_new"
811
},
912
"dependencies": {
1013
"alpaca": "1.5.23",
@@ -68,9 +71,14 @@
6871
"zeroclipboard": "2.3.0"
6972
},
7073
"devDependencies": {
74+
"chalk": "2.3.0",
7175
"glob": "^7.1.2",
76+
"globby": "7.1.1",
7277
"gulp": "^3.9.1",
7378
"gulp-zip": "^4.0.0",
74-
"merge-stream": "^1.0.1"
79+
"merge-stream": "^1.0.1",
80+
"package-json": "4.0.1",
81+
"yeoman-generator": "2.0.2",
82+
"yo": "2.0.1"
7583
}
7684
}

0 commit comments

Comments
 (0)