Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fixes #126

Merged
merged 7 commits into from
Nov 21, 2018
Merged

Fixes #126

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
85 changes: 75 additions & 10 deletions package-lock.json

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

100 changes: 57 additions & 43 deletions server/build-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,36 +35,26 @@ const getPackageName = name => {
};

async function installRemotePackages(installPackages) {
// check if connected to internet
// if not, skip npm install
const EXTERNAL_URI = process.env.EXTERNAL_URI || 'npmjs.com';
await require('dns').lookup(EXTERNAL_URI, async err => {
if (err && err.code === 'ENOTFOUND')
logger.error(`Can't reach npm servers. Skipping npm install`);
else {
// validation is done earlier, but still confirming at this step
const pkgStr = installPackages.reduce((str, name) => {
if (validate(name).validForNewPackages) str = `${str} ${name}`;
return str;
});
logger.info(`Installing plugin packages: ${pkgStr.split(' ')}`);

try {
execSync(`npm install --no-save ${pkgStr} --production`, {
stdio: [0, 1, 2],
cwd: resolve(__dirname, '..')
});
logger.info('Done installing remote plugins');
} catch (e) {
logger.error(
'There was an error installing plugins. Sometimes this is because of permissions errors \
in node_modules. Try deleting the node_modules directory and running `npm install` again.'
);
logger.error(e.stack);
process.exit(1);
}
}
const pkgStr = installPackages.reduce((str, name) => {
if (validate(name).validForNewPackages) str = `${str} ${name}`;
return str;
});
logger.info(`Installing plugin packages: ${pkgStr.split(' ')}`);

try {
execSync(`npm install --no-save ${pkgStr} --production`, {
stdio: [0, 1, 2],
cwd: resolve(__dirname, '..')
});
logger.info('Done installing remote plugins');
} catch (e) {
logger.error(
'There was an error installing plugins. Sometimes this is because of permissions errors \
in node_modules. Try deleting the node_modules directory and running `npm install` again.'
);
logger.error(e.stack);
process.exit(1);
}
}

/*
Expand Down Expand Up @@ -142,7 +132,7 @@ async function getLocalPlugins() {
return plugins;
}

async function prepareModules(plugins = [], local = true) {
async function prepareModules(plugins = [], local = true, network = false) {
let pluginsIndex = local
? '// exports for all local plugin modules\n\n'
: '// exports for all published plugin modules\n\n';
Expand Down Expand Up @@ -180,13 +170,17 @@ async function prepareModules(plugins = [], local = true) {
resolve(PLUGINS_PATH, 'local', packageName)
);

// if adding a remote plugin and it doesn't exist on npm, skip
const existsRemote = await npmExists(packageName);
if (!local && !existsRemote) {
logger.error(
`Remote module ${packageName} does not exist on npm. If developing locally, add to local plugins. Skipping...`
);
continue;
// can skip remote check if no nework connection
let existsRemote = true;
if (network) {
// if adding a remote plugin and it doesn't exist on npm, skip
existsRemote = !local && (await npmExists(packageName));
if (!local && !existsRemote) {
logger.error(
`Remote module ${packageName} does not exist on npm. If developing locally, add to local plugins. Skipping...`
);
continue;
}
}

if (existsLocal && local)
Expand Down Expand Up @@ -235,8 +229,13 @@ async function prepareModules(plugins = [], local = true) {
if (newModules) break;
}

// if there is no network connection, log message
if (!network)
logger.info(
'Skipping npm install of remote plugins due to lack of network connection'
);
// if there are new modules, install them with npm
if (newModules) await installRemotePackages(installPackages);
else if (newModules) await installRemotePackages(installPackages);
else
logger.info('No new remote plugins to install. Skipping npm install');
}
Expand Down Expand Up @@ -264,13 +263,28 @@ your config file.'
);

const { localPlugins, plugins } = require(PLUGINS_CONFIG);

// CLI & ENV plugins override configuration file
const envPlugins = config.str('plugins');
await prepareModules(
envPlugins ? envPlugins.split(',').map(s => s.trim(s)) : plugins,
false
);
await prepareModules(localPlugins);

// get network status for dealing with remote plugins
let network = false;
const EXTERNAL_URI = process.env.EXTERNAL_URI || 'npmjs.com';
require('dns').lookup(EXTERNAL_URI, async err => {
if (err && err.code === 'ENOTFOUND')
logger.error(`No network connection found.`);
else {
network = true;
}
// prepare remote plugins
await prepareModules(
envPlugins ? envPlugins.split(',').map(s => s.trim(s)) : plugins,
false,
network
);
// prepare local plugins
await prepareModules(localPlugins, true, network);
});
} catch (err) {
logger.error('There was an error preparing modules: ', err.stack);
}
Expand Down
17 changes: 10 additions & 7 deletions webapp/config/themeConfig/themeCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ const { makeRem, makeGutter } = utils;

const themeCreator = (_themeVariables = {}, _themeConfig = {}) => {
/* This if statement gives you access to default themeVariables in your custom theme.
** Declaring your themeVariables as a function gives you access to the default themeVariables as
** an argument to that function.
*/
* Declaring your themeVariables as a function gives you access to the default themeVariables as
* an argument to that function.
*/
if (typeof _themeVariables === 'function')
_themeVariables = _themeVariables(themeVariables);

Expand Down Expand Up @@ -360,7 +360,10 @@ const themeCreator = (_themeVariables = {}, _themeConfig = {}) => {
},
header: {
fontWeight: fontWeights.semiBold,
textTransform: 'capitalize'
textTransform: 'capitalize',
whiteSpace: 'nowrap',
overflow: 'hidden',
textOverflow: 'ellipsis'
},
body: {
fontWeight: fontWeights.light
Expand Down Expand Up @@ -491,9 +494,9 @@ const themeCreator = (_themeVariables = {}, _themeConfig = {}) => {
};

/* This if statement gives you access to default themeConfig in your custom theme.
** Declaring your themeConfig as a function gives you access to the default theme config as
** an argument to that function.
*/
* Declaring your themeConfig as a function gives you access to the default theme config as
* an argument to that function.
*/
if (typeof _themeConfig === 'function')
_themeConfig = _themeConfig(themeVariables, themeConfig);

Expand Down
2 changes: 1 addition & 1 deletion webapp/store/actions/navActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function loadSideNav() {
let sideNav = sortedNavItems({ pluginMetadata });
// add unique id to each nav item
sideNav = sideNav.map(item => {
item.id = item.id ? item.id : helpers.getHash(item, 'sha256', 0, 6);
item.id = item.id ? item.id : helpers.getHash(item, 'SHA256', 0, 6);
return item;
});
dispatch(setSideNav(sideNav));
Expand Down
18 changes: 13 additions & 5 deletions webapp/store/selectors/nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ function composeNavItems(_navItems = []) {
}

// selectors for converting pluginMetadata to nav list
export const sortedNavItems = createSelector(getMetadataList, composeNavItems);
export const sortedNavItems = createSelector(
getMetadataList,
composeNavItems
);

// selector for ordering and composing sidebar navigation items
export const sortedSidebarItems = createSelector(
Expand All @@ -126,10 +129,15 @@ export const sortedSidebarItems = createSelector(
);

// Useful selector for the Panel which just needs to match names to paths
export const uniquePathsByName = createSelector(getMetadataList, metadata =>
metadata
.filter(plugin => plugin.pathName)
.reduce((paths, { name, pathName }) => ({ ...paths, [name]: pathName }), {})
export const uniquePathsByName = createSelector(
getMetadataList,
metadata =>
metadata
.filter(plugin => plugin.pathName)
.reduce(
(paths, { name, pathName }) => ({ ...paths, [name]: pathName }),
{}
)
);

export default {
Expand Down