Skip to content

Commit

Permalink
fix(fusumarc): decide repositoryUrl automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroppy committed Jun 22, 2019
1 parent 7e03faa commit 175b966
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 47 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ meta:
description: Explain how specifications are determined and how it will be in the future.
thumbnail: https://avatars1.githubusercontent.com/u/1725583?v=4&s=200
siteName: slides.hiroppy.me
repositoryUrl: https://github.com/hiroppy/fusuma
sns:
- twitter
- hatena
Expand Down Expand Up @@ -204,8 +203,7 @@ module.exports = {
description: 'test',
thumbnail: 'url',
siteName: 'siteName',
sns: ['twitter', 'hatena'],
repositoryUrl: 'https://github.com/hiroppy/fusuma'
sns: ['twitter', 'hatena']
},
slide: {
loop: true,
Expand Down
1 change: 0 additions & 1 deletion packages/configs/src/fusumarc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const config = {
meta: {
url: null,
name: null,
author: null,
thumbnail: null,
description: null,
sns: ['twitter'] // twitter, hatena
Expand Down
4 changes: 2 additions & 2 deletions packages/fusuma/src/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async function initProcess({ schema }) {
async function startProcess(basePath) {
const spinner = loader('Starting with webpack-dev-server...').start();
const config = await fusuma.read(basePath);
const remoteOrigin = await getRemoteOriginUrl(basePath);
const remoteOrigin = await getRemoteOriginUrl();

start(
{
Expand All @@ -36,7 +36,7 @@ async function startProcess(basePath) {
async function buildProcess(basePath, extendedConfig = {}, isOutput = true) {
const spinner = loader('Building with webpack...').start();
const config = merge(await fusuma.read(basePath), extendedConfig);
const remoteOrigin = await getRemoteOriginUrl(basePath);
const remoteOrigin = await getRemoteOriginUrl();

await deleteDir(join(basePath, 'dist'));
await build(
Expand Down
38 changes: 16 additions & 22 deletions packages/utils/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"homepage": "https://github.com/hiroppy/fusuma#readme",
"dependencies": {
"child-process-promise": "^2.2.1",
"remote-origin-url": "2.0.0",
"git-remote-origin-url": "^3.0.0",
"rmfr": "2.0.0"
}
}
27 changes: 13 additions & 14 deletions packages/utils/src/getRemoteOriginUrl.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
'use strict';

const remoteOriginUrl = require('remote-origin-url');
const gitRemoteOriginUrl = require('git-remote-origin-url');

function getRemoteOriginUrl(basePath) {
return new Promise((resolve) => {
remoteOriginUrl(`${basePath}/.git/config`, (err, url) => {
if (err) {
console.error('Could not find github url');
resolve('');
} else {
url = url || '';
async function getRemoteOriginUrl() {
try {
let url = await gitRemoteOriginUrl();

if (url.includes('git@')) resolve(`https://github.com/${url.split(':')[1]}`);
else resolve(url);
}
});
});
if (url.includes('git@')) {
url = `https://github.com/${url.split(':')[1]}`;
}

return url;
} catch (e) {
console.error(e);
return '';
}
}

module.exports = getRemoteOriginUrl;
5 changes: 3 additions & 2 deletions packages/webpack/src/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
const { babel: babelrc } = require('@fusuma/configs');
const css = require('./css');

// set paths in node_modules
const configsEntryPoint = require.resolve('@fusuma/configs');
const configsBasePath = configsEntryPoint.split('/src')[0];
const clientEntryPoint = require.resolve('@fusuma/client');
Expand All @@ -20,7 +21,7 @@ module.exports = ({
internal = {},
server = {}
}) => {
const { url, name, description, thumbnail, siteName, sns, repositoryUrl } = meta;
const { url, name, description, thumbnail, siteName, sns } = meta;
const {
sidebar,
targetBlank = true,
Expand Down Expand Up @@ -105,7 +106,7 @@ module.exports = ({
'process.env.SIDEBAR': JSON.stringify(sidebar === undefined ? true : sidebar),
'process.env.TITLE': JSON.stringify(name),
'process.env.BASE_PATH': JSON.stringify(basePath),
'process.env.REMOTE_ORIGIN_URL': JSON.stringify(repositoryUrl || remoteOrigin),
'process.env.REMOTE_ORIGIN_URL': JSON.stringify(remoteOrigin),
'process.env.TARGET_BLANK': JSON.stringify(targetBlank),
'process.env.SHOW_INDEX': JSON.stringify(showIndex),
'process.env.IS_VERTICAL': JSON.stringify(isVertical),
Expand Down
1 change: 0 additions & 1 deletion samples/intro/.fusumarc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ meta:
description: Introduce Fusuma
thumbnail: https://avatars0.githubusercontent.com/u/3367801?s=400&v=4
siteName: hiroppy.me
repositoryUrl: https://github.com/hiroppy/fusuma
sns: ['twitter']
slide:
showIndex: true
Expand Down
1 change: 0 additions & 1 deletion samples/issues/.fusumarc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ meta:
description: Introduce Fusuma
thumbnail: https://avatars0.githubusercontent.com/u/3367801?s=400&v=4
siteName: hiroppy.me
repositoryUrl: https://github.com/hiroppy/fusuma
sns: ['twitter']
slide:
showIndex: true
Expand Down

0 comments on commit 175b966

Please sign in to comment.