Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Feature/20 fix GitHub link evaluation #22

Merged
merged 2 commits into from
Jul 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions app/src/components/AboutView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@
</div>
<div class="u-marginBottom">
<h1 class="o-headline-2">Forrest</h1>
<p class="o-paragraph u-marginTopSmall">Brought to you by <button class="o-linkBtn" type="button" v-open-external :url="'https://twitter.com/stefanjudis'">Stefan Judis</button></p>
<p class="o-paragraph u-marginTopSmall">Brought to you by <button class="o-linkBtn" type="button" v-open-external="'https://twitter.com/stefanjudis'">Stefan Judis</button></p>

<p class="o-paragraph">Check out the project on <button class="o-linkBtn" type="button" v-open-external :url="'https://github.com/stefanjudis/forrest'">GitHub</button>.</p>
<p class="o-paragraph">Check out the project on <button class="o-linkBtn" type="button" v-open-external="'https://github.com/stefanjudis/forrest'">GitHub</button>.</p>
</div>

<h2 class="o-headline-3 u-marginBottomSmall">Shout out to these projects/people:</h2>
Expand All @@ -107,7 +107,7 @@
<li class="c-about--heartList--item">
<h3 class="o-headline-4 u-flexCenter">
<span>Evan You</span>
<button class="o-icon" type="button" v-open-external :url="'https://twitter.com/youyuxi'">
<button class="o-icon" type="button" v-open-external="'https://twitter.com/youyuxi'">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
<path d="M72.955 17.969l-22.41 22.41c5.637 11.592 3.65 25.958-5.978 35.585-9.45 9.451-23.469 11.543-34.946 6.285 17.658 17.15 45.87 17.003 63.333-.461 17.625-17.623 17.625-46.196.001-63.819z"/>
<path d="M58.281 47.966c-12.855 3.768-26.293-3.047-31.006-15.339-7.596 6.311-11.149 16.751-8.194 26.831 3.966 13.531 18.151 21.284 31.682 17.317 13.53-3.967 21.284-18.15 17.317-31.682a25.574 25.574 0 0 0-.675-1.979 25.458 25.458 0 0 1-9.124 4.852z"/>
Expand All @@ -117,11 +117,11 @@
</svg>
</button>
</h3>
<p>for creation and maintenance of <button class="o-linkBtn" type="button" v-open-external :url="'https://vuejs.org/'">vue.js</button></p>
<p>for creation and maintenance of <button class="o-linkBtn" type="button" v-open-external="'https://vuejs.org/'">vue.js</button></p>
<li class="c-about--heartList--item">
<h3 class="o-headline-4 u-flexCenter">
<span>Greg Holguin</span>
<button class="o-icon" type="button" v-open-external :url="'https://twitter.com/simulatedgreg'">
<button class="o-icon" type="button" v-open-external="'https://twitter.com/simulatedgreg'">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
<path d="M72.955 17.969l-22.41 22.41c5.637 11.592 3.65 25.958-5.978 35.585-9.45 9.451-23.469 11.543-34.946 6.285 17.658 17.15 45.87 17.003 63.333-.461 17.625-17.623 17.625-46.196.001-63.819z"/>
<path d="M58.281 47.966c-12.855 3.768-26.293-3.047-31.006-15.339-7.596 6.311-11.149 16.751-8.194 26.831 3.966 13.531 18.151 21.284 31.682 17.317 13.53-3.967 21.284-18.15 17.317-31.682a25.574 25.574 0 0 0-.675-1.979 25.458 25.458 0 0 1-9.124 4.852z"/>
Expand All @@ -131,11 +131,11 @@
</svg>
</button>
</h3>
<p>for creation of the <button class="o-linkBtn" type="button" v-open-external :url="'https://github.com/SimulatedGREG/electron-vue'">electron vue boilerplate</button></p>
<p>for creation of the <button class="o-linkBtn" type="button" v-open-external="'https://github.com/SimulatedGREG/electron-vue'">electron vue boilerplate</button></p>
<li class="c-about--heartList--item">
<h3 class="o-headline-4 u-flexCenter">
<span>Sindre Sorhus</span>
<button class="o-icon" type="button" v-open-external :url="'https://twitter.com/sindresorhus'">
<button class="o-icon" type="button" v-open-external="'https://twitter.com/sindresorhus'">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
<path d="M72.955 17.969l-22.41 22.41c5.637 11.592 3.65 25.958-5.978 35.585-9.45 9.451-23.469 11.543-34.946 6.285 17.658 17.15 45.87 17.003 63.333-.461 17.625-17.623 17.625-46.196.001-63.819z"/>
<path d="M58.281 47.966c-12.855 3.768-26.293-3.047-31.006-15.339-7.596 6.311-11.149 16.751-8.194 26.831 3.966 13.531 18.151 21.284 31.682 17.317 13.53-3.967 21.284-18.15 17.317-31.682a25.574 25.574 0 0 0-.675-1.979 25.458 25.458 0 0 1-9.124 4.852z"/>
Expand All @@ -149,7 +149,7 @@
<li class="c-about--heartList--item">
<h3 class="o-headline-4 u-flexCenter">
<span>Michael Kühnel</span>
<button class="o-icon" type="button" v-open-external :url="'https://twitter.com/mkuehnel'">
<button class="o-icon" type="button" v-open-external="'https://twitter.com/mkuehnel'">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
<path d="M72.955 17.969l-22.41 22.41c5.637 11.592 3.65 25.958-5.978 35.585-9.45 9.451-23.469 11.543-34.946 6.285 17.658 17.15 45.87 17.003 63.333-.461 17.625-17.623 17.625-46.196.001-63.819z"/>
<path d="M58.281 47.966c-12.855 3.768-26.293-3.047-31.006-15.339-7.596 6.311-11.149 16.751-8.194 26.831 3.966 13.531 18.151 21.284 31.682 17.317 13.53-3.967 21.284-18.15 17.317-31.682a25.574 25.574 0 0 0-.675-1.979 25.458 25.458 0 0 1-9.124 4.852z"/>
Expand Down
19 changes: 16 additions & 3 deletions app/src/components/RepoListView/KnownRepos.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
<a id="{{ repo.name }}" class="c-project" v-link="{ path : `/repos/${ encodeURIComponent( repo.name ) }` }" @contextmenu="openContextMenu">
<div class="c-project--name">
<span>{{ repo.name }}</span>
<button type="button" v-if="repo.url" v-open-external :url="repo.url" class="o-icon" aria-label="Open project on GitHub" title="Open project on GitHub">
<button type="button" v-if="repo.url" v-open-external="repo.url" class="o-icon" aria-label="Open project on GitHub" title="Open project on GitHub">
<svg x="0px" y="0px" width="438.549px" height="438.549px" viewBox="0 0 438.549 438.549">
<g>
<path d="M409.132,114.573c-19.608-33.596-46.205-60.194-79.798-79.8C295.736,15.166,259.057,5.365,219.271,5.365
Expand Down Expand Up @@ -140,7 +140,7 @@

<script>
import { getRepos } from '../../vuex/getters';
import { removeRepo } from '../../vuex/actions';
import { removeRepo, reloadRepo } from '../../vuex/actions';
import { getParentWithClass } from '../../modules/DomUtils';

export default {
Expand Down Expand Up @@ -182,6 +182,18 @@
);
}
},
{
label : 'Reload project meta',
click : () => {
let repoToReload = this.repos.find(
repo => repo.name === repoElement.id
);

if ( repoToReload ) {
this.reloadRepo( repoToReload );
}
}
},
{
type : 'separator'
},
Expand Down Expand Up @@ -239,7 +251,8 @@

vuex : {
actions : {
removeRepo : removeRepo
removeRepo,
reloadRepo
},
getters : {
repos : getRepos
Expand Down
2 changes: 1 addition & 1 deletion app/src/components/RepoView/Command.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
{{ script.name }}
</div>
<div class="c-script--actions">
<button type="button" class="o-icon" v-if="script.docs" v-open-external :url="script.docs">
<button type="button" class="o-icon" v-if="script.docs" v-open-external="script.docs">
<svg height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M0 0h24v24H0z" fill="none"/>
<path d="M19 4H5c-1.11 0-2 .9-2 2v12c0 1.1.89 2 2 2h4v-2H5V8h14v10h-4v2h4c1.1 0 2-.9 2-2V6c0-1.1-.89-2-2-2zm-7 6l-4 4h3v6h2v-6h3l-4-4z"/>
Expand Down
2 changes: 1 addition & 1 deletion app/src/components/RepoView/Repo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
<div class="c-project--noScriptsMsg">
<div>
<p class="o-paragraph">There are no custom scripts defined in your package.json.</p>
<p class="o-paragraph u-noMarginBottom">If you rely on installed globals, <button type="button" class="o-linkBtn" v-open-external :url="'http://4waisenkinder.de/blog/2014/10/18/npm-2-dot-0-and-the-much-better-star-npm-run-star-command/'">you might wanna change that</button>.</p>
<p class="o-paragraph u-noMarginBottom">If you rely on installed globals, <button type="button" class="o-linkBtn" v-open-external="'http://4waisenkinder.de/blog/2014/10/18/npm-2-dot-0-and-the-much-better-star-npm-run-star-command/'">you might wanna change that</button>.</p>
</div>
<svg height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M0 0h24v24H0z" fill="none"/>
Expand Down
13 changes: 8 additions & 5 deletions app/src/directives/OpenExternal.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
<script>
export default {
bind() {
update( value ) {
if ( this.handler ) {
this.el.removeEventListener( 'click', this.handler );
}

let openExternal = this.vm.$electron.shell.openExternal;
let url = this.params.url;

this.handler = ( event ) => {
openExternal( url );
openExternal( value );

event.preventDefault();
};

this.el.addEventListener( 'click', this.handler );
},

unbind() {
this.el.removeEventListener( 'click', this.handler );
},
params : [ 'url' ]
}
};
</script>
59 changes: 59 additions & 0 deletions app/src/modules/RepoUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { remote } from 'electron';

const fs = remote.require( 'fs' );

/**
* Evaluate repo url from a read package data
*
* @param {Object} repoData
*
* @returns {null|Object}
*/
function getRepoUrl( repoData ) {
let { repository : repo } = repoData;

if ( repo ) {
if ( repo.url ) {
return repo.url.replace( /(git:\/\/|\.git)/g, '' );
}

if ( /^.*?\/.*?$/.test( repo ) ) {
return `https://github.com/${ repo }`;
}
}

return null;
}


/**
* Read repo data
*
* @param {String} repo path
*
* @returns {Promise}
*/
export const readRepoData = function( repoPath ) {
return new Promise( ( resolve, reject ) => {
fs.readFile( `${ repoPath }/package.json`, ( error, data ) => {
if ( error ) {
return reject( error );
}

try {
var packageJSON = JSON.parse( data );
} catch( error ) {
return reject( error );
}

let repo = {
path : repoPath,
name : packageJSON.name,
description : packageJSON.description,
url : getRepoUrl( packageJSON )
};

resolve( repo );
} );
} );
};
54 changes: 27 additions & 27 deletions app/src/vuex/actions.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
import { remote } from 'electron';

const fs = remote.require( 'fs' );
import { readRepoData } from '../modules/RepoUtils';

export const addRepoWithPath = function( { dispatch, state }, repoPath ) {
fs.readFile( `${ repoPath }/package.json`, ( error, data ) => {
// TODO put error handling here

try {
var packageJSON = JSON.parse( data );
} catch( error ) {
// TODO error handling
}

if ( ! state.repos.all.some( repo => repo.path === repoPath ) ) {
let url = packageJSON.repository &&
packageJSON.repository.url &&
packageJSON.repository.url.replace( /(git:\/\/|\.git)/g, '' );

let repo = {
path : repoPath,
name : packageJSON.name,
description : packageJSON.description,
url : url
};
let repoIsAlreadyAdded = state.repos.all.some( repo => repo.path === repoPath );

if ( ! repoIsAlreadyAdded ) {
readRepoData( repoPath )
.then( repo => {
dispatch( 'ADD_REPO', repo );
} )
.catch( () => {
// TODO put error handling here
} );
} else {
new Notification(
'Project is already in the list',
{
body : `-> ${ repoPath }`
}
);
}
};

dispatch( 'ADD_REPO', repo );
} else {
export const reloadRepo = function( { dispatch, state }, repo ) {
readRepoData( repo.path )
.then( repo => {
dispatch( 'RELOAD_REPO', repo );
} )
.catch( () => {
// TODO put error handling here
}
} );
} );
};

export const removeRepo = function( { dispatch, state }, repo ) {
Expand Down
15 changes: 15 additions & 0 deletions app/src/vuex/modules/repos.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ const mutations = {
ipcRenderer.send( 'updatedRepos', JSON.stringify( state.all ) );
},

RELOAD_REPO ( state, repo ) {
state.all = state.all.reduce( ( all, savedRepo ) => {
if ( savedRepo.path === repo.path ) {
all.push( repo );
} else {
all.push( savedRepo );
}

return all;
}, [] );

settings.set( 'repos', state.all );
ipcRenderer.send( 'updatedRepos', JSON.stringify( state.all ) );
},

REMOVE_REPO_WITH_INDEX ( state, repoIndex ) {
state.all = state.all.filter( ( repo, index ) => index !== repoIndex );

Expand Down