Skip to content

Commit 781a3dd

Browse files
authored
Merge pull request #114 from spencer516/update-demo-url
Add `homepage` to add-on config in default blueprint
2 parents e0dd05a + bea26ad commit 781a3dd

File tree

18 files changed

+217
-3
lines changed

18 files changed

+217
-3
lines changed

blueprints/ember-cli-addon-docs/index.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use strict';
22

33
const fs = require('fs-extra');
4+
const path = require('path');
5+
const updateDemoUrl = require('../../lib/utils/update-demo-url');
46

57
module.exports = {
68
name: 'ember-cli-addon-docs',
@@ -39,7 +41,7 @@ module.exports = {
3941
}
4042

4143
fs.writeFileSync(configPath, configContents, 'utf-8');
42-
44+
4345
if (fs.existsSync('.npmignore')) {
4446
this.insertIntoFile('.npmignore', '/config/addon-docs.js');
4547
}
@@ -50,10 +52,20 @@ module.exports = {
5052
return isPlugin || isPluginPack;
5153
});
5254

55+
const packageJsonPath = path.join(this.project.root, 'package.json');
56+
const updatedDemoUrl = updateDemoUrl(packageJsonPath);
57+
58+
if (!updatedDemoUrl) {
59+
this.ui.writeWarnLine(
60+
`Unable to update the "homepage" configuration in your package.json. To include this for ` +
61+
`including a link on Ember Observer, set it to https://{ORGANIZATION}.github.io/{REPO}`
62+
);
63+
}
64+
5365
if (!hasPlugins) {
5466
return this.addAddonsToProject({
5567
packages: ['ember-cli-addon-docs-yuidoc']
56-
})
68+
});
5769
}
5870
}
5971
};

lib/utils/update-demo-url.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use strict';
2+
3+
const fs = require('fs-extra');
4+
const hostedGitInfo = require('hosted-git-info');
5+
const parseGitConfig = require('parse-git-config');
6+
7+
function gitConfigUrl(configPath) {
8+
const options = configPath ? { path: configPath } : {};
9+
const config = parseGitConfig.sync(options);
10+
const originProp = Object.keys(config).find(key => /^remote/.test(key));
11+
12+
return originProp ? config[originProp].url : '';
13+
}
14+
15+
function repoFromPackage(packageJson) {
16+
const repo = packageJson.repository;
17+
return typeof repo === 'object' ? repo.url : repo;
18+
}
19+
20+
module.exports = function updateDemoUrl(packageJsonPath, gitConfigPath) {
21+
const packageJson = fs.readJsonSync(packageJsonPath);
22+
23+
// https://docs.npmjs.com/files/package.json#homepage
24+
if (packageJson.homepage) {
25+
return true;
26+
}
27+
28+
const repo = repoFromPackage(packageJson) || gitConfigUrl(gitConfigPath);
29+
const gitInfo = hostedGitInfo.fromUrl(repo);
30+
31+
if (gitInfo) {
32+
packageJson.homepage = `https://${gitInfo.user}.github.io/${gitInfo.project}`;
33+
34+
fs.writeJSONSync(packageJsonPath, packageJson, {
35+
spaces: 2
36+
});
37+
38+
return true;
39+
} else {
40+
return false;
41+
}
42+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"lodash": "^4.17.5",
6262
"lunr": "^2.1.5",
6363
"marked": "^0.3.12",
64+
"parse-git-config": "^1.1.1",
6465
"quick-temp": "^0.1.8",
6566
"resolve": "^1.5.0",
6667
"semver": "^5.5.0",
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"repository": "https://github.com/ember-learn/ember-cli-addon-docs",
3+
"homepage": "https://www.somewhere-else.com"
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"repository": "https://github.com/ember-learn/ember-cli-addon-docs",
3+
"homepage": "https://www.somewhere-else.com"
4+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"repository": {
3+
"url": "https://github.com/ember-learn/ember-cli-addon-docs"
4+
}
5+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"repository": {
3+
"url": "https://github.com/ember-learn/ember-cli-addon-docs"
4+
},
5+
"homepage": "https://ember-learn.github.io/ember-cli-addon-docs"
6+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[remote "origin"]
2+
url = [email protected]:ember-learn/ember-cli-addon-docs.git
3+
fetch = +refs/heads/*:refs/remotes/origin/*
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"homepage": "https://ember-learn.github.io/ember-cli-addon-docs"
3+
}

0 commit comments

Comments
 (0)