Skip to content

Commit

Permalink
feat(package): Minimum default Node.js version is 10
Browse files Browse the repository at this point in the history
- Increase the minimum default Node.js version to 10
- Uprade deprecated config and support interactive mode
  • Loading branch information
sapegin committed Sep 2, 2020
1 parent 16dc19f commit 497807e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 19 deletions.
4 changes: 2 additions & 2 deletions packages/mrm-task-package/__snapshots__/index.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exports[`should add package.json 1`] = `
\\"repository\\": \\"gendalf/mrm-task-package\\",
\\"license\\": \\"MIT\\",
\\"engines\\": {
\\"node\\": \\">=6.9\\"
\\"node\\": \\">=10\\"
},
\\"main\\": \\"index.js\\",
\\"files\\": [
Expand Down Expand Up @@ -65,7 +65,7 @@ exports[`should set custom license 1`] = `
\\"repository\\": \\"gendalf/\\",
\\"license\\": \\"BSD\\",
\\"engines\\": {
\\"node\\": \\">=6.9\\"
\\"node\\": \\">=10\\"
},
\\"main\\": \\"index.js\\",
\\"files\\": [
Expand Down
47 changes: 37 additions & 10 deletions packages/mrm-task-package/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
// @ts-check
const path = require('path');
const meta = require('user-meta');
const gitUsername = require('git-username');
const { json } = require('mrm-core');

function task(config) {
const { name, url, github, minNode, license } = config
.defaults({ github: gitUsername(), minNode: 6.9, license: 'MIT' })
.defaults(meta)
.require('name', 'url', 'github')
.values();

module.exports = function task({ name, url, github, minNode, license }) {
const packageName = path.basename(process.cwd());
const repository = `${github}/${packageName}`;

Expand Down Expand Up @@ -46,7 +41,39 @@ function task(config) {
}

pkg.save();
}
};

task.description = 'Adds package.json';
module.exports = task;
module.exports.description = 'Adds package.json';
module.exports.parameters = {
name: {
type: 'input',
message: 'Enter your name',
default: meta.name,
validate(value) {
return value ? true : '`name` option is required';
},
},
url: {
type: 'input',
message: 'Enter your site address',
default: meta.url,
},
github: {
type: 'input',
message: 'Enter your GitHub usename or organization name',
default: gitUsername(),
validate(value) {
return value ? true : '`github` option is required';
},
},
minNode: {
type: 'input',
message: 'Enter minimum supported Node.js version',
default: 10,
},
license: {
type: 'input',
message: 'Enter project license',
default: 'MIT',
},
};
18 changes: 11 additions & 7 deletions packages/mrm-task-package/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jest.mock('mrm-core/src/util/log', () => ({
}));

const path = require('path');
const { getConfigGetter } = require('mrm');
const { getTaskOptions } = require('mrm');
const vol = require('memfs').vol;
const task = require('./index');

Expand All @@ -20,19 +20,21 @@ afterEach(() => {
process.chdir('/');
});

it('should add package.json', () => {
it('should add package.json', async () => {
// The task will use the folder name as a package name
vol.mkdirpSync(__dirname);
process.chdir(__dirname);

task(getConfigGetter(options));
task(await getTaskOptions(task, false, options));

expect(vol.toJSON()[path.join(__dirname, 'package.json')]).toMatchSnapshot();
});

it('should set custom Node.js version', () => {
it('should set custom Node.js version', async () => {
task(
getConfigGetter(
await getTaskOptions(
task,
false,
Object.assign({}, options, {
minNode: '9.1',
})
Expand All @@ -41,9 +43,11 @@ it('should set custom Node.js version', () => {
expect(vol.toJSON()['/package.json']).toMatchSnapshot();
});

it('should set custom license', () => {
it('should set custom license', async () => {
task(
getConfigGetter(
await getTaskOptions(
task,
false,
Object.assign({}, options, {
license: 'BSD',
})
Expand Down

0 comments on commit 497807e

Please sign in to comment.