diff --git a/.changeset/silver-panthers-sort.md b/.changeset/silver-panthers-sort.md new file mode 100644 index 00000000..96206e70 --- /dev/null +++ b/.changeset/silver-panthers-sort.md @@ -0,0 +1,6 @@ +--- +"generator-verdaccio-plugin": major +--- + +fix: broken build + \ No newline at end of file diff --git a/.eslintignore b/.eslintignore index 8937c73a..18737932 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1,3 @@ coverage/ -build/* +generators/* +src/app/templates/typescript/common/index.js diff --git a/.gitignore b/.gitignore index 6a353bab..5fd6f5e6 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ yarn-error.log .idea/* generators/* .pnpm-store/* +.pnpm-debug.log diff --git a/.prettierignore b/.prettierignore index 40f3a8e2..7b1d381b 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,2 +1,2 @@ node_modules -build/* +generators/* diff --git a/__tests__/generator-template.test.js b/__tests__/generator-template.test.js index e10cb3f3..3ae1d027 100644 --- a/__tests__/generator-template.test.js +++ b/__tests__/generator-template.test.js @@ -3,10 +3,10 @@ const os = require('os'); const fs = require('fs'); const assert = require('yeoman-assert'); const helpers = require('yeoman-test'); -const constants = require('../test/constants'); +const constants = require('../helpers/constants'); describe('template generator', function() { - jest.setTimeout(10000); + // jest.setTimeout(10000); const name = 'test'; const description = 'An amazing verdaccio plugin'; const githubUsername = 'testing'; @@ -27,7 +27,7 @@ describe('template generator', function() { const lang = 'typescript'; test('should check storage files', function(done) { - helpers.run(path.join(__dirname, '../generators/app')).inDir(tempRoot).withPrompts({ + helpers.run(path.join(__dirname, '../src/app')).inDir(tempRoot).withPrompts({ name, lang, pluginType: 'storage', @@ -41,7 +41,7 @@ describe('template generator', function() { }).then(function() { assert.file([ ...constants.map((item) => getBuildAsset(tempRoot, item)), - getBuildAsset(tempRoot, '/index.ts'), + getBuildAsset(tempRoot, '/index.js'), getBuildAsset(tempRoot, '/types/index.ts'), getBuildAsset(tempRoot, '/tsconfig.json'), getBuildAsset(tempRoot, '/src/index.ts'), @@ -53,7 +53,7 @@ describe('template generator', function() { }); test('should check auth files', function(done) { - helpers.run(path.join(__dirname, '../generators/app')).inDir(tempRoot).withPrompts({ + helpers.run(path.join(__dirname, '../src/app')).inDir(tempRoot).withPrompts({ name, lang, pluginType: 'auth', @@ -68,7 +68,7 @@ describe('template generator', function() { assert.file([ ...constants.map((item) => getBuildAsset(tempRoot, item)), getBuildAsset(tempRoot, '/src/index.ts'), - getBuildAsset(tempRoot, '/index.ts'), + getBuildAsset(tempRoot, '/index.js'), getBuildAsset(tempRoot, '/types/index.ts'), getBuildAsset(tempRoot, '/tsconfig.json'), ]); @@ -77,7 +77,7 @@ describe('template generator', function() { }); test('should check middleware files', function(done) { - helpers.run(path.join(__dirname, '../generators/app')).inDir(tempRoot).withPrompts({ + helpers.run(path.join(__dirname, '../src/app')).inDir(tempRoot).withPrompts({ name, lang, pluginType: 'middleware', @@ -92,7 +92,7 @@ describe('template generator', function() { assert.file([ ...constants.map((item) => getBuildAsset(tempRoot, item)), getBuildAsset(tempRoot, '/src/index.ts'), - getBuildAsset(tempRoot, '/index.ts'), + getBuildAsset(tempRoot, '/index.js'), getBuildAsset(tempRoot, '/types/index.ts'), getBuildAsset(tempRoot, '/tsconfig.json'), ]); diff --git a/test/constants.js b/helpers/constants.js similarity index 100% rename from test/constants.js rename to helpers/constants.js diff --git a/package.json b/package.json index 59b371f3..8acf346f 100644 --- a/package.json +++ b/package.json @@ -91,7 +91,7 @@ "release": "standard-version -a -s", "type-check": "tsc --noEmit -p tsconfig.build.json", "build:types": "tsc --emitDeclarationOnly -p tsconfig.build.json", - "build": "babel src/ --out-dir generators/ --copy-files --extensions \".ts,.tsx\" --source-maps", + "build": "babel src/ --out-dir generators/ --copy-files --extensions \".ts,.tsx\" --source-maps --ignore src/app/templates", "test": "jest", "lint": "eslint --max-warnings 0 \"**/*.{js,ts}\"", "changeset": "changeset", diff --git a/src/app/index.ts b/src/app/index.ts index 7130e3ea..845ae313 100644 --- a/src/app/index.ts +++ b/src/app/index.ts @@ -159,12 +159,12 @@ class VerdaccioPluginGenerator extends Generator { this.fs.copy( this.templatePath( - `typescript/common/index.ts`, + `typescript/common/index.js`, ), this.destinationPath( resolve( this.destinationPathName, - `index.ts`, + `index.js`, ), ), ); diff --git a/src/app/templates/typescript/auth/_package.json b/src/app/templates/typescript/auth/_package.json new file mode 100644 index 00000000..fe58298a --- /dev/null +++ b/src/app/templates/typescript/auth/_package.json @@ -0,0 +1,34 @@ +{ + "name": "<%= name %>", + "version": "0.0.1", + "description": "<%= description %>", + "main": "lib/index.js", + "types": "lib/index.d.ts", + "files": ["lib/"], + "engines": { + "node": ">=12" + }, + "dependencies": { + "@verdaccio/commons-api": "latest", + }, + "devDependencies": { + "@types/jest": "27.5.1", + "@types/node": "^12.12.5", + "@types/express": "4.17.13", + "@typescript-eslint/eslint-plugin": "5.26.0", + "@typescript-eslint/parser": "5.26.0", + "@verdaccio/types": "latest", + "eslint": "8.16.0", + "jest": "28.1.1", + "typescript": "4.7.3" + }, + "keywords": ["<%= keywords %>]"], + "license": "<%= license %>", + "repository": "<%= repository %>", + "author": "<%= authorName %> <<%= authorEmail %>>", + "scripts": { + "build": "tsc", + "test": "jest .", + "lint": "eslint \"**/*.{js,ts}\"" + } +} diff --git a/src/app/templates/typescript/auth/src/index.ts b/src/app/templates/typescript/auth/src/index.ts new file mode 100644 index 00000000..fcb26a84 --- /dev/null +++ b/src/app/templates/typescript/auth/src/index.ts @@ -0,0 +1,91 @@ +import { + PluginOptions, + AuthAccessCallback, + AuthCallback, + PackageAccess, + IPluginAuth, + RemoteUser, + Logger, +} from '@verdaccio/types'; + +import {CustomConfig} from '../types/index'; + +/** + * Custom Verdaccio Authenticate Plugin. + */ +export default class AuthCustomPlugin implements IPluginAuth { + public logger: Logger; + private foo: string; + public constructor(config: CustomConfig, options: PluginOptions) { + this.logger = options.logger; + this.foo = config.foo; + return this; + } + /** + * Authenticate an user. + * @param user user to log + * @param password provided password + * @param cb callback function + */ + public authenticate(user: string, password: string, cb: AuthCallback): void { + /** + * This code is just an example for demostration purpose + if (this.foo) { + cb(null, ['group-foo', 'group-bar']); + } else { + cb('error, try again', false); + } + */ + } + + /** + * Triggered on each access request + * @param user + * @param pkg + * @param cb + */ + public allow_access(user: RemoteUser, pkg: PackageAccess, cb: AuthAccessCallback): void { + /** + * This code is just an example for demostration purpose + if (user.name === this.foo && pkg?.access?.includes[user.name]) { + this.logger.debug({name: user.name}, 'your package has been granted for @{name}'); + cb(null, true) + } else { + this.logger.error({name: user.name}, '@{name} is not allowed to access this package'); + cb('error, try again', false); + } + */ + } + + /** + * Triggered on each publish request + * @param user + * @param pkg + * @param cb + */ + public allow_publish(user: RemoteUser, pkg: PackageAccess, cb: AuthAccessCallback): void { + /** + * This code is just an example for demostration purpose + if (user.name === this.foo && pkg?.access?.includes[user.name]) { + this.logger.debug({name: user.name}, '@{name} has been granted to publish'); + cb(null, true) + } else { + this.logger.error({name: user.name}, '@{name} is not allowed to publish this package'); + cb('error, try again', false); + } + */ + } + + public allow_unpublish(user: RemoteUser, pkg: PackageAccess, cb: AuthAccessCallback): void { + /** + * This code is just an example for demostration purpose + if (user.name === this.foo && pkg?.access?.includes[user.name]) { + this.logger.debug({name: user.name}, '@{name} has been granted to unpublish'); + cb(null, true) + } else { + this.logger.error({name: user.name}, '@{name} is not allowed to publish this package'); + cb('error, try again', false); + } + */ + } +} diff --git a/src/app/templates/typescript/auth/types/index.ts b/src/app/templates/typescript/auth/types/index.ts new file mode 100644 index 00000000..aa2a23e2 --- /dev/null +++ b/src/app/templates/typescript/auth/types/index.ts @@ -0,0 +1,5 @@ +import {Config} from '@verdaccio/types'; + +export interface CustomConfig extends Config { + foo: string; +} diff --git a/src/app/templates/typescript/common/README.md b/src/app/templates/typescript/common/README.md new file mode 100644 index 00000000..1ee5c828 --- /dev/null +++ b/src/app/templates/typescript/common/README.md @@ -0,0 +1,22 @@ +# <%= name %> + +<%- (description || '').split('\n').map(function (line) { + return '> ' + line +}).join('\n') %> + +--- + +## development + +See the [verdaccio contributing guide](https://github.com/verdaccio/verdaccio/blob/master/CONTRIBUTING.md) for instructions setting up your development environment. +Once you have completed that, use the following npm tasks. + + - `npm run build` + + Build a distributable archive + + - `npm run test` + + Run unit test + +For more information about any of these commands run `npm run ${task} -- --help`. diff --git a/src/app/templates/typescript/common/editorconfig b/src/app/templates/typescript/common/editorconfig new file mode 100644 index 00000000..d96d43f2 --- /dev/null +++ b/src/app/templates/typescript/common/editorconfig @@ -0,0 +1,12 @@ +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +end_of_line = lf +insert_final_newline = true + +# 2 space indentation +[{.,}*.{js,yml,yaml}] +indent_style = space +indent_size = 2 \ No newline at end of file diff --git a/src/app/templates/typescript/common/eslintignore b/src/app/templates/typescript/common/eslintignore new file mode 100644 index 00000000..491fc359 --- /dev/null +++ b/src/app/templates/typescript/common/eslintignore @@ -0,0 +1,2 @@ +node_modules +lib diff --git a/src/app/templates/typescript/common/eslintrc b/src/app/templates/typescript/common/eslintrc new file mode 100644 index 00000000..11643ef3 --- /dev/null +++ b/src/app/templates/typescript/common/eslintrc @@ -0,0 +1,12 @@ +{ + "root": true, + "parser": "@typescript-eslint/parser", + "plugins": [ + "@typescript-eslint" + ], + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/eslint-recommended", + "plugin:@typescript-eslint/recommended" + ] +} diff --git a/src/app/templates/typescript/common/gitignore b/src/app/templates/typescript/common/gitignore new file mode 100644 index 00000000..f66604ee --- /dev/null +++ b/src/app/templates/typescript/common/gitignore @@ -0,0 +1,3 @@ +npm-debug.log* +node_modules +/lib/ \ No newline at end of file diff --git a/src/app/templates/typescript/common/index.js b/src/app/templates/typescript/common/index.js new file mode 100644 index 00000000..4c8153eb --- /dev/null +++ b/src/app/templates/typescript/common/index.js @@ -0,0 +1,13 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; + +var _index = _interopRequireDefault(require("./lib/index")); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +var _default = _index.default; +exports.default = _default; diff --git a/src/app/templates/typescript/common/index.js~Stashed changes b/src/app/templates/typescript/common/index.js~Stashed changes new file mode 100644 index 00000000..cd711e2d --- /dev/null +++ b/src/app/templates/typescript/common/index.js~Stashed changes @@ -0,0 +1,7 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const index_1 = __importDefault(require("./generators/index")); +exports.default = index_1.default; diff --git a/src/app/templates/typescript/common/jest.config.js b/src/app/templates/typescript/common/jest.config.js new file mode 100644 index 00000000..4523dc5b --- /dev/null +++ b/src/app/templates/typescript/common/jest.config.js @@ -0,0 +1,4 @@ +module.exports = { + name: 'verdaccio-<%= name %>', + preset: 'ts-jest', +}; diff --git a/src/app/templates/typescript/common/npmignore b/src/app/templates/typescript/common/npmignore new file mode 100644 index 00000000..21c57575 --- /dev/null +++ b/src/app/templates/typescript/common/npmignore @@ -0,0 +1,3 @@ +src/ +.eslintrc +test/ diff --git a/src/app/templates/typescript/common/tsconfig.json b/src/app/templates/typescript/common/tsconfig.json new file mode 100644 index 00000000..9e2e0734 --- /dev/null +++ b/src/app/templates/typescript/common/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "target": "esnext", + "module": "commonjs", + "declaration": true, + "allowJs": false, + "noImplicitAny": false, + "strict": true, + "outDir": "./lib", + "allowSyntheticDefaultImports": true, + "esModuleInterop": true + }, + "include": [ + "src/*.ts", + "types/*.ts" + ] +} diff --git a/src/app/templates/typescript/middleware/types/index.ts b/src/app/templates/typescript/middleware/types/index.ts new file mode 100644 index 00000000..aa2a23e2 --- /dev/null +++ b/src/app/templates/typescript/middleware/types/index.ts @@ -0,0 +1,5 @@ +import {Config} from '@verdaccio/types'; + +export interface CustomConfig extends Config { + foo: string; +} diff --git a/test/.eslintrc b/test/.eslintrc deleted file mode 100644 index 603f8176..00000000 --- a/test/.eslintrc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "rules": { - "no-undef": 0 - } -} \ No newline at end of file