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

Linux package manager #364

Merged
merged 3 commits into from
May 10, 2017
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
21 changes: 14 additions & 7 deletions app/services/plugin.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { PythonPluginLoader } from "sinap-python-loader";
const app = remote.app;
const LOG = getLogger("plugin.service");

export const PLUGIN_DIRECTORY = IS_PRODUCTION ? path.join(app.getPath("userData"), "plugins") : "./plugins";
export const PLUGIN_DIRECTORY = IS_PRODUCTION ? path.join(app.getPath("userData"), "plugins") : path.join(app.getAppPath(), "plugins");
export const ROOT_DIRECTORY = IS_PRODUCTION ? path.join(app.getAppPath(), "..", "app") : ".";

class PluginHolder {
Expand Down Expand Up @@ -210,12 +210,15 @@ export class PluginService {
let dirs: string[] = [];

try {
dirs = await subdirs(PLUGIN_DIRECTORY);
const unfiltered = await subdirs(PLUGIN_DIRECTORY);
for (const dir of unfiltered) {
const files = await dirFiles(dir);
if (files.findIndex(file => file === "package.json") >= 0)
dirs.push(dir);
}
} catch (err) {
if (err && err.code === "ENOENT") {
if (err && err.code === "ENOENT")
await createDir(PLUGIN_DIRECTORY);
dirs = [];
}
}

const plugins = await somePromises(dirs.map(dir => this.loadPlugin(dir)), LOG);
Expand Down Expand Up @@ -254,8 +257,12 @@ export class PluginService {
public async importPlugin(dir: string): Promise<void> {
// Recursively progress through directories until we get interpreter info.
const dest = path.join(PLUGIN_DIRECTORY, path.basename(dir));
LOG.log(`Importing plugins from ${dir} to ${dest}.`);
await copy(dir, dest);
if (dest === dir) {
return Promise.resolve();
} else {
LOG.log(`Importing plugins from ${dir} to ${dest}.`);
await copy(dir, dest);
}
}

public async unload(plugin: Plugin): Promise<void> {
Expand Down
23 changes: 8 additions & 15 deletions app/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,16 @@ export function getExpected(program: Program) {


// Similar to Promise.all. However, this will always resolve and ignore rejected promises.
export function somePromises<T>(promises: Iterable<Promise<T>>, logger: Logger): Promise<T[]> {
let result: Promise<T[]> = Promise.resolve([]);

export async function somePromises<T>(promises: Iterable<Promise<T>>, logger: Logger): Promise<T[]> {
const arr = [] as T[];
for (const promise of promises) {
result = result.then((arr) => {
return promise.then((ele) => {
arr.push(ele);
return arr;
}).catch((err) => {
logger.log(err);
return arr;
});
});
try {
arr.push(await promise);
} catch (err) {
logger.log(err);
}
}

return result;
return Promise.resolve(arr);
}

export function getPath(name: string) {
Expand Down Expand Up @@ -151,7 +145,6 @@ export async function requestOpenDirs(name?: string): Promise<string[]> {
const result = new NodePromise<string[]>();
dialog.showOpenDialog(remote.BrowserWindow.getFocusedWindow(), {
properties: ["openDirectory"],
filters: [ZIP_FILE_FILTER],
defaultPath: name
}, names => result.cb(names ? null : "Directory selection cancelled", names));

Expand Down
19 changes: 12 additions & 7 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,19 @@ module.exports = (env = {}) => { // pass command line arguments like `webpack ..
plugins: [
new webpack.NoEmitOnErrorsPlugin(),

/*** # 5/9/2017 ***/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we really don't even need Uglify for our application since our code is so minimal compared to the rest of electron.

/*** See: https://github.com/webpack/webpack/issues/2545#issuecomment-300134407 ***/
/*** Removing uglify for the time being. ***/
/*** See also: https://github.com/webpack-contrib/uglifyjs-webpack-plugin ***/
/*** for up-to-date instructions on how to use the webpack uglify plugin. ***/
// Note because our project is ES6, we're using the harmony branch of uglifyjs
new webpack.optimize.UglifyJsPlugin({
debug: false,
minimize: true,
output: {
comments: false
},
}),
// new webpack.optimize.UglifyJsPlugin({
// debug: false,
// minimize: true,
// output: {
// comments: false
// },
// }),
]
};

Expand Down