Skip to content

Commit

Permalink
fixed issue where spaces in dockerPath were not being escaped
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Kemme committed Jun 15, 2017
1 parent 415c21a commit c26b199
Show file tree
Hide file tree
Showing 4 changed files with 226 additions and 225 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

## Description

Add this addon to Local By Flywheel to see the active and inactive plugins for each site. This addon currently lists active and inactive themes/plugins.
Add this addon to Local By Flywheel to see the active and inactive plugins for each site. This addon currently lists active and inactive themes/plugins. Now completely functional with Local by Flywheel v2.0. This addon will no longer work for Local versions less than 2.0

![local-addon-plugins-themes](https://cloud.githubusercontent.com/assets/3424234/23125040/90227d88-f735-11e6-84e7-f68313ef0e96.gif)

Expand All @@ -26,7 +26,7 @@ Add this addon to Local By Flywheel to see the active and inactive plugins for e
1. Clone this repo: `git clone git@github.com:JRGould/local-addon-plugins-themes.git local-addon-plugins-themes`
2. Run `npm install`
3. Run initial build: `npm run-script build`
4. Link into Local's `addon` directory: `ln -s "$(pwd)" ~/Library/Application Support/Local by Flywheel/addons`
4. Link into Local's `addon` directory: `ln -s "$(pwd)" ~/Library/Application\ Support/Local\ by\ Flywheel/addons`
5. Restart Local and activate addon from Settings > Addons

## Notes for Developers
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
"run-when-changed": "^1.3.0"
},
"engines": {
"local-by-flywheel": "^1.1.0"
"local-by-flywheel": "^2.0.0"
}
}
213 changes: 107 additions & 106 deletions src/SitePluginsInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,37 @@ const path = require('path');

module.exports = function( context ) {

const Component = context.React.Component
const React = context.React
const $ = context.jQuery

return class SitePluginsInfo extends Component {
constructor( props ) {
super( props )
// init class vars
this.state = {
activeContent: null,
const Component = context.React.Component
const React = context.React
const $ = context.jQuery

return class SitePluginsInfo extends Component {
constructor( props ) {
super( props )
// init class vars
this.state = {
activeContent: null,
inactiveContent: null,
content: null
}
}

this.stylesheetPath = path.resolve(__dirname, '../style.css');
}
this.stylesheetPath = path.resolve(__dirname, '../style.css');
}

componentDidMount() {
// set up
componentDidMount() {
// set up
if ( 'running' === this.props.siteStatus ) {
this.getPluginList();
} else {
this.setState( { content: ( <p className="plugins-danger">Machine not running!</p> ) } )
this.setState( { activeContent: null} )
this.setState( { inactiveContent: null} )
}
}
}

componentWillUnmount() {
// tear down
}
componentWillUnmount() {
// tear down
}

getPluginList() {

Expand All @@ -54,126 +54,127 @@ module.exports = function( context ) {
<td className="plugins-table-info"> - </td>
</tr> } )

// get site object using siteID
let site = this.props.sites[ this.props.params.siteID ]

// construct command using bundled docker binary to execute 'wp plugin list' inside container for active plugins
let activeCommand = `${context.environment.dockerPath} exec ${site.container} wp plugin list --status=active --path=/app/public --format=csv --allow-root`

// execute command in docker env and run callback when it returns
childProcess.exec( activeCommand, { env: context.environment.dockerEnv }, (error, stdout, stderr) => {
// Display error message if there's an issue
if (error) {
this.setState( { activeContent:
<tr>
<td className="plugins-table-name">Error retrieving active plugin: <pre>{ stderr }</pre></td>
<td className="plugins-table-info"> - </td>
<td className="plugins-table-info"> - </td>
</tr> } )
} else {
// split list into array
let plugins = stdout.trim().split( "\n" )
plugins.splice(0, 1)

// Only create unordered list if there are plugins to list
if ( plugins.length && plugins[0].length > 1 ) {
this.setState( { activeContent: plugins.map( (item) =>
<tr>
<td className="plugins-table-name" key={ plugins.indexOf(item) }>{ item.trim().split( "," )[0] }</td>
<td className={ item.trim().split( "," )[2] + " plugins-table-info" } >{ item.trim().split( "," )[2] }</td>
<td className="plugins-table-info">{ item.trim().split( "," )[3] }</td>
</tr> ) } )
} else {
this.setState( { activeContent:
<tr>
<td className="plugins-table-name">No active plugins.</td>
<td className="plugins-table-info"> - </td>
<td className="plugins-table-info"> - </td>
</tr> } )
}
}
} );
// get site object using siteID
let site = this.props.sites[ this.props.params.siteID ]

// construct command using bundled docker binary to execute 'wp plugin list' inside container for active plugins
// IMPORTANT can't forget to escape any spaces in dockerPath!
let activeCommand = `${ context.environment.dockerPath.replace(/ /g, "\\ ") } exec ${site.container} wp plugin list --status=active --path=/app/public --format=csv --allow-root`

// execute command in docker env and run callback when it returns
childProcess.exec( activeCommand, { env: context.environment.dockerEnv }, (error, stdout, stderr) => {
// Display error message if there's an issue
if (error) {
this.setState( { activeContent:
<tr>
<td className="plugins-table-name">Error retrieving active plugin: <pre>{ error, stdout, stderr }</pre></td>
<td className="plugins-table-info"> - </td>
<td className="plugins-table-info"> - </td>
</tr> } )
}
else {
// split list into array
let plugins = stdout.trim().split( "\n" )
plugins.splice(0, 1)

// Only create unordered list if there are plugins to list
if ( plugins.length && plugins[0].length > 1 ) {
this.setState( { activeContent: plugins.map( (item) =>
<tr>
<td className="plugins-table-name" key={ plugins.indexOf(item) }>{ item.trim().split( "," )[0] }</td>
<td className={ item.trim().split( "," )[2] + " plugins-table-info" } >{ item.trim().split( "," )[2] }</td>
<td className="plugins-table-info">{ item.trim().split( "," )[3] }</td>
</tr> ) } )
}
else {
this.setState( { activeContent:
<tr>
<td className="plugins-table-name">No active plugins.</td>
<td className="plugins-table-info"> - </td>
<td className="plugins-table-info"> - </td>
</tr> } )
}
}
} );

// construct command using bundled docker binary to execute 'wp plugin list' inside container for inactive plugins
let inactiveCommand = `${context.environment.dockerPath} exec ${site.container} wp plugin list --status=inactive --path=/app/public --format=csv --allow-root`

// execute command in docker env and run callback when it returns
childProcess.exec( inactiveCommand, { env: context.environment.dockerEnv }, (error, stdout, stderr) => {
// Display error message if there's an issue
if (error) {
this.setState( { inactiveContent:
// IMPORTANT can't forget to escape any spaces in dockerPath!
let inactiveCommand = `${ context.environment.dockerPath.replace(/ /g, "\\ ") } exec ${site.container} wp plugin list --status=inactive --path=/app/public --format=csv --allow-root`

// execute command in docker env and run callback when it returns
childProcess.exec( inactiveCommand, { env: context.environment.dockerEnv }, (error, stdout, stderr) => {
// Display error message if there's an issue
if (error) {
this.setState( { inactiveContent:
<tr>
<td className="plugins-table-name">Error retrieving inactive plugin: <pre>{ stderr }</pre></td>
<td className="plugins-table-info"> - </td>
<td className="plugins-table-info"> - </td>
</tr> } )
} else {
// split list into array
let plugins = stdout.trim().split( "\n" )
plugins.splice(0, 1)

// Only create unordered list if there are plugins to list
if ( plugins.length && plugins[0].length > 1 ) {
this.setState( { inactiveContent: plugins.map( (item) =>
}
else {
// split list into array
let plugins = stdout.trim().split( "\n" )
plugins.splice(0, 1)

// Only create unordered list if there are plugins to list
if ( plugins.length && plugins[0].length > 1 ) {
this.setState( { inactiveContent: plugins.map( (item) =>
<tr>
<td className="plugins-table-name" key={ plugins.indexOf(item) }>{ item.trim().split( "," )[0] }</td>
<td className={ item.trim().split( "," )[2] + " plugins-table-info" } >{ item.trim().split( "," )[2] }</td>
<td className="plugins-table-info">{ item.trim().split( "," )[3] }</td>
</tr> ) } )
} else {
this.setState( { inactiveContent:
<tr>
<td className="plugins-table-name">No inactive plugins.</td>
<td className="plugins-table-info"> - </td>
<td className="plugins-table-info"> - </td>
</tr> } )
}
}
} );
} else {
this.setState( { inactiveContent:
<tr>
<td className="plugins-table-name">No inactive plugins.</td>
<td className="plugins-table-info"> - </td>
<td className="plugins-table-info"> - </td>
</tr> } )
}
}
} );

this.setState( { content: null} )

}

render() {
return (
render() {
return (
<div className="plugins-container">
<link rel="stylesheet" href={this.stylesheetPath}/>

{ this.state.content }

<h3 className="plugins-table-title">Active Plugins</h3>
<h3 className="plugins-table-title">Active Plugins</h3>
<table className="table-striped plugins-table">
<thead>
<tr className="plugin-table-head" >
<th className="plugins-table-name"><strong>Name</strong></th>
<th className="plugins-table-info"><strong>Update</strong></th>
<th className="plugins-table-info"><strong>Version</strong></th>
</tr>
<tr className="plugin-table-head" >
<th className="plugins-table-name"><strong>Name</strong></th>
<th className="plugins-table-info"><strong>Update</strong></th>
<th className="plugins-table-info"><strong>Version</strong></th>
</tr>
</thead>
<tbody>

{ this.state.activeContent }

{ this.state.activeContent }
</tbody>
</table>

<h3 className="plugins-table-title">Inactive Plugins</h3>
<h3 className="plugins-table-title">Inactive Plugins</h3>
<table className="table-striped plugins-table">
<thead>
<tr className="plugin-table-head" >
<th className="plugins-table-name"><strong>Name</strong></th>
<th className="plugins-table-info"><strong>Update</strong></th>
<th className="plugins-table-info"><strong>Version</strong></th>
</tr>
<tr className="plugin-table-head" >
<th className="plugins-table-name"><strong>Name</strong></th>
<th className="plugins-table-info"><strong>Update</strong></th>
<th className="plugins-table-info"><strong>Version</strong></th>
</tr>
</thead>
<tbody>
{ this.state.inactiveContent }
{ this.state.inactiveContent }
</tbody>
</table>
</div>
);
}
</div>
);
}

}
}
Loading

0 comments on commit c26b199

Please sign in to comment.