Skip to content

Commit

Permalink
Get rid of some dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus authored and SBoudrias committed Mar 5, 2017
1 parent 6553965 commit 2cab46e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 20 deletions.
13 changes: 6 additions & 7 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';
const util = require('util');
const fs = require('fs');
const path = require('path');
const os = require('os');
const EventEmitter = require('events');
const assert = require('assert');
const _ = require('lodash');
Expand All @@ -11,10 +13,7 @@ const mkdirp = require('mkdirp');
const minimist = require('minimist');
const runAsync = require('run-async');
const through = require('through2');
const userHome = require('user-home');
const FileEditor = require('mem-fs-editor');
const pathIsAbsolute = require('path-is-absolute');
const pathExists = require('path-exists');
const debug = require('debug')('yeoman:generator');
const Conflicter = require('./util/conflicter');
const Storage = require('./util/storage');
Expand Down Expand Up @@ -575,7 +574,7 @@ Base.prototype._getStorage = function () {
*/

Base.prototype._getGlobalStorage = function () {
const storePath = path.join(userHome, '.yo-rc-global.json');
const storePath = path.join(os.homedir(), '.yo-rc-global.json');
const storeName = util.format('%s:%s', this.rootGeneratorName(), this.rootGeneratorVersion());
return new Storage(storeName, this.fs, storePath);
};
Expand All @@ -592,7 +591,7 @@ Base.prototype.destinationRoot = function (rootPath) {
if (_.isString(rootPath)) {
this._destinationRoot = path.resolve(rootPath);

if (!pathExists.sync(rootPath)) {
if (!fs.existsSync(rootPath)) {
mkdirp.sync(rootPath);
}

Expand Down Expand Up @@ -630,7 +629,7 @@ Base.prototype.sourceRoot = function (rootPath) {
Base.prototype.templatePath = function () {
let filepath = path.join.apply(path, arguments);

if (!pathIsAbsolute(filepath)) {
if (!path.isAbsolute(filepath)) {
filepath = path.join(this.sourceRoot(), filepath);
}

Expand All @@ -646,7 +645,7 @@ Base.prototype.templatePath = function () {
Base.prototype.destinationPath = function () {
let filepath = path.join.apply(path, arguments);

if (!pathIsAbsolute(filepath)) {
if (!path.isAbsolute(filepath)) {
filepath = path.join(this.destinationRoot(), filepath);
}

Expand Down
4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@
"mem-fs-editor": "^3.0.0",
"minimist": "^1.2.0",
"mkdirp": "^0.5.0",
"path-exists": "^3.0.0",
"path-is-absolute": "^1.0.0",
"pretty-bytes": "^4.0.2",
"read-chunk": "^2.0.0",
"read-pkg-up": "^2.0.0",
Expand All @@ -59,7 +57,6 @@
"shelljs": "^0.7.0",
"text-table": "^0.2.0",
"through2": "^2.0.0",
"user-home": "^2.0.0",
"yeoman-environment": "^1.1.0"
},
"devDependencies": {
Expand All @@ -73,7 +70,6 @@
"jsdoc": "^3.3.0-beta1",
"mockery": "^2.0.0",
"nock": "^9.0.5",
"pinkie-promise": "^2.0.0",
"proxyquire": "^1.0.0",
"sinon": "^1.9.1",
"tui-jsdoc-template": "^1.0.4",
Expand Down
11 changes: 4 additions & 7 deletions test/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ const mkdirp = require('mkdirp');
const mockery = require('mockery');
const rimraf = require('rimraf');
const through = require('through2');
const pathExists = require('path-exists');
const Promise = require('pinkie-promise');
const yeoman = require('yeoman-environment');
const userHome = require('user-home');

mockery.enable({
warnOnReplace: false,
Expand Down Expand Up @@ -458,15 +455,15 @@ describe('Base', () => {
};

this.testGen.run(() => {
assert(pathExists.sync(filepath));
assert(fs.existsSync(filepath));
done();
});
});

it('allow skipping file writes to disk', function (done) {
const action = {action: 'skip'};
const filepath = path.join(__dirname, '/fixtures/conflict.js');
assert(pathExists.sync(filepath));
assert(fs.existsSync(filepath));

this.TestGenerator.prototype.writing = function () {
this.fs.write(filepath, 'some new content');
Expand Down Expand Up @@ -521,7 +518,7 @@ describe('Base', () => {
it('does not pass config file to conflicter', function (done) {
this.TestGenerator.prototype.writing = function () {
fs.writeFileSync(this.destinationPath('.yo-rc.json'), '{"foo": 3}');
fs.writeFileSync(path.join(userHome, '.yo-rc-global.json'), '{"foo": 3}');
fs.writeFileSync(path.join(os.homedir(), '.yo-rc-global.json'), '{"foo": 3}');
this.config.set('bar', 1);
this._globalConfig.set('bar', 1);
};
Expand All @@ -535,7 +532,7 @@ describe('Base', () => {
};

this.testGen.run(() => {
assert(pathExists.sync(this.testGen.destinationPath('foo.txt')));
assert(fs.existsSync(this.testGen.destinationPath('foo.txt')));
done();
});
});
Expand Down
3 changes: 1 addition & 2 deletions test/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ const fs = require('fs');
const os = require('os');
const path = require('path');
const FileEditor = require('mem-fs-editor');
const pathExists = require('path-exists');
const env = require('yeoman-environment');
const helpers = require('yeoman-test');
const Storage = require('../lib/util/storage');

const tmpdir = path.join(os.tmpdir(), 'yeoman-storage');

function rm(filepath) {
if (pathExists.sync(filepath)) {
if (fs.existsSync(filepath)) {
fs.unlinkSync(path);
}
}
Expand Down

0 comments on commit 2cab46e

Please sign in to comment.