Skip to content

Commit

Permalink
chore: upgrade to ShellJS v0.7 and refactor accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
nfischer committed May 7, 2016
1 parent 8461446 commit 1928a28
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 51 deletions.
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ gulp.task('packages', function () {
readme = readme.replace(/\{package\-name\}/g, `cash-${name}`);
readme = readme.replace(/\{command\-name\}/g, `${name}`);
readme = readme.replace(/\{related\}/g, related);
readme.to(`${dir}/README.md`);
new $.ShellString(readme).to(`${dir}/README.md`);
for (let i = 0; i < files.length; ++i) {
$.cp('-f', files[i], `${dir}/${files[i]}`);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"gulp-eslint": "^2.0.0",
"istanbul": "^0.4.2",
"mocha": "^2.2.5",
"shelljs": "^0.6.0",
"shelljs": "^0.7.0",
"should": "^7.0.3",
"webpack": "^1.12.13",
"xo": "^0.12.1"
Expand Down
8 changes: 4 additions & 4 deletions test/cat.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ const $ = require('shelljs');

describe('cat', function () {
before(function () {
'aardvark'.to('a.test');
'batman'.to('b.test');
'dont\n\n\neat\naardvarks\n\n\n'.to('c.test2');
new $.ShellString('aardvark').to('a.test');
new $.ShellString('batman').to('b.test');
new $.ShellString('dont\n\n\neat\naardvarks\n\n\n').to('c.test2');
});

after(function () {
$.rm(['a.test', 'b.test', 'c.test2']);
$.rm('a.test', 'b.test', 'c.test2');
});

it('should exist and be a function', function () {
Expand Down
12 changes: 6 additions & 6 deletions test/cp.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ describe('cp', function () {
});

it('should clobber existing files', function () {
'foxes'.to('cp-d');
'elephants'.to('cp-e');
new $.ShellString('foxes').to('cp-d');
new $.ShellString('elephants').to('cp-e');
cash.cp('cp-d cp-e');
$.test('-e', 'cp-d').should.equal(true);
$.cat('cp-e').should.equal('foxes');
});

describe('-n', function () {
it('should not clobber existing files', function () {
'foxes'.to('cp-d');
'elephants'.to('cp-e');
new $.ShellString('foxes').to('cp-d');
new $.ShellString('elephants').to('cp-e');
cash.cp('cp-d cp-e', {noclobber: true}).should.equal('');
$.test('-e', 'cp-d').should.equal(true);
$.cat('cp-d').should.equal('foxes');
Expand All @@ -110,8 +110,8 @@ describe('cp', function () {

describe('-f', function () {
it('should overwrite -n', function () {
'foxes'.to('cp-d');
'elephants'.to('cp-e');
new $.ShellString('foxes').to('cp-d');
new $.ShellString('elephants').to('cp-e');
cash.cp('cp-d cp-e', {noclobber: true, force: true});
$.test('-e', 'cp-d').should.equal(true);
$.cat('cp-e').should.equal('foxes');
Expand Down
7 changes: 3 additions & 4 deletions test/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ require('mocha');
const should = require('should');
const cash = require('../dist/index.js');
const $ = require('shelljs');
require('shelljs/global');

const fxt = {
ten: 'line1\nline2\nline3\nline4\nline5\nline6\nline7\nline8\nline9\nline10\n',
Expand All @@ -17,12 +16,12 @@ const fxt = {

describe('head', function () {
before(function () {
'line1\nline2\nline3\nline4\nline5\nline6\nline7\nline8\nline9\nline10\nline11'.to('eleven.test');
'line1\nline2\nline3\nline4\nline5\nline6\nline7\nline8\nline9\nline10'.to('ten.test');
new $.ShellString('line1\nline2\nline3\nline4\nline5\nline6\nline7\nline8\nline9\nline10\nline11').to('eleven.test');
new $.ShellString('line1\nline2\nline3\nline4\nline5\nline6\nline7\nline8\nline9\nline10').to('ten.test');
});

after(function () {
$.rm(['eleven.test', 'ten.test']);
$.rm('eleven.test', 'ten.test');
});

it('should exist', function () {
Expand Down
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('cash', function () {
console.error('warning: unable to save your cashrc file');
}
}
'touch fizzlecrumbs'.to(cashrcPath);
new $.ShellString('touch fizzlecrumbs').to(cashrcPath);
cash = require('..');
});

Expand Down
12 changes: 6 additions & 6 deletions test/mv.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,17 @@ describe('mv', function () {
});

it('should clobber existing files', function () {
'foxes'.to('mv-d');
'elephants'.to('mv-e');
new $.ShellString('foxes').to('mv-d');
new $.ShellString('elephants').to('mv-e');
cash.mv('mv-d mv-e');
$.test('-e', 'mv-d').should.equal(false);
$.cat('mv-e').should.equal('foxes');
});

describe('-n', function () {
it('should not clobber existing files', function () {
'foxes'.to('mv-d');
'elephants'.to('mv-e');
new $.ShellString('foxes').to('mv-d');
new $.ShellString('elephants').to('mv-e');
cash.mv('mv-d mv-e', {noclobber: true}).should.equal('');
$.test('-e', 'mv-d').should.equal(true);
$.cat('mv-d').should.equal('foxes');
Expand All @@ -106,8 +106,8 @@ describe('mv', function () {

describe('-f', function () {
it('should overwrite -n', function () {
'foxes'.to('mv-d');
'elephants'.to('mv-e');
new $.ShellString('foxes').to('mv-d');
new $.ShellString('elephants').to('mv-e');
cash.mv('mv-d mv-e', {noclobber: true, force: true});
$.test('-e', 'mv-d').should.equal(false);
$.cat('mv-e').should.equal('foxes');
Expand Down
23 changes: 11 additions & 12 deletions test/rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@ const should = require('should');
const cash = require('../dist/index.js');
const fs = require('fs');
const $ = require('shelljs');
require('shelljs/global');

describe('rm', function () {
before(function () {
$.mkdir('rm-test');
$.mkdir('./rm-test/sub');
'1'.to('1.rm');
'a'.to('./rm-test/a.txt');
'b'.to('./rm-test/b.txt');
'c'.to('./rm-test/c.txt');
'd'.to('./rm-test/sub/d.txt');
'cow'.to('./rm-test/a.cows');
'cow'.to('./rm-test/b.cows');
'cow'.to('./rm-test/c.cows');
'goose'.to('./rm-test/a.goose');
'goose'.to('./rm-test/b.goose');
new $.ShellString('1').to('1.rm');
new $.ShellString('a').to('./rm-test/a.txt');
new $.ShellString('b').to('./rm-test/b.txt');
new $.ShellString('c').to('./rm-test/c.txt');
new $.ShellString('d').to('./rm-test/sub/d.txt');
new $.ShellString('cow').to('./rm-test/a.cows');
new $.ShellString('cow').to('./rm-test/b.cows');
new $.ShellString('cow').to('./rm-test/c.cows');
new $.ShellString('goose').to('./rm-test/a.goose');
new $.ShellString('goose').to('./rm-test/b.goose');
});

after(function () {
Expand Down Expand Up @@ -78,7 +77,7 @@ describe('rm', function () {
describe('rm -f', function () {
it('should remove a read only file with', function () {
$.mkdir('-p', './rm-temp/readonly');
'asdf'.to('./rm-temp/readonly/file2');
new $.ShellString('asdf').to('./rm-temp/readonly/file2');
fs.chmodSync('./rm-temp/readonly/file2', '0444'); // -r--r--r--
cash.rm('./rm-temp/readonly/file2', {force: true});
($.ls('.').indexOf('./rm-temp/readonly/file2')).should.equal(-1);
Expand Down
15 changes: 7 additions & 8 deletions test/sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ require('assert');
const should = require('should');
const cash = require('../dist/index.js');
const $ = require('shelljs');
require('shelljs/global');

function sort(dir, opts) {
opts = opts || {};
Expand All @@ -20,13 +19,13 @@ function sort(dir, opts) {
describe('sort', function () {
before(function (done) {
setTimeout(function () {
'zaz\nsss\nqqq\n-zbz\nBBB\nddd\nCCC\n2bbb\nccc\n'.to('./default.sort');
'22 zaz\n33 sss\n11 qqq\n77 ccc\n55 BBB\nddd\nCCC\n2bbb\n-zbz\n'.to('./numeric.sort');
'1k\na 2G\n8k\n1M\n.8K\nddd\nCCC\n7bbb\n1bbb\n5M\n4G\n3T\n2.5P\n2E\n1Z\n6bbb\n5bbb\n-zbz\n'.to('./human.sort');
'4mar\nMarch\nMarc\napr\nAPR\ngoats\n56sevenjan\njan345kds\ndec\ndecem\nau\nAuGuSt\nAuGurt\naug\naugust\n'.to('./month.sort');
'1\n2\n3\n4\n5\n26\n7\n8\n9\n10\n11\n'.to('./disorder-numeric.sort');
'a\nb\nc\nd\nf\ne\ng\n'.to('./disorder.sort');
'1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n'.to('./numbers.sort');
new $.ShellString('zaz\nsss\nqqq\n-zbz\nBBB\nddd\nCCC\n2bbb\nccc\n').to('./default.sort');
new $.ShellString('22 zaz\n33 sss\n11 qqq\n77 ccc\n55 BBB\nddd\nCCC\n2bbb\n-zbz\n').to('./numeric.sort');
new $.ShellString('1k\na 2G\n8k\n1M\n.8K\nddd\nCCC\n7bbb\n1bbb\n5M\n4G\n3T\n2.5P\n2E\n1Z\n6bbb\n5bbb\n-zbz\n').to('./human.sort');
new $.ShellString('4mar\nMarch\nMarc\napr\nAPR\ngoats\n56sevenjan\njan345kds\ndec\ndecem\nau\nAuGuSt\nAuGurt\naug\naugust\n').to('./month.sort');
new $.ShellString('1\n2\n3\n4\n5\n26\n7\n8\n9\n10\n11\n').to('./disorder-numeric.sort');
new $.ShellString('a\nb\nc\nd\nf\ne\ng\n').to('./disorder.sort');
new $.ShellString('1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n').to('./numbers.sort');
done();
}, 100);
});
Expand Down
8 changes: 4 additions & 4 deletions test/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ describe('source', function () {
before(function () {
oldCwd = process.cwd();
oldProcessEnv = process.env;
'echo " hello world"\nalias foo bar\n'.to('a.sh');
`export FOO=hello
new $.ShellString('echo " hello world"\nalias foo bar\n').to('a.sh');
new $.ShellString(`export FOO=hello
export BAR=$FOO$FOO
cd ..`.to('b.sh');
cd ..`).to('b.sh');
$.touch('nonreadable.txt');
$.chmod('000', 'nonreadable.txt');
});

after(function () {
process.env = oldProcessEnv;
$.chmod('555', 'nonreadable.txt'); // to allow deletion
$.rm('-f', ['a.sh', 'b.sh', 'nonreadable.txt']);
$.rm('-f', 'a.sh', 'b.sh', 'nonreadable.txt');
});

beforeEach(function () {
Expand Down
6 changes: 3 additions & 3 deletions test/tail.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ const fxt = {

describe('tail', function () {
before(function () {
'line1\nline2\nline3\nline4\nline5\nline6\nline7\nline8\nline9\nline10\nline11\n'.to('eleven.test');
'line1\nline2\nline3\nline4\nline5\nline6\nline7\nline8\nline9\nline10\n'.to('ten.test');
new $.ShellString('line1\nline2\nline3\nline4\nline5\nline6\nline7\nline8\nline9\nline10\nline11\n').to('eleven.test');
new $.ShellString('line1\nline2\nline3\nline4\nline5\nline6\nline7\nline8\nline9\nline10\n').to('ten.test');
});

after(function () {
$.rm(['eleven.test', 'ten.test']);
$.rm('eleven.test', 'ten.test');
});

it('should exist and be a function', function () {
Expand Down
2 changes: 1 addition & 1 deletion test/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = {
const next = files.shift();
if (next) {
filler = double(filler);
filler.to(dir + next);
new $.ShellString(filler).to(dir + next);
setTimeout(function () {
write();
}, 10);
Expand Down

0 comments on commit 1928a28

Please sign in to comment.