Skip to content
This repository has been archived by the owner on Jun 16, 2024. It is now read-only.

Commit

Permalink
fix: broken build
Browse files Browse the repository at this point in the history
  • Loading branch information
juanpicado committed Jun 7, 2022
1 parent 4d5eb42 commit 0a5326d
Show file tree
Hide file tree
Showing 23 changed files with 251 additions and 18 deletions.
6 changes: 6 additions & 0 deletions .changeset/silver-panthers-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"generator-verdaccio-plugin": major
---

fix: broken build

3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
coverage/
build/*
generators/*
src/app/templates/typescript/common/index.js
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ yarn-error.log
.idea/*
generators/*
.pnpm-store/*
.pnpm-debug.log
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
node_modules
build/*
generators/*
16 changes: 8 additions & 8 deletions __tests__/generator-template.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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',
Expand All @@ -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'),
Expand All @@ -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',
Expand All @@ -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'),
]);
Expand All @@ -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',
Expand All @@ -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'),
]);
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
),
),
);
Expand Down
34 changes: 34 additions & 0 deletions src/app/templates/typescript/auth/_package.json
Original file line number Diff line number Diff line change
@@ -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}\""
}
}
91 changes: 91 additions & 0 deletions src/app/templates/typescript/auth/src/index.ts
Original file line number Diff line number Diff line change
@@ -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<CustomConfig> {
public logger: Logger;
private foo: string;
public constructor(config: CustomConfig, options: PluginOptions<CustomConfig>) {
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);
}
*/
}
}
5 changes: 5 additions & 0 deletions src/app/templates/typescript/auth/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {Config} from '@verdaccio/types';

export interface CustomConfig extends Config {
foo: string;
}
22 changes: 22 additions & 0 deletions src/app/templates/typescript/common/README.md
Original file line number Diff line number Diff line change
@@ -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`.
12 changes: 12 additions & 0 deletions src/app/templates/typescript/common/editorconfig
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions src/app/templates/typescript/common/eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
lib
12 changes: 12 additions & 0 deletions src/app/templates/typescript/common/eslintrc
Original file line number Diff line number Diff line change
@@ -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"
]
}
3 changes: 3 additions & 0 deletions src/app/templates/typescript/common/gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
npm-debug.log*
node_modules
/lib/
13 changes: 13 additions & 0 deletions src/app/templates/typescript/common/index.js
Original file line number Diff line number Diff line change
@@ -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;
7 changes: 7 additions & 0 deletions src/app/templates/typescript/common/index.js~Stashed changes
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 4 additions & 0 deletions src/app/templates/typescript/common/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
name: 'verdaccio-<%= name %>',
preset: 'ts-jest',
};
3 changes: 3 additions & 0 deletions src/app/templates/typescript/common/npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
src/
.eslintrc
test/
17 changes: 17 additions & 0 deletions src/app/templates/typescript/common/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
5 changes: 5 additions & 0 deletions src/app/templates/typescript/middleware/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {Config} from '@verdaccio/types';

export interface CustomConfig extends Config {
foo: string;
}
5 changes: 0 additions & 5 deletions test/.eslintrc

This file was deleted.

0 comments on commit 0a5326d

Please sign in to comment.