Skip to content

Commit d8471c6

Browse files
committed
Fix issues in yeoman
Don't include version in folder name Install package with Yarn (in the background) Show friendly error message if package doesn't exist Fix path issues when picking existing path
1 parent 25f5a5b commit d8471c6

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

_new/index.js

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,34 @@ module.exports = class extends Generator {
2323
type: 'input',
2424
name: 'libraryName',
2525
message: "What is the npm module's name?",
26+
validate: (libraryName, answers) => {
27+
this.spawnCommand('yarn', ['add', libraryName], {
28+
stdio: 'ignore',
29+
});
30+
31+
return packageJson(libraryName, {
32+
fullMetadata: true,
33+
})
34+
.then(pkg => {
35+
answers.pkg = pkg;
36+
if (pkg.repository && pkg.repository.url) {
37+
answers.githubUrl = pkg.repository.url
38+
.replace(/^git(?:\+https?)?:/, 'https:')
39+
.replace(/\.git$/, '');
40+
}
41+
})
42+
.then(
43+
() => true,
44+
err =>
45+
`There was an error retrieving metadata for npm package ${libraryName} \n ${err}`
46+
);
47+
},
2648
},
2749
{
2850
type: 'input',
2951
name: 'friendlyName',
3052
message: "What is the library's friendly name?",
31-
default: answers =>
32-
packageJson(answers.libraryName, {
33-
fullMetadata: true,
34-
}).then(pkg => {
35-
answers.pkg = pkg;
36-
if (pkg.repository && pkg.repository.url) {
37-
answers.githubUrl = pkg.repository.url
38-
.replace(/^git(?:\+https?)?:/, 'https:')
39-
.replace(/\.git$/, '');
40-
}
41-
42-
return pkg.name;
43-
}),
53+
default: answers => answers.pkg.name,
4454
},
4555
{
4656
type: 'input',
@@ -91,13 +101,17 @@ module.exports = class extends Generator {
91101
)
92102
)
93103
.map(path.normalize)
104+
.map(file => file.replace(/\\/g, '/'))
94105
.concat([new inquirer.Separator(), 'Other']);
95106
} catch (e) {
96107
console.error(e);
97108
}
98109
},
99110
default: answers =>
100-
path.normalize(answers.pkg.browser || answers.pkg.main),
111+
path
112+
.normalize(answers.pkg.browser || answers.pkg.main)
113+
.replace(/\\/g, '/'),
114+
filter: libraryPath => libraryPath.replace(/\\/g, '/'),
101115
},
102116
{
103117
type: 'input',
@@ -131,7 +145,7 @@ module.exports = class extends Generator {
131145
}
132146

133147
writing() {
134-
const folder = `${this.props.libraryName}_${this.props.version}`;
148+
const folder = this.props.libraryName;
135149
this.fs.copyTpl(
136150
this.templatePath('{libraryName}.dnn'),
137151
this.destinationPath(`${folder}/${this.props.libraryName}.dnn`),

_new/templates/{libraryName}.dnn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<fileName><%=fileName%></fileName>
2323
<preferredScriptLocation><%=preferredScriptLocation%></preferredScriptLocation>
2424
<objectName><%=objectName%></objectName>
25-
<cdnUrl>https://cdn.jsdelivr.net/npm/<%=libraryName%>@<~=version~><%=relativePath%></cdnUrl>
25+
<cdnUrl>https://cdn.jsdelivr.net/npm/<%=libraryName%>@<~=version~>/<%=relativePath%></cdnUrl>
2626
</javaScriptLibrary>
2727
</component>
2828
<component type="JavaScriptFile">

0 commit comments

Comments
 (0)