generator-verdaccio-plugin 6.0.0-next-8.27 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +6 -6
- package/README.md +6 -76
- package/generators/app/index.d.ts +11 -0
- package/generators/app/index.js +131 -122
- package/generators/app/templates/auth/_package.json +3 -16
- package/generators/app/templates/auth/src/auth-plugin.ts +102 -0
- package/generators/app/templates/auth/src/index.ts +3 -90
- package/generators/app/templates/auth/types/index.ts +1 -1
- package/generators/app/templates/common/_package.json +26 -0
- package/generators/app/templates/common/npmignore +1 -1
- package/generators/app/templates/common/nvmrc +1 -0
- package/generators/app/templates/middleware/_package.json +3 -17
- package/generators/app/templates/middleware/src/index.ts +3 -40
- package/generators/app/templates/middleware/src/middleware-plugin.ts +40 -0
- package/generators/app/templates/middleware/types/index.ts +1 -1
- package/generators/app/templates/storage/_package.json +3 -15
- package/generators/app/templates/storage/src/index.ts +5 -1
- package/generators/app/templates/storage/src/storage-plugin.ts +70 -0
- package/generators/app/templates/storage/types/index.ts +1 -1
- package/package.json +50 -26
- package/generators/app/index.js.map +0 -1
- package/generators/app/templates/common/eslintignore +0 -2
- package/generators/app/templates/common/eslintrc +0 -12
- package/generators/app/templates/common/index.js +0 -15
- package/generators/app/templates/common/jest.config.js +0 -4
- package/generators/app/templates/storage/src/PackageStorage.ts +0 -175
- package/generators/app/templates/storage/src/plugin.ts +0 -134
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
MIT License
|
|
1
|
+
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2024 Juan Picado <@jotadeveloper> <juanpicado19@gmail.com>
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
9
9
|
copies of the Software, and to permit persons to whom the Software is
|
|
10
10
|
furnished to do so, subject to the following conditions:
|
|
11
11
|
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
|
13
|
-
copies or substantial portions of the Software.
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
14
|
|
|
15
15
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
16
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
17
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
SOFTWARE.
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
# generator-verdaccio-plugin
|
|
1
|
+
# generator-verdaccio-plugin
|
|
2
2
|
|
|
3
|
-
[](https://verdaccio.org/docs)
|
|
9
|
-
[](https://discord.com/channels/388674437219745793)
|
|
10
|
-
[](https://bsky.app/profile/verdaccio.org)
|
|
11
|
-
[](https://opencollective.com/verdaccio/contribute)
|
|
12
|
-
[](https://opencollective.com/verdaccio/contribute)
|
|
13
|
-
|
|
14
|
-
[](https://www.npmjs.com/package/verdaccio)
|
|
15
|
-
[](https://hub.docker.com/r/verdaccio/verdaccio)
|
|
16
|
-
[](https://github.com/verdaccio/verdaccio/stargazers)
|
|
3
|
+
[](https://www.npmjs.com/package/generator-verdaccio-plugin)
|
|
4
|
+
[](https://www.npmjs.com/package/generator-verdaccio-plugin)
|
|
5
|
+
[](https://opencollective.com/verdaccio)
|
|
6
|
+
[](http://chat.verdaccio.org/)
|
|
17
7
|
|
|
18
8
|
Verdaccio plugin generator based in [Yeoman](http://yeoman.io) aims to help to scaffold plugins development
|
|
19
9
|
|
|
@@ -43,66 +33,6 @@ yo verdaccio-plugin
|
|
|
43
33
|
- [Anix](https://github.com/anikethsaha)
|
|
44
34
|
- [Juan Picado](https://github.com/juanpicado)
|
|
45
35
|
|
|
46
|
-
## Donations
|
|
47
|
-
|
|
48
|
-
Verdaccio is run by **volunteers**; nobody is working full-time on it. If you find this project to be useful and would like to support its development, consider making a donation - **your logo might end up in this readme.** 😉
|
|
49
|
-
|
|
50
|
-
**[Donate](https://opencollective.com/verdaccio)** 💵👍🏻 starting from _\$1/month_ or just one single contribution.
|
|
51
|
-
|
|
52
|
-
## Report a vulnerability
|
|
53
|
-
|
|
54
|
-
If you want to report a security vulnerability, please follow the steps which we have defined for you in our [security policy](https://github.com/verdaccio/verdaccio/security/policy).
|
|
55
|
-
|
|
56
|
-
## Open Collective Sponsors
|
|
57
|
-
|
|
58
|
-
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/verdaccio/contribute)]
|
|
59
|
-
|
|
60
|
-
[](https://opencollective.com/verdaccio/sponsor/0/website)
|
|
61
|
-
[](https://opencollective.com/verdaccio/sponsor/1/website)
|
|
62
|
-
[](https://opencollective.com/verdaccio/sponsor/2/website)
|
|
63
|
-
[](https://opencollective.com/verdaccio/sponsor/3/website)
|
|
64
|
-
[](https://opencollective.com/verdaccio/sponsor/4/website)
|
|
65
|
-
[](https://opencollective.com/verdaccio/sponsor/5/website)
|
|
66
|
-
[](https://opencollective.com/verdaccio/sponsor/6/website)
|
|
67
|
-
[](https://opencollective.com/verdaccio/sponsor/7/website)
|
|
68
|
-
[](https://opencollective.com/verdaccio/sponsor/8/website)
|
|
69
|
-
[](https://opencollective.com/verdaccio/sponsor/9/website)
|
|
70
|
-
|
|
71
|
-
## Open Collective Backers
|
|
72
|
-
|
|
73
|
-
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/verdaccio/contribute)]
|
|
74
|
-
|
|
75
|
-
[](https://opencollective.com/verdaccio/contributes)
|
|
76
|
-
|
|
77
|
-
## Special Thanks
|
|
78
|
-
|
|
79
|
-
Thanks to the following companies to help us to achieve our goals providing free open source licenses.
|
|
80
|
-
|
|
81
|
-
[](https://www.jetbrains.com/)
|
|
82
|
-
[](https://crowdin.com/)
|
|
83
|
-
|
|
84
|
-
## Contributors
|
|
85
|
-
|
|
86
|
-
This project exists thanks to all the people who contribute. [[Contribute](https://github.com/verdaccio/verdaccio/blob/master/CONTRIBUTING.md)].
|
|
87
|
-
|
|
88
|
-
[](https://github.com/verdaccio/verdaccio/graphs/contributors)
|
|
89
|
-
|
|
90
|
-
## FAQ / Contact / Troubleshoot
|
|
91
|
-
|
|
92
|
-
If you have any issue you can try the following options. Do not hesitate to ask or check our issues database. Perhaps someone has asked already what you are looking for.
|
|
93
|
-
|
|
94
|
-
- [Blog](https://verdaccio.org/blog/)
|
|
95
|
-
- [Donations](https://opencollective.com/verdaccio)
|
|
96
|
-
- [Reporting an issue](https://github.com/verdaccio/verdaccio/blob/master/CONTRIBUTING.md#reporting-a-bug)
|
|
97
|
-
- [Running discussions](https://github.com/orgs/verdaccio/discussions)
|
|
98
|
-
- [Chat](https://discord.com/channels/388674437219745793)
|
|
99
|
-
- [Logos](https://verdaccio.org/docs/logo)
|
|
100
|
-
- [Docker Examples](https://github.com/verdaccio/verdaccio/tree/master/docker-examples)
|
|
101
|
-
- [FAQ](https://github.com/verdaccio/verdaccio/issues?utf8=%E2%9C%93&q=is%3Aissue%20label%3Aquestion%20)
|
|
102
|
-
|
|
103
36
|
## License
|
|
104
37
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
The Verdaccio documentation and logos (excluding /thanks, e.g., .md, .png, .sketch files within the /assets folder) are
|
|
108
|
-
[Creative Commons licensed](https://creativecommons.org/licenses/by/4.0/).
|
|
38
|
+
MIT © [Juan Picado <@jotadeveloper>]()
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Generator from 'yeoman-generator';
|
|
2
|
+
export default class PluginGenerator extends Generator {
|
|
3
|
+
private props;
|
|
4
|
+
private projectName;
|
|
5
|
+
private destinationPathName;
|
|
6
|
+
constructor(args: string | string[], opts: Record<string, unknown>);
|
|
7
|
+
prompting(): Promise<void>;
|
|
8
|
+
packageJSON(): void;
|
|
9
|
+
writing(): void;
|
|
10
|
+
install(): void;
|
|
11
|
+
}
|
package/generators/app/index.js
CHANGED
|
@@ -1,125 +1,134 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
7
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
+
const node_path_1 = require("node:path");
|
|
9
|
+
const yeoman_generator_1 = __importDefault(require("yeoman-generator"));
|
|
10
|
+
const yosay_1 = __importDefault(require("yosay"));
|
|
11
|
+
const package_json_1 = __importDefault(require("../../package.json"));
|
|
12
|
+
class PluginGenerator extends yeoman_generator_1.default {
|
|
13
|
+
props = {};
|
|
14
|
+
projectName = 'verdaccio-';
|
|
15
|
+
destinationPathName = '';
|
|
16
|
+
constructor(args, opts) {
|
|
17
|
+
super(args, opts);
|
|
18
|
+
}
|
|
19
|
+
async prompting() {
|
|
20
|
+
this.log((0, yosay_1.default)(`Welcome to ${chalk_1.default.red('generator-verdaccio-plugin')} plugin generator!`));
|
|
21
|
+
const answers = await this.prompt([
|
|
22
|
+
{
|
|
23
|
+
type: 'list',
|
|
24
|
+
name: 'pluginType',
|
|
25
|
+
message: 'What kind of plugin do you want to create?',
|
|
26
|
+
default: process.env.PLUGIN_TYPE ?? 'auth',
|
|
27
|
+
choices: [
|
|
28
|
+
{ name: 'Auth', value: 'auth' },
|
|
29
|
+
{ name: 'Storage', value: 'storage' },
|
|
30
|
+
{ name: 'Middleware', value: 'middleware' },
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
type: 'input',
|
|
35
|
+
name: 'name',
|
|
36
|
+
message: 'What\'s the plugin name? The prefix (verdaccio-xxx) will be added automatically',
|
|
37
|
+
default: process.env.PLUGIN_NAME ?? 'my-plugin',
|
|
38
|
+
validate: (input) => {
|
|
39
|
+
if (!input) {
|
|
40
|
+
return 'Name cannot be empty';
|
|
41
|
+
}
|
|
42
|
+
if (input.startsWith('verdaccio-')) {
|
|
43
|
+
return 'Do not include the verdaccio- prefix';
|
|
44
|
+
}
|
|
45
|
+
return true;
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
type: 'input',
|
|
50
|
+
name: 'description',
|
|
51
|
+
message: 'Please, describe your plugin',
|
|
52
|
+
default: 'An amazing verdaccio plugin',
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
type: 'input',
|
|
56
|
+
name: 'githubUsername',
|
|
57
|
+
message: 'GitHub username or Organization',
|
|
58
|
+
validate: (input) => Boolean(input) || 'GitHub username is required',
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
type: 'input',
|
|
62
|
+
name: 'authorName',
|
|
63
|
+
message: 'Author\'s Name',
|
|
64
|
+
store: true,
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
type: 'input',
|
|
68
|
+
name: 'authorEmail',
|
|
69
|
+
message: 'Author\'s Email',
|
|
70
|
+
store: true,
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
type: 'input',
|
|
74
|
+
name: 'keywords',
|
|
75
|
+
message: 'Type your keywords (comma separated)',
|
|
76
|
+
filter: (keywords) => lodash_1.default.uniq(lodash_1.default.words(keywords).concat(['verdaccio'])),
|
|
77
|
+
},
|
|
78
|
+
]);
|
|
79
|
+
this.props = {
|
|
80
|
+
...answers,
|
|
81
|
+
license: 'MIT',
|
|
82
|
+
};
|
|
83
|
+
this.projectName = `verdaccio-${answers.name}`;
|
|
84
|
+
this.destinationPathName = (0, node_path_1.resolve)(this.projectName);
|
|
85
|
+
this.props.name = this.projectName;
|
|
86
|
+
if (answers.githubUsername) {
|
|
87
|
+
this.props.repository = `${answers.githubUsername}/${answers.name}`;
|
|
46
88
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
this.projectName = `verdaccio-${name}`;
|
|
92
|
-
|
|
93
|
-
// @ts-ignore
|
|
94
|
-
this.destinationPathName = (0, _nodePath.resolve)(this.projectName);
|
|
95
|
-
// @ts-ignore
|
|
96
|
-
this.props.name = this.projectName;
|
|
97
|
-
}.bind(this));
|
|
98
|
-
}
|
|
99
|
-
packageJSON() {
|
|
100
|
-
const {
|
|
101
|
-
pluginType
|
|
102
|
-
} = this.props;
|
|
103
|
-
const pkgJsonLocation = `${pluginType}/_package.json`;
|
|
104
|
-
this.fs.copyTpl(this.templatePath(pkgJsonLocation), this.destinationPath((0, _nodePath.resolve)(this.destinationPathName, 'package.json')), this.props);
|
|
105
|
-
}
|
|
106
|
-
writing() {
|
|
107
|
-
this.fs.copy(this.templatePath(`common/gitignore`), this.destinationPath((0, _nodePath.resolve)(this.destinationPathName, '.gitignore')));
|
|
108
|
-
this.fs.copy(this.templatePath(`common/npmignore`), this.destinationPath((0, _nodePath.resolve)(this.destinationPathName, '.npmignore')));
|
|
109
|
-
this.fs.copy(this.templatePath(`common/jest.config.js`), this.destinationPath((0, _nodePath.resolve)(this.destinationPathName, 'jest.config.js')));
|
|
110
|
-
this.fs.copyTpl(this.templatePath(`common/README.md`), this.destinationPath((0, _nodePath.resolve)(this.destinationPathName, 'README.md')), this.props);
|
|
111
|
-
this.fs.copyTpl(this.templatePath(`common/eslintrc`), this.destinationPath((0, _nodePath.resolve)(this.destinationPathName, '.eslintrc')), this.props);
|
|
112
|
-
this.fs.copyTpl(this.templatePath(`common/eslintignore`), this.destinationPath((0, _nodePath.resolve)(this.destinationPathName, '.eslintignore')), this.props);
|
|
113
|
-
this.fs.copy(this.templatePath(`${this.props.pluginType}/src`), this.destinationPath((0, _nodePath.resolve)(this.destinationPathName, 'src')));
|
|
114
|
-
this.fs.copy(this.templatePath(`common/index.js`), this.destinationPath((0, _nodePath.resolve)(this.destinationPathName, `index.js`)));
|
|
115
|
-
this.fs.copy(this.templatePath(`common/tsconfig.json`), this.destinationPath((0, _nodePath.resolve)(this.destinationPathName, 'tsconfig.json')));
|
|
116
|
-
this.fs.copy(this.templatePath(`${this.props.pluginType}/types`), this.destinationPath((0, _nodePath.resolve)(this.destinationPathName, 'types')));
|
|
117
|
-
this.fs.copy(this.templatePath(`common/editorconfig`), this.destinationPath((0, _nodePath.resolve)(this.destinationPathName, '.editorconfig')));
|
|
118
|
-
}
|
|
119
|
-
install() {
|
|
120
|
-
process.chdir(this.projectName);
|
|
121
|
-
// this.installDependencies({ npm: true, bower: false });
|
|
122
|
-
}
|
|
89
|
+
}
|
|
90
|
+
packageJSON() {
|
|
91
|
+
const { pluginType } = this.props;
|
|
92
|
+
if (!pluginType) {
|
|
93
|
+
this.log.error('pluginType is required');
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const pkg = this.fs.readJSON(this.templatePath(`${pluginType}/_package.json`));
|
|
97
|
+
// devDependencies
|
|
98
|
+
pkg.devDependencies['@types/node'] = package_json_1.default.devDependencies['@types/node'];
|
|
99
|
+
pkg.devDependencies['@types/express'] = package_json_1.default.devDependencies['@types/express'];
|
|
100
|
+
pkg.devDependencies['@types/debug'] = package_json_1.default.devDependencies['@types/debug'];
|
|
101
|
+
pkg.devDependencies['typescript'] = package_json_1.default.devDependencies['typescript'];
|
|
102
|
+
pkg.devDependencies['@verdaccio/types'] = package_json_1.default.devDependencies['@verdaccio/types'];
|
|
103
|
+
// required by verdaccio types
|
|
104
|
+
pkg.devDependencies['@types/jsonwebtoken'] = package_json_1.default.devDependencies['@types/jsonwebtoken'];
|
|
105
|
+
// dependencies
|
|
106
|
+
pkg.dependencies['@verdaccio/core'] = package_json_1.default.dependencies['@verdaccio/core'];
|
|
107
|
+
pkg.dependencies['@verdaccio/config'] = package_json_1.default.dependencies['@verdaccio/config'];
|
|
108
|
+
pkg.dependencies['debug'] = package_json_1.default.dependencies['debug'];
|
|
109
|
+
if (pluginType === 'auth') {
|
|
110
|
+
pkg.devDependencies['@verdaccio/auth'] = package_json_1.default.devDependencies['@verdaccio/auth'];
|
|
111
|
+
}
|
|
112
|
+
else if (pluginType === 'middleware') {
|
|
113
|
+
pkg.dependencies['express'] = package_json_1.default.dependencies['express'];
|
|
114
|
+
}
|
|
115
|
+
this.fs.writeJSON(this.templatePath(`${pluginType}/_package.json`), pkg);
|
|
116
|
+
this.fs.copyTpl(this.templatePath(`${pluginType}/_package.json`), this.destinationPath((0, node_path_1.resolve)(this.destinationPathName, 'package.json')), this.props);
|
|
117
|
+
}
|
|
118
|
+
writing() {
|
|
119
|
+
const dest = (path) => this.destinationPath((0, node_path_1.resolve)(this.destinationPathName, path));
|
|
120
|
+
this.fs.copy(this.templatePath('common/gitignore'), dest('.gitignore'));
|
|
121
|
+
this.fs.copy(this.templatePath('common/npmignore'), dest('.npmignore'));
|
|
122
|
+
this.fs.copy(this.templatePath('common/nvmrc'), dest('.nvmrc'));
|
|
123
|
+
this.fs.copyTpl(this.templatePath('common/README.md'), dest('README.md'), this.props);
|
|
124
|
+
this.fs.copy(this.templatePath(`${this.props.pluginType}/src`), dest('src'));
|
|
125
|
+
// this.fs.copy(this.templatePath('common/index.ts'), dest('index.ts'));
|
|
126
|
+
this.fs.copy(this.templatePath('common/tsconfig.json'), dest('tsconfig.json'));
|
|
127
|
+
this.fs.copy(this.templatePath(`${this.props.pluginType}/types`), dest('types'));
|
|
128
|
+
this.fs.copy(this.templatePath('common/editorconfig'), dest('.editorconfig'));
|
|
129
|
+
}
|
|
130
|
+
install() {
|
|
131
|
+
this.destinationRoot(this.projectName);
|
|
132
|
+
}
|
|
123
133
|
}
|
|
124
|
-
|
|
125
|
-
//# sourceMappingURL=index.js.map
|
|
134
|
+
exports.default = PluginGenerator;
|
|
@@ -7,27 +7,14 @@
|
|
|
7
7
|
"engines": {
|
|
8
8
|
"node": ">=18"
|
|
9
9
|
},
|
|
10
|
-
"dependencies": {
|
|
11
|
-
|
|
12
|
-
},
|
|
13
|
-
"devDependencies": {
|
|
14
|
-
"@types/jest": "27.5.1",
|
|
15
|
-
"@types/node": "12.12.5",
|
|
16
|
-
"@types/express": "4.17.13",
|
|
17
|
-
"@typescript-eslint/eslint-plugin": "5.26.0",
|
|
18
|
-
"@typescript-eslint/parser": "5.26.0",
|
|
19
|
-
"@verdaccio/types": "10.5.2",
|
|
20
|
-
"eslint": "8.21.0",
|
|
21
|
-
"jest": "28.1.3",
|
|
22
|
-
"typescript": "4.7.4"
|
|
23
|
-
},
|
|
10
|
+
"dependencies": {},
|
|
11
|
+
"devDependencies": {},
|
|
24
12
|
"keywords": ["<%= keywords %>]"],
|
|
25
13
|
"license": "<%= license %>",
|
|
26
14
|
"repository": "<%= repository %>",
|
|
27
15
|
"author": "<%= authorName %> <<%= authorEmail %>>",
|
|
28
16
|
"scripts": {
|
|
29
17
|
"build": "tsc",
|
|
30
|
-
"test": "
|
|
31
|
-
"lint": "eslint \"**/*.{js,ts}\""
|
|
18
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
32
19
|
}
|
|
33
20
|
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import debugCore from 'debug';
|
|
2
|
+
|
|
3
|
+
import {API_ERROR, errorUtils, pluginUtils} from '@verdaccio/core';
|
|
4
|
+
import {Config, Logger, PackageAccess, RemoteUser} from '@verdaccio/types';
|
|
5
|
+
|
|
6
|
+
import {CustomConfig} from '../types/index';
|
|
7
|
+
|
|
8
|
+
const {Plugin} = pluginUtils;
|
|
9
|
+
|
|
10
|
+
// Initialize debug logging
|
|
11
|
+
// Replace 'custom-auth-plugin' with your plugin name
|
|
12
|
+
// This code is meant to help during development and debugging
|
|
13
|
+
const debug = debugCore('verdaccio:plugin:custom-auth-plugin');
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Custom Verdaccio Authenticate Plugin.
|
|
17
|
+
*/
|
|
18
|
+
export default class AuthCustomPlugin
|
|
19
|
+
extends Plugin<CustomConfig>
|
|
20
|
+
implements pluginUtils.Auth<CustomConfig> {
|
|
21
|
+
private _logger: Logger;
|
|
22
|
+
private _config: {};
|
|
23
|
+
private _app_config: Config;
|
|
24
|
+
public constructor(config: CustomConfig, appOptions: pluginUtils.PluginOptions) {
|
|
25
|
+
super(config, appOptions);
|
|
26
|
+
this._config = config;
|
|
27
|
+
this._logger = appOptions.logger;
|
|
28
|
+
this._app_config = appOptions.config;
|
|
29
|
+
debug('AuthCustomPlugin config: %o', this._config);
|
|
30
|
+
debug('App Config: %o', this._app_config);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Authenticate an user.
|
|
34
|
+
* @param user user to log
|
|
35
|
+
* @param password provided password
|
|
36
|
+
* @param cb callback function
|
|
37
|
+
*/
|
|
38
|
+
public authenticate(user: string, password: string, cb: pluginUtils.AuthCallback): void {
|
|
39
|
+
debug('Authenticating user: %o', user);
|
|
40
|
+
debug('Password: %o', password);
|
|
41
|
+
|
|
42
|
+
// TODO: replace this code with your own authentication logic
|
|
43
|
+
// TODO: replace this code with your own authentication logic
|
|
44
|
+
// TODO: replace this code with your own authentication logic
|
|
45
|
+
if (password === 'verdaccio') {
|
|
46
|
+
this._logger.info(`User @{user} authenticated successfully`);
|
|
47
|
+
debug('User @{user} authenticated successfully', {user});
|
|
48
|
+
return cb(null, [user]);
|
|
49
|
+
} else {
|
|
50
|
+
this._logger.error(`User @{user} authentication failed`);
|
|
51
|
+
return cb(errorUtils.getUnauthorized(API_ERROR.BAD_USERNAME_PASSWORD));
|
|
52
|
+
}
|
|
53
|
+
// TODO: replace this code with your own authentication logic
|
|
54
|
+
// TODO: replace this code with your own authentication logic
|
|
55
|
+
// TODO: replace this code with your own authentication logic
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public allow_access(user: RemoteUser, pkg: PackageAccess, cb: pluginUtils.AccessCallback): void {
|
|
59
|
+
debug('allow access for %o', user);
|
|
60
|
+
debug('package access list %o', pkg?.access);
|
|
61
|
+
// TODO: replace this code with your own access logic
|
|
62
|
+
// TODO: replace this code with your own access logic
|
|
63
|
+
// TODO: replace this code with your own access logic
|
|
64
|
+
if (pkg?.access?.includes('$anonymous')) {
|
|
65
|
+
debug('%o has been granted access', user?.name);
|
|
66
|
+
this._logger.info('Anonymous user granted access to package');
|
|
67
|
+
return cb(null, true);
|
|
68
|
+
} else if (pkg?.access?.includes('$all')) {
|
|
69
|
+
debug('%o has been granted access', user?.name);
|
|
70
|
+
this._logger.info('All users granted access to package');
|
|
71
|
+
return cb(null, false);
|
|
72
|
+
}
|
|
73
|
+
// TODO: replace this code with your own access logic
|
|
74
|
+
// TODO: replace this code with your own access logic
|
|
75
|
+
// TODO: replace this code with your own access logic
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public allow_publish(
|
|
79
|
+
user: RemoteUser,
|
|
80
|
+
pkg: PackageAccess,
|
|
81
|
+
cb: pluginUtils.AuthAccessCallback,
|
|
82
|
+
): void {
|
|
83
|
+
// TODO: replace this code with your own publish logic
|
|
84
|
+
// TODO: replace this code with your own publish logic
|
|
85
|
+
// TODO: replace this code with your own publish logic
|
|
86
|
+
// TODO: replace this code with your own publish logic
|
|
87
|
+
debug('allow publish for %o', user);
|
|
88
|
+
debug('package publish access list %o', pkg?.publish);
|
|
89
|
+
if (user?.name === 'verdaccio') {
|
|
90
|
+
debug('%o has been granted to publish', user?.name);
|
|
91
|
+
return cb(null, true);
|
|
92
|
+
} else {
|
|
93
|
+
const err = errorUtils.getForbidden('not allowed to publish package');
|
|
94
|
+
this._logger.error('%o not allowed to publish package');
|
|
95
|
+
debug('%o not allowed to publish package err %o', user?.name, err.message);
|
|
96
|
+
return cb(err);
|
|
97
|
+
}
|
|
98
|
+
// TODO: replace this code with your own publish logic
|
|
99
|
+
// TODO: replace this code with your own publish logic
|
|
100
|
+
// TODO: replace this code with your own publish logic
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -1,92 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
AuthAccessCallback,
|
|
4
|
-
AuthCallback,
|
|
5
|
-
IPluginAuth,
|
|
6
|
-
Logger,
|
|
7
|
-
PackageAccess,
|
|
8
|
-
PluginOptions,
|
|
9
|
-
RemoteUser,
|
|
10
|
-
} from '@verdaccio/types';
|
|
1
|
+
import AuthPlugin from './auth-plugin';
|
|
11
2
|
|
|
12
|
-
|
|
3
|
+
export {AuthPlugin};
|
|
13
4
|
|
|
14
|
-
|
|
15
|
-
* Custom Verdaccio Authenticate Plugin.
|
|
16
|
-
*/
|
|
17
|
-
export default class AuthCustomPlugin implements IPluginAuth<CustomConfig> {
|
|
18
|
-
public logger: Logger;
|
|
19
|
-
private foo: string;
|
|
20
|
-
public constructor(config: CustomConfig, options: PluginOptions<CustomConfig>) {
|
|
21
|
-
this.logger = options.logger;
|
|
22
|
-
this.foo = config.foo;
|
|
23
|
-
return this;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Authenticate an user.
|
|
27
|
-
* @param user user to log
|
|
28
|
-
* @param password provided password
|
|
29
|
-
* @param cb callback function
|
|
30
|
-
*/
|
|
31
|
-
public authenticate(user: string, password: string, cb: AuthCallback): void {
|
|
32
|
-
/**
|
|
33
|
-
* This code is just an example for demostration purpose
|
|
34
|
-
if (this.foo) {
|
|
35
|
-
cb(null, ['group-foo', 'group-bar']);
|
|
36
|
-
} else {
|
|
37
|
-
cb(getInternalError("error, try again"), false);
|
|
38
|
-
}
|
|
39
|
-
*/
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Triggered on each access request
|
|
44
|
-
* @param user
|
|
45
|
-
* @param pkg
|
|
46
|
-
* @param cb
|
|
47
|
-
*/
|
|
48
|
-
public allow_access(user: RemoteUser, pkg: PackageAccess, cb: AuthAccessCallback): void {
|
|
49
|
-
/**
|
|
50
|
-
* This code is just an example for demostration purpose
|
|
51
|
-
if (user.name === this.foo && pkg?.access?.includes[user.name]) {
|
|
52
|
-
this.logger.debug({name: user.name}, 'your package has been granted for @{name}');
|
|
53
|
-
cb(null, true)
|
|
54
|
-
} else {
|
|
55
|
-
this.logger.error({name: user.name}, '@{name} is not allowed to access this package');
|
|
56
|
-
cb(getInternalError("error, try again"), false);
|
|
57
|
-
}
|
|
58
|
-
*/
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Triggered on each publish request
|
|
63
|
-
* @param user
|
|
64
|
-
* @param pkg
|
|
65
|
-
* @param cb
|
|
66
|
-
*/
|
|
67
|
-
public allow_publish(user: RemoteUser, pkg: PackageAccess, cb: AuthAccessCallback): void {
|
|
68
|
-
/**
|
|
69
|
-
* This code is just an example for demostration purpose
|
|
70
|
-
if (user.name === this.foo && pkg?.access?.includes[user.name]) {
|
|
71
|
-
this.logger.debug({name: user.name}, '@{name} has been granted to publish');
|
|
72
|
-
cb(null, true)
|
|
73
|
-
} else {
|
|
74
|
-
this.logger.error({name: user.name}, '@{name} is not allowed to publish this package');
|
|
75
|
-
cb(getInternalError("error, try again"), false);
|
|
76
|
-
}
|
|
77
|
-
*/
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
public allow_unpublish(user: RemoteUser, pkg: PackageAccess, cb: AuthAccessCallback): void {
|
|
81
|
-
/**
|
|
82
|
-
* This code is just an example for demostration purpose
|
|
83
|
-
if (user.name === this.foo && pkg?.access?.includes[user.name]) {
|
|
84
|
-
this.logger.debug({name: user.name}, '@{name} has been granted to unpublish');
|
|
85
|
-
cb(null, true)
|
|
86
|
-
} else {
|
|
87
|
-
this.logger.error({name: user.name}, '@{name} is not allowed to publish this package');
|
|
88
|
-
cb(getInternalError("error, try again"), false);
|
|
89
|
-
}
|
|
90
|
-
*/
|
|
91
|
-
}
|
|
92
|
-
}
|
|
5
|
+
export default AuthPlugin;
|