Skip to content

Commit 93723aa

Browse files
authored
feat(create): Add support create command (#40)
* feat(create): add "support create" command basic functionality
1 parent 650b141 commit 93723aa

File tree

29 files changed

+761
-27
lines changed

29 files changed

+761
-27
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ A command line tool is provided which supports the following commands:
2323
* show - show the support info for the package tree.
2424
* validate - validate support info for a package, to be used by a
2525
maintainer before publishing.
26+
* create - setup a support declaration for a package.
2627

2728
These commands support the following options:
2829

@@ -47,3 +48,7 @@ npx @pkgjs/support show
4748
```
4849
npx @pkgjs/support validate
4950
```
51+
52+
```
53+
npx @pkgjs/support create
54+
```

doc/command-line-usage.md

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Using the package support tool from the command line
22

3-
There are 2 main uses cases for the package support tool
3+
There are 2 main use cases for the package support tool
44

55
* Package Maintainers - document and communicate expectations to consumers
66
* Package Consumers - understand more about their key dependencies and where they
@@ -164,24 +164,35 @@ where the `support` entry was:
164164
165165
Package maintainers want to add and manage the support information for their modules.
166166
167-
Ultimately we'll want commands help generate the support info, but as a first step
168-
the `validate` command is provided which validates that the info is in the
169-
right format/locations.
167+
[Integration into package.json](https://github.com/nodejs/package-maintenance/blob/HEAD/docs/PACKAGE-SUPPORT.md#integration-into-packagejson)
168+
explains the options for providing support info and what goes into the package.json for
169+
each case.
170170
171-
To add support information a maintainer needs to:
171+
In order to add support information a maintainer can use `create` command.
172172
173-
* add information to the package.json which specifies were to find the support info
174-
* provide a file with the package support info.
173+
`npx @pkgjs/support create` is run from the directory that contains the `package.json` for the package.
174+
It will ask few questions (e.g. what Node.js version your package support or how quickly you are able to respond to issues)
175+
in order to build proper `package-support.json` file.
176+
This command can also build [`backing`](https://github.com/nodejs/package-maintenance/blob/HEAD/docs/PACKAGE-SUPPORT.md#support-backing) field based on your `.github/FUNDING.yml` file or `"funding"` field from `package.json`.
175177
176-
The `validate` command checks that both the information added to the package.json
177-
and the file containing the support info (package-support.json by default) is valid.
178+
`create` command will create `package-support.json` file in current working directory for you
179+
and will update `package.json` in order to set `"support: true"` field.
178180
181+
`create` command has `-y|--yes` flag which does pretty much the same as `npm init -y` but with package support info.
182+
It will create `package-support.json` file with default commonly-used values.
183+
This can be used in case you want to get some basic scaffolding and edit file manually.
179184
180-
[Integration into package.json](https://github.com/nodejs/package-maintenance/blob/HEAD/docs/PACKAGE-SUPPORT.md#integration-into-packagejson)
181-
explains the options for providing support info and what goes into the package.json for
182-
each case.
185+
```shell
186+
npx @pkgjs/support create -y
187+
```
188+
189+
In case package support information was added manually - `@pkgjs/support` also provides
190+
ability to validate this infomation automatically according to official schema.
191+
192+
The `validate` command checks that both the information added to the package.json
193+
and the file containing the support info (package-support.json by default) is valid.
183194
184-
`npx @pkgjs/support validate` is run from the directory that contains the package.json for the package.
195+
`npx @pkgjs/support validate` is run from the directory that contains the `package.json` for the package.
185196
Depending the how the `support` section in the package.json is configured validate will:
186197
187198
* validate the format of the `support` section in the package.json conforms to the

index.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const normalizeUrl = require('normalize-url');
55
const Ajv = require('ajv');
66
const got = require('got');
77
const betterAjvErrors = require('better-ajv-errors');
8+
const create = require('./lib/cli/create');
89

910
let ajv;
1011
let compiledSchema;
@@ -15,6 +16,7 @@ const schema = module.exports.schema = require('./schema.json');
1516
const supportElementSchema = module.exports.schema = require('./support-element-schema.json');
1617

1718
module.exports.defaultPackageSupport = 'package-support.json';
19+
module.exports.create = create;
1820

1921
function getBetterAjvErrorsOptions (cli) {
2022
const options = { format: 'js' };
@@ -128,3 +130,38 @@ module.exports.getSupportData = async (pkg, pkgPath, preferCanonical, basePathOv
128130
}
129131
return supportInfo;
130132
};
133+
134+
/**
135+
* Returns list of target Node.js versions for package-support.json file
136+
*/
137+
module.exports.getNodeJsTargetVersionsList = () => {
138+
return [
139+
'abandoned',
140+
'none',
141+
'all',
142+
'lts',
143+
'active',
144+
'lts_active',
145+
'lts_latest',
146+
'supported',
147+
'current'
148+
];
149+
};
150+
151+
/**
152+
* Returns list of response types for package-support.json file
153+
*/
154+
module.exports.getSupportResponseTypesList = () => {
155+
const schemaOptions = [
156+
'none',
157+
'time-permitting',
158+
'best-effort',
159+
'24-7'
160+
];
161+
162+
for (let daysForResponse = 1; daysForResponse <= 7; daysForResponse++) {
163+
schemaOptions.push(`regular-${daysForResponse}`);
164+
}
165+
166+
return schemaOptions;
167+
};

lib/cli/commands/create.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
const support = require('../../../index.js');
3+
4+
module.exports = function (opts) {
5+
return {
6+
command: 'create',
7+
desc: 'Setup a support declaration for a package',
8+
builder: function (yargs) {
9+
return yargs
10+
.option('yes', {
11+
desc: 'Apply default values',
12+
type: 'boolean',
13+
alias: 'y'
14+
});
15+
},
16+
handler: async function (argv) {
17+
try {
18+
await support.create(argv.y);
19+
console.log('Support info created');
20+
} catch (error) {
21+
console.error(error.message);
22+
}
23+
}
24+
};
25+
};

lib/cli/commands/setup.js

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"versions": [
3+
{
4+
"version": "*",
5+
"target": {
6+
"node": ""
7+
},
8+
"response": {
9+
"type": ""
10+
},
11+
"backing": {}
12+
}
13+
]
14+
}

0 commit comments

Comments
 (0)