Skip to content
This repository has been archived by the owner on Jun 26, 2022. It is now read-only.

Commit

Permalink
split into modules
Browse files Browse the repository at this point in the history
  • Loading branch information
floatwork_jan committed Jul 10, 2019
1 parent 2887800 commit 74059bf
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 79 deletions.
2 changes: 1 addition & 1 deletion lib/provider.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/provider.js.map

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import meta from '../package.json';

export const configSchema = {
customArguments: {
title: 'Custom Arguments',
description: 'Specify your preferred arguments for `makensis`, supports [replacement](https://github.com/noseglid/atom-build#replacement) placeholders',
type: 'string',
default: '{FILE_ACTIVE}',
order: 0
},
manageDependencies: {
title: 'Manage Dependencies',
description: 'When enabled, third-party dependencies will be installed automatically',
type: 'boolean',
default: true,
order: 1
},
alwaysEligible: {
title: 'Always Eligible',
description: 'The build provider will be available in your project, even when not eligible',
type: 'boolean',
default: false,
order: 2
}
};

export function getConfig(key) {
return atom.config.get(`${meta.name}.${key}`);
}
89 changes: 12 additions & 77 deletions src/provider.js
Original file line number Diff line number Diff line change
@@ -1,77 +1,16 @@
'use babel';

import meta from '../package.json';
import { configSchema, getConfig } from './config';
import { EventEmitter } from 'events';
import { install } from 'atom-package-deps';
import { join } from 'path';
import { platform } from 'os';
import { spawn } from 'child_process';
import { satisfyDependencies } from './util';
import { spawnSync } from 'child_process';

import meta from '../package.json';
const pathToScript = join(__dirname, 'makensis-wine.sh');

// Package settings
export const config = {
customArguments: {
title: 'Custom Arguments',
description: 'Specify your preferred arguments for `makensis`, supports [replacement](https://github.com/noseglid/atom-build#replacement) placeholders',
type: 'string',
default: '{FILE_ACTIVE}',
order: 0
},
manageDependencies: {
title: 'Manage Dependencies',
description: 'When enabled, third-party dependencies will be installed automatically',
type: 'boolean',
default: true,
order: 1
},
alwaysEligible: {
title: 'Always Eligible',
description: 'The build provider will be available in your project, even when not eligible',
type: 'boolean',
default: false,
order: 2
}
};

export function satisfyDependencies() {
install(meta.name);

const packageDeps = meta['package-deps'];

packageDeps.forEach( packageDep => {
if (packageDep) {
if (atom.packages.isPackageDisabled(packageDep)) {
if (atom.inDevMode()) console.log(`Enabling package '${packageDep}\'`);
atom.packages.enablePackage(packageDep);
}
}
});
}

function spawnPromise(cmd, args) {
return new Promise(function (resolve, reject) {
const child = spawn(cmd, args);
let stdOut;
let stdErr;

child.stdout.on('data', function (line) {
stdOut += line.toString().trim();
});

child.stderr.on('data', function (line) {
stdErr += line.toString().trim();
});

child.on('close', function (code) {
if (code === 0) {
resolve(stdOut);
}

reject(stdErr);
});
});
}
export { configSchema as config };

export function provideBuilder() {
return class MakensisWineProvider extends EventEmitter {
Expand All @@ -85,22 +24,18 @@ export function provideBuilder() {
return 'NSIS (Wine)';
}

async isEligible() {
if (atom.config.get(`${meta.name}.alwaysEligible`) === true) {
isEligible() {
if (getConfig('alwaysEligible') === true) {
return true;
}

if (platform() === 'win32') {
return false;
}

const whichCmd = await spawnPromise('which', ['wine']);

if (whichCmd.stdout && whichCmd.stdout.toString()) {
return true;
}
const whichCmd = spawnSync('which', ['wine']);

return false;
return (whichCmd.stdout && whichCmd.stdout.toString().length) ? true : false;
}

settings() {
Expand All @@ -113,7 +48,7 @@ export function provideBuilder() {
const comboMatch = errorMatch.concat(warningMatch);

// User settings
const customArguments = atom.config.get(`${meta.name}.customArguments`).trim().split(' ');
const customArguments = getConfig('customArguments').trim().split(' ');

// Adjust errorMatch and warningMatch
const customErrorMatch = (customArguments.includes('-WX')) ? comboMatch : errorMatch;
Expand Down Expand Up @@ -157,8 +92,8 @@ export function provideBuilder() {
};
}

export function activate() {
if (atom.config.get(`${meta.name}.manageDependencies`) === true) {
export async function activate() {
if (getConfig('manageDependencies') === true) {
satisfyDependencies();
}
}
17 changes: 17 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import meta from '../package.json';
import { install } from 'atom-package-deps';

export function satisfyDependencies() {
install(meta.name);

const packageDeps = meta['package-deps'];

packageDeps.forEach( packageDep => {
if (packageDep) {
if (atom.packages.isPackageDisabled(packageDep)) {
if (atom.inDevMode()) console.log(`Enabling package '${packageDep}\'`);
atom.packages.enablePackage(packageDep);
}
}
});
}

0 comments on commit 74059bf

Please sign in to comment.