-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
137,459 additions
and
1,763 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default new Set(['onLoad', 'onUnload', 'getProjectMenu']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { join, dirname } from 'path'; | ||
import preferences from '~/preferences'; | ||
|
||
const PLUGINS_DIR = '.npmkit_plugins'; | ||
|
||
export default function getPluginsDir(mod) { | ||
const base = join(dirname(preferences.path), PLUGINS_DIR); | ||
return mod ? join(base, 'node_modules', mod) : base; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import preferences from '~/preferences'; | ||
import base from './base'; | ||
|
||
export default function getPluginHooks(name) { | ||
return preferences | ||
.get('plugins') | ||
.map(name => __non_webpack_require__(base(name))) | ||
.map(plugin => (plugin.hasOwnProperty(name) ? plugin[name] : false)) | ||
.filter(Boolean); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import available from './available'; | ||
import install from './install'; | ||
import load from './load'; | ||
import hooks from './hooks'; | ||
import base from './base'; | ||
|
||
export default { | ||
available, | ||
load, | ||
install, | ||
hooks, | ||
base, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import cp from 'child_process'; | ||
import util from 'util'; | ||
import { join, resolve } from 'path'; | ||
import { ensureDir, writeJson } from 'fs-extra'; | ||
import preferences from '~/preferences'; | ||
import getPluginsDir from './base'; | ||
|
||
const execFileAsync = util.promisify(cp.execFile); | ||
const yarn = resolve(__dirname, '../../bin/yarn-standalone.js'); | ||
|
||
async function install(pluginName) { | ||
const pluginsDir = getPluginsDir(); | ||
const cacheDir = join(pluginsDir, 'cache'); | ||
await ensureDir(pluginsDir); | ||
await ensureDir(cacheDir); | ||
await writeJson(join(pluginsDir, 'package.json'), { | ||
name: 'npmkit-plugins', | ||
description: 'Auto-generated by npmkit', | ||
private: true, | ||
version: '0.0.1', | ||
dependencies: preferences | ||
.get('plugins') | ||
.reduce((deps, name) => ({ ...deps, [name]: 'latest' }), {}), | ||
}); | ||
await execFileAsync( | ||
process.execPath, | ||
[ | ||
yarn, | ||
'install', | ||
'--no-emoji', | ||
'--no-lockfile', | ||
'--cache-folder', | ||
cacheDir, | ||
], | ||
{ | ||
cwd: pluginsDir, | ||
env: { NODE_ENV: 'production', ELECTRON_RUN_AS_NODE: 'true' }, | ||
timeout: 1000 * 60 * 5, | ||
maxBuffer: 1024 * 1024, | ||
} | ||
); | ||
return __non_webpack_require__(getPluginsDir(pluginName)); | ||
} | ||
|
||
export default install; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import install from './install'; | ||
import getPluginsDir from './base'; | ||
|
||
export default async function loadPlugin(pluginName) { | ||
let mod; | ||
try { | ||
mod = __non_webpack_require__(getPluginsDir(pluginName)); | ||
} catch (reason) { | ||
if (/Cannot find module/.test(reason.toString())) { | ||
mod = await install(pluginName); | ||
} else { | ||
throw reason; | ||
} | ||
} | ||
return mod.default ? mod.default : mod; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import createStore from './create-store'; | ||
|
||
const preferences = createStore().ensureDefaults(); | ||
|
||
export default preferences; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { app } from 'electron'; | ||
|
||
if (global.process.env.NODE_ENV === 'test') { | ||
// Point userData to temp directory | ||
app.setPath('userData', app.getPath('temp')); | ||
// Make sure visual snapshots are the same on CI | ||
app.commandLine.appendSwitch('high-dpi-support', 'true'); | ||
app.commandLine.appendSwitch('force-device-scale-factor', '2'); | ||
} |
Oops, something went wrong.