Skip to content

Commit

Permalink
Extract methods
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-dv committed Jan 28, 2018
1 parent d754cc8 commit 49b3ef4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 25 deletions.
29 changes: 19 additions & 10 deletions scripts/compile-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@ const fs = require('fs');
const path = require('path');
const shell = require('shelljs');

function babelify(options = {}) {
const { watch = false, silent = true, errorCallback } = options;

if (!fs.existsSync('src')) {
if (!silent) console.log('No src dir');
return;
}

function getCommand(watch) {
const babel = path.join(__dirname, '..', 'node_modules', '.bin', 'babel');

const args = [
'--ignore __mocks__/,tests/*,__tests__/,**.test.js,stories/,**.story.js,**.stories.js,__snapshots__',
'--plugins "transform-runtime"',
Expand All @@ -23,9 +17,10 @@ function babelify(options = {}) {
args.push('-w');
}

const command = `${babel} ${args.join(' ')}`;
const { code } = shell.exec(command, { silent });
return `${babel} ${args.join(' ')}`;
}

function handleExit(code, errorCallback) {
if (code !== 0) {
if (errorCallback && typeof errorCallback === 'function') {
errorCallback();
Expand All @@ -35,6 +30,20 @@ function babelify(options = {}) {
}
}

function babelify(options = {}) {
const { watch = false, silent = true, errorCallback } = options;

if (!fs.existsSync('src')) {
if (!silent) console.log('No src dir');
return;
}

const command = getCommand(watch);
const { code } = shell.exec(command, { silent });

handleExit(code, errorCallback);
}

module.exports = {
babelify,
};
38 changes: 23 additions & 15 deletions scripts/compile-ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,27 @@ const fs = require('fs');
const path = require('path');
const shell = require('shelljs');

function getCommand(watch) {
const tsc = path.join(__dirname, '..', 'node_modules', '.bin', 'tsc');
const args = ['--outDir dist', '-d true', '--listEmittedFiles true'];

if (watch) {
args.push('-w');
}

return `${tsc} ${args.join(' ')}`;
}

function handleExit(code, errorCallback) {
if (code !== 0) {
if (errorCallback && typeof errorCallback === 'function') {
errorCallback();
}

shell.exit(code);
}
}

function tscfy(options = {}) {
const { watch = false, silent = true, errorCallback } = options;
const tsConfigFile = 'tsconfig.json';
Expand All @@ -20,23 +41,10 @@ function tscfy(options = {}) {
return;
}

const tsc = path.join(__dirname, '..', 'node_modules', '.bin', 'tsc');
const args = ['--outDir dist', '-d true', '--listEmittedFiles true'];

if (watch) {
args.push('-w');
}

const command = `${tsc} ${args.join(' ')}`;
const command = getCommand(watch);
const { code } = shell.exec(command, { silent });

if (code !== 0) {
if (errorCallback && typeof errorCallback === 'function') {
errorCallback();
}

shell.exit(code);
}
handleExit(code, errorCallback);
}

module.exports = {
Expand Down

0 comments on commit 49b3ef4

Please sign in to comment.