Skip to content
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.

Commit

Permalink
Removed path.getProjectFolderName().
Browse files Browse the repository at this point in the history
Added docblocks throughout.
  • Loading branch information
hassankhan committed May 15, 2016
1 parent 042b244 commit bcecdc5
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 22 deletions.
40 changes: 28 additions & 12 deletions src/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,43 @@
const fs = require('fs');
const path = require('path');

const getProjectFolderName = (givenPath) => {
return givenPath.split(path.sep).pop();
/**
* Checks if `file` exists and returns `true`, `false` otherwise.
*
* @param {String} file Path of the file
*
* @return {Boolean}
*/
const isFile = (file) => {
return fs.statSync(file).isFile();
};

const isFile = (givenPath) => {
return fs.statSync(givenPath).isFile();
/**
* Checks if `directory` exists and returns `true`, `false` otherwise.
*
* @param {String} directory
*
* @return {Boolean}
*/
const isDirectory = (directory) => {
return fs.statSync(directory).isDirectory();
};

const isDirectory = (givenPath) => {
return fs.statSync(givenPath).isDirectory();
};

const makeDirectory = (givenPath) => {
if (!fs.existsSync(givenPath)) {
fs.mkdirSync(givenPath);
/**
* Creates a directory at `directory` if it doesn't already exist
*
* @param {String} directory
*
* @return {Void}
*/
const makeDirectory = (directory) => {
if (!fs.existsSync(directory)) {
fs.mkdirSync(directory);
}
};

module.exports = {
isFile: isFile,
isDirectory: isDirectory,
makeDirectory: makeDirectory,
getProjectFolderName: getProjectFolderName,
};
9 changes: 9 additions & 0 deletions src/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

let spawn = require('child_process').spawn;

/**
* Runs `command` as a shell process. Optionally, options can be passed to the
* underlying `child_process.spawn()` command via `sArgs`.
*
* @param {String} command
* @param {Object} sArgs
*
* @return {Void}
*/
const run = (command, sArgs) => {
const spawnArgs = sArgs || {stdio: 'inherit', stdin: 'inherit'};

Expand Down
9 changes: 8 additions & 1 deletion src/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@
const path = require('path');
const log = require('npmlog');

/**
* Retrieve the `package.json` file from the path provided by `folder`.
*
* @param {String} folder
*
* @return {Object}
*/
const getPackageJson = (folder) => {
let pkg = [];
let pkg = {};
try {
pkg = require(path.join(folder, 'package.json'));
} catch (e) {
Expand Down
27 changes: 27 additions & 0 deletions src/validate.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
'use strict';

/**
* If `name` is a valid package name, returns `true`, otherwise `false`.
*
* @param {String} name
*
* @return {Boolean}
*/
const isPackageName = (name) => {
return !name.match(/^([a-zA-Z_$][a-zA-Z\d_$]*\.)+([a-zA-Z_$][a-zA-Z\d_$]*)$/)
? false
: true;
};

/**
* If `dependency` is a valid React Native dependency, returns `true`, otherwise `false`.
*
* @param {String} dependency
*
* @return {Boolean}
*/
const isPlugin = (dependency) => {
return !!~dependency.indexOf('react-native-');
};

/**
* If `RN_PROJECT_ROOT`
*
* @param {String} folder
*
* @return {Boolean}
*/
const isProject = () => {
const pkg = require('./project').getPackageJson(process.env.RN_PROJECT_ROOT);
var result = false;
Expand All @@ -25,6 +46,12 @@ const isProject = () => {
return result;
};

/**
* If the current working directory matches the `RN_PROJECT_ROOT` environment
* variable, then returns `true`, otherwise `false`.
*
* @return {Boolean}
*/
const inProject = () => {
return process.cwd() === process.env.RN_PROJECT_ROOT;
};
Expand Down
8 changes: 0 additions & 8 deletions tests/path.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,5 @@ describe('path', () => {

});

describe('#getProjectFolderName', () => {

it('should get the folder name', () => {
expect(pathUtils.getProjectFolderName(path.join(__dirname, '..'))).to.deep.equals('rsx-common');
});

});

});

2 changes: 1 addition & 1 deletion tests/project.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('project', () => {

it('should return an empty array if no package file exists', () => {
let nonprojectPath = path.join(__dirname, 'fixtures');
expect(projectUtils.getPackageJson(nonprojectPath)).to.deep.equals([]);
expect(projectUtils.getPackageJson(nonprojectPath)).to.deep.equals({});
});

});
Expand Down

0 comments on commit bcecdc5

Please sign in to comment.