Skip to content

Commit

Permalink
Merge 8ca3ca0 into c72be4c
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry Ruhs committed Aug 12, 2020
2 parents c72be4c + 8ca3ca0 commit cc444d6
Show file tree
Hide file tree
Showing 14 changed files with 271 additions and 26 deletions.
38 changes: 27 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,15 @@ Create a `.handpick` file to override configuration:
"--no-lockfile"
]
},
"path": ".",
"file": "package.json",
"range": "exact",
"rangeArray":
[
"dirty",
"exact",
"patch",
"minor"
],
"ignorePrefix": "__",
"ignoreArray":
[
"dependencies",
Expand All @@ -63,7 +70,8 @@ Create a `.handpick` file to override configuration:
"devDependencies"
],
"filterArray": [],
"prefix": "__"
"path": ".",
"file": "package.json"
}
```

Expand All @@ -81,6 +89,7 @@ handpick [options]
-T, --target <target>
-F, --filter <filter>
-M, --manager <manager>
-R, --range <range>
-P, --path <path>
-h, --help
```
Expand All @@ -89,13 +98,14 @@ handpick [options]
Options
-------

| Name | Type | Default | Mandatory |
|---------|---------|--------------------------------|-----------|
| config | string | .handpick | optional |
| target | string | dependencies / devDependencies | optional |
| filter | string | | optional |
| manager | string | npm | optional |
| path | string | . | optional |
| Name | Type | Default | Mandatory |
|---------|--------|--------------------------------|-----------|
| config | string | .handpick | optional |
| target | string | dependencies / devDependencies | optional |
| filter | string | | optional |
| manager | string | npm | optional |
| range | string | exact | optional |
| path | string | . | optional |


Examples
Expand All @@ -113,7 +123,7 @@ Define unofficial dependencies inside `package.json` file:
"testDependencies":
{
"chai": "4.2.0",
"mocha": "7.1.2"
"mocha": "7.2.0"
}
}
```
Expand Down Expand Up @@ -142,6 +152,12 @@ Install the `dependencies` and `devDependencies` within path:
handpick --path=../shared
```

Install the `dependencies` with `exact` range:

```
handpick --target=dependencies --range=exact
```


Managers
--------
Expand Down
10 changes: 7 additions & 3 deletions bin/handpick
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const option = handpick.option;
const packageObject = require('../package.json');
const targetArray = [];
const filterArray = [];
const managerArray = Object.keys(option.get('managerObject'));
const rangeArray = option.get('rangeArray');

let CORE;

Expand All @@ -16,7 +18,8 @@ program
.option('-C, --config <config>')
.option('-T, --target <target>', null, target => targetArray.push(target))
.option('-F, --filter <target>', null, filter => filterArray.push(filter))
.option('-M, --manager <manager>')
.option('-M, --manager <manager>', managerArray.join(' | '))
.option('-R, --range <range>', rangeArray.join(' | '))
.option('-P, --path <path>')
.parse(process.argv);

Expand All @@ -25,8 +28,9 @@ option.initWithConfig(
config: program.config,
targetArray: targetArray.length > 0 ? targetArray : option.get('targetArray'),
filterArray: filterArray.length > 0 ? filterArray : option.get('filterArray'),
manager: program.manager,
path: program.path
manager: managerArray.includes(program.manager) ? program.manager : option.get('manager'),
path: program.path,
range: rangeArray.includes(program.range) ? program.range : option.get('range')
});
CORE = new core(
{
Expand Down
14 changes: 11 additions & 3 deletions option.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,15 @@
"--no-lockfile"
]
},
"path": ".",
"file": "package.json",
"range": "exact",
"rangeArray":
[
"dirty",
"exact",
"patch",
"minor"
],
"ignorePrefix": "__",
"ignoreArray":
[
"dependencies",
Expand All @@ -31,5 +38,6 @@
"devDependencies"
],
"filterArray": [],
"prefix": "__"
"path": ".",
"file": "package.json"
}
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "handpick",
"description": "Handpick conditional dependencies like a boss",
"version": "2.1.0",
"version": "3.0.0-beta.1",
"license": "MIT",
"keywords":
[
Expand All @@ -25,8 +25,9 @@
},
"dependencies":
{
"commander": "5.1.0",
"ora": "4.0.4",
"commander": "6.0.0",
"ora": "5.0.0",
"semver": "7.3.2",
"utility-redaxmedia": "1.0.0"
},
"devDependencies":
Expand Down
33 changes: 31 additions & 2 deletions src/core.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const semver = require('semver');
const { promisify } = require('util');
const fs = require('fs');
const spawn = require('child_process').spawn;
Expand Down Expand Up @@ -85,16 +86,19 @@ function prepare(packageObject)
const ignoreArray = option.get('ignoreArray');
const targetArray = option.get('targetArray');
const filterArray = option.get('filterArray');
const range = option.get('range');
const filterObject = {};
const resultObject = {};

/* handle prefix */

Object.keys(packageObject).map(packageValue =>
{
const prefixValue = option.get('prefix') + packageValue;
const ignorePrefix = option.get('ignorePrefix') + packageValue;

if (ignoreArray.includes(packageValue))
{
resultObject[prefixValue] = packageObject[packageValue];
resultObject[ignorePrefix] = packageObject[packageValue];
}
else
{
Expand All @@ -109,6 +113,9 @@ function prepare(packageObject)
};
}
});

/* handle filter */

filterArray.map(filterValue =>
{
Object.keys(resultObject['dependencies']).filter(resultValue =>
Expand All @@ -120,6 +127,26 @@ function prepare(packageObject)
});
resultObject['dependencies'] = filterObject;
});

/* handle range */

Object.keys(resultObject['dependencies']).map(resultValue =>
{
const resultVersion = semver.coerce(resultObject['dependencies'][resultValue]).version;

if (range === 'exact')
{
resultObject['dependencies'][resultValue] = resultVersion;
}
if (range === 'patch')
{
resultObject['dependencies'][resultValue] = '~' + resultVersion;
}
if (range === 'minor')
{
resultObject['dependencies'][resultValue] = '^' + resultVersion;
}
});
return resultObject;
}

Expand All @@ -136,9 +163,11 @@ function startWording()
const manager = option.get('manager');
const targetArray = option.get('targetArray');
const filterArray = option.get('filterArray');
const range = option.get('range');
const wordingArray =
[
wordingObject.handpick,
range.toUpperCase(),
targetArray.join(' ' + wordingObject.and + ' ')
];

Expand Down
40 changes: 38 additions & 2 deletions tests/coreTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('core', () =>
expect(packageObject).to.have.property('devDependencies');
expect(packageObject).to.have.property('lintDependencies');
expect(packageObject).to.have.property('testDependencies');
expect(packageObject).to.have.property('dirtyDependencies');
done();
})
.catch(() => done('error'));
Expand Down Expand Up @@ -82,6 +83,40 @@ describe('core', () =>
.catch(() => done('error'));
});

[
'exact',
'patch',
'minor'
]
.map(range =>
{
it('prepare dirty to ' + range, done =>
{
option.initWithConfig(
{
path: 'tests/provider/core',
range,
targetArray:
[
'dirtyDependencies'
]
});
CORE.readObjectFromFile()
.then(packageObject =>
{
option.set('file', 'package_prepare_dirty_to_' + range + '.json');
CORE.readObjectFromFile()
.then(expectObject =>
{
expect(CORE.prepare(packageObject)).to.deep.equal(expectObject);
done();
})
.catch(() => done('error'));
})
.catch(() => done('error'));
});
});

it('prepare lint and test', done =>
{
option.initWithConfig(
Expand Down Expand Up @@ -143,8 +178,9 @@ describe('core', () =>
{
path: 'tests/provider/core'
});
expect(CORE.startWording()).to.equal('Hand picking dependencies and devDependencies via NPM');
expect(CORE.startWording()).to.equal('Hand picking EXACT dependencies and devDependencies via NPM');
option.set('manager', 'yarn');
option.set('range', 'patch');
option.set('targetArray',
[
'devDependencies'
Expand All @@ -153,6 +189,6 @@ describe('core', () =>
[
'lintDependencies'
]);
expect(CORE.startWording()).to.equal('Hand picking devDependencies without lintDependencies via YARN');
expect(CORE.startWording()).to.equal('Hand picking PATCH devDependencies without lintDependencies via YARN');
});
});
4 changes: 2 additions & 2 deletions tests/optionTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ describe('option', () =>
option.initWithConfig(
{
config: 'tests/provider/option/.handpick',
prefix: "____"
ignorePrefix: "____"
});
expect(option.get('config')).to.equal('tests/provider/option/.handpick');
expect(option.get('prefix')).to.equal('____');
expect(option.get('ignorePrefix')).to.equal('____');
expect(option.get('manager')).to.equal('yarn');
expect(option.get('file')).to.equal('package.json');
});
Expand Down
7 changes: 7 additions & 0 deletions tests/provider/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,12 @@
{
"chai": "1.0.0",
"mocha": "1.0.0"
},
"dirtyDependencies":
{
"chai": "v2.0",
"eslint": "^2.0.0",
"eslint-config-redaxmedia": "~2.0.0",
"mocha": ">2"
}
}
7 changes: 7 additions & 0 deletions tests/provider/core/package_prepare_dev_without_lint.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
"chai": "1.0.0",
"mocha": "1.0.0"
},
"dirtyDependencies":
{
"chai": "v2.0",
"eslint": "^2.0.0",
"eslint-config-redaxmedia": "~2.0.0",
"mocha": ">2"
},
"dependencies":
{
"chai": "1.0.0",
Expand Down
41 changes: 41 additions & 0 deletions tests/provider/core/package_prepare_dirty_to_exact.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "handpick",
"version": "1.0.0",
"__dependencies":
{
"commander": "1.0.0",
"ora": "1.0.0",
"utility-redaxmedia": "1.0.0"
},
"__devDependencies":
{
"chai": "1.0.0",
"eslint": "1.0.0",
"eslint-config-redaxmedia": "1.0.0",
"mocha": "1.0.0"
},
"lintDependencies":
{
"eslint": "1.0.0",
"eslint-config-redaxmedia": "1.0.0"
},
"testDependencies":
{
"chai": "1.0.0",
"mocha": "1.0.0"
},
"dirtyDependencies":
{
"chai": "v2.0",
"eslint": "^2.0.0",
"eslint-config-redaxmedia": "~2.0.0",
"mocha": ">2"
},
"dependencies":
{
"chai": "2.0.0",
"eslint": "2.0.0",
"eslint-config-redaxmedia": "2.0.0",
"mocha": "2.0.0"
}
}

0 comments on commit cc444d6

Please sign in to comment.