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

chore: update dependencies to latest #56

Merged
merged 2 commits into from
Mar 23, 2020
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
3 changes: 1 addition & 2 deletions __mocks__/bin-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
const src = jest.fn(() => binWrapperObject);
const dest = jest.fn(() => binWrapperObject);
const path = jest.fn(() => binWrapperObject);
const run = jest.fn((_, cb) => {
cb();
const run = jest.fn(async () => {
return binWrapperObject;
});
const use = jest.fn(() => binWrapperObject);
Expand Down
17 changes: 10 additions & 7 deletions __tests__/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,25 @@ describe('install', () => {

test('runs after installation', async () => {
await install();
expect(run).toHaveBeenCalledWith(['version'], expect.any(Function));
expect(run).toHaveBeenCalledWith(['version']);
expect(run).toHaveBeenCalledTimes(1);
});

test('runs after installation', async () => {
await install();
expect(run).toHaveBeenCalledWith(['version'], expect.any(Function));
expect(run).toHaveBeenCalledWith(['version']);
expect(run).toHaveBeenCalledTimes(1);
});

test('rejects promise if error in installation run', () => {
test('rejects promise if error in installation run', async () => {
const errorMessage = 'some err';
run.mockImplementationOnce((_, cb) => {
cb(errorMessage);
});
run.mockRejectedValue(errorMessage);

expect(install()).rejects.toMatch(errorMessage);
expect.assertions(1);
try {
await install();
} catch (err) {
expect(err.message).toMatch(errorMessage);
}
});
});
1 change: 1 addition & 0 deletions __tests__/themekit.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const path = require('path');
const {spawn} = require('child_process');

const cfg = require('../lib/config');
const themekit = require('../lib/themekit');

Expand Down
4 changes: 3 additions & 1 deletion __tests__/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const fsMock = require('mock-fs');
const fs = require('fs');

const fsMock = require('mock-fs');

const {cleanFile, getFlagArrayFromObject} = require('../lib/utils');

describe('getFlagArrayFromObject', () => {
Expand Down
59 changes: 28 additions & 31 deletions lib/install.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const BinWrapper = require('bin-wrapper');
const spinner = require('simple-spinner');

const config = require('./config');
const {cleanFile} = require('./utils');

Expand All @@ -8,37 +9,33 @@ const {cleanFile} = require('./utils');
* Call this on npm postinstall.
* @param {string} logLevel Log level
*/
function install(logLevel) {
return new Promise((resolve, reject) => {
const logger = require('./logger')(logLevel);
const urlAndPath = `${config.baseURL}/v${config.version}`;

logger.silly('Theme Kit installation starting');
spinner.start();

const installer = new BinWrapper()
.src(`${urlAndPath}/darwin-amd64/theme`, 'darwin')
.src(`${urlAndPath}/linux-386/theme`, 'linux')
.src(`${urlAndPath}/linux-amd64/theme`, 'linux', 'x64')
.src(`${urlAndPath}/windows-386/theme.exe`, 'win32')
.src(`${urlAndPath}/windows-amd64/theme.exe`, 'win32', 'x64')
.dest(config.destination)
.use(config.binName);

const pathToExecutable = installer.path();

cleanFile(pathToExecutable);

installer.run(['version'], (runErr) => {
if (runErr) {
reject(runErr);
}

spinner.stop();
logger.info(`Theme Kit path: ${pathToExecutable}`);
resolve();
});
});
async function install(logLevel) {
const logger = require('./logger')(logLevel);
const urlAndPath = `${config.baseURL}/v${config.version}`;

logger.silly('Theme Kit installation starting');
spinner.start();

const installer = new BinWrapper()
.src(`${urlAndPath}/darwin-amd64/theme`, 'darwin')
.src(`${urlAndPath}/linux-386/theme`, 'linux')
.src(`${urlAndPath}/linux-amd64/theme`, 'linux', 'x64')
.src(`${urlAndPath}/windows-386/theme.exe`, 'win32')
.src(`${urlAndPath}/windows-amd64/theme.exe`, 'win32', 'x64')
.dest(config.destination)
.use(config.binName);

const pathToExecutable = installer.path();

cleanFile(pathToExecutable);

try {
await installer.run(['version']);
spinner.stop();
logger.info(`Theme Kit path: ${pathToExecutable}`);
} catch (err) {
throw new Error(err);
}
}

module.exports = install;
4 changes: 1 addition & 3 deletions lib/themekit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ const themekit = {
* @param {Object} options additional options (cwd and logLevel)
*/
command(cmd, flagObj = {}, options = {cwd: process.cwd()}) {
const updatedFlagObj = Object.assign({}, flagObj, {
noUpdateNotifier: true
});
const updatedFlagObj = {...flagObj, noUpdateNotifier: true};
const flagArr = getFlagArrayFromObject(updatedFlagObj);

return runExecutable(
Expand Down
Loading