Skip to content

Commit

Permalink
Merge pull request #69 from RegestaItalia/fixPublishVisibility
Browse files Browse the repository at this point in the history
Fix publish visibility
  • Loading branch information
simonegaffurini authored Nov 28, 2024
2 parents 0e821bf + 3801304 commit 1b3d05f
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 86 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "trm-core",
"version": "6.0.0",
"version": "6.1.4",
"description": "TRM (Transport Request Manager) Core",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
3 changes: 2 additions & 1 deletion src/actions/publish/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ export const init: Step<PublishWorkflowContext> = {
...context.rawInput.packageData.manifest,
...{
name: context.rawInput.packageData.name,
version: context.rawInput.packageData.version
version: context.rawInput.packageData.version,
private: context.rawInput.publishData.private
}
}
},
Expand Down
104 changes: 56 additions & 48 deletions src/actions/publish/setManifestValues.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Step } from "@simonegaffurini/sammarksworkflow";
import { PublishWorkflowContext } from ".";
import { Logger } from "../../logger";
import { Inquirer } from "../../inquirer";
import { Inquirer, validatePackageVisibility } from "../../inquirer";
import { RegistryType } from "../../registry";
import { Manifest } from "../../manifest";

Expand All @@ -23,53 +23,70 @@ export const setManifestValues: Step<PublishWorkflowContext> = {
Logger.log('Set manifest values step', true);

//1- check if previous release manifest values should be copied
if(context.rawInput.publishData.keepLatestReleaseManifestValues){
if(context.runtime.trmPackage.latestReleaseManifest){
if (context.rawInput.publishData.keepLatestReleaseManifestValues) {
if (context.runtime.trmPackage.latestReleaseManifest) {
Logger.log(`Setting manifest values like latest version (${context.runtime.trmPackage.latestReleaseManifest.version})`, true);
context.runtime.trmPackage.manifest = {...context.runtime.trmPackage.latestReleaseManifest, ...context.runtime.trmPackage.manifest};
context.runtime.trmPackage.manifest = { ...context.runtime.trmPackage.latestReleaseManifest, ...context.runtime.trmPackage.manifest };
}
}

//2- input manifest values
if(!context.rawInput.contextData.noInquirer){
if (!context.rawInput.contextData.noInquirer) {
var defaultAuthors: string;
var defaultKeywords: string;
if(Array.isArray(context.runtime.trmPackage.manifest.authors)){
if (Array.isArray(context.runtime.trmPackage.manifest.authors)) {
defaultAuthors = context.runtime.trmPackage.manifest.authors.map(o => {
var author: string;
if(o.name){
if (o.name) {
author = o.name;
if(o.email){
if (o.email) {
author += ` <${o.email}>`;
}
}else if(o.email){
} else if (o.email) {
author = o.email;
}else{
throw new Error(`Invalid manifest values: authors.`);
}
return author;
}).join(', ');
}else{
}).filter(o => o !== undefined).join(', ');
} else {
defaultAuthors = context.runtime.trmPackage.manifest.authors;
}
if(Array.isArray(context.runtime.trmPackage.manifest.keywords)){
if (Array.isArray(context.runtime.trmPackage.manifest.keywords)) {
defaultKeywords = context.runtime.trmPackage.manifest.keywords.join(', ');
}else{
} else {
defaultKeywords = context.runtime.trmPackage.manifest.keywords;
}
var inq = await Inquirer.prompt([{
type: "list",
message: "Package visibility",
name: "private",
default: false,
choices: [{
name: `Public`,
value: false
}, {
name: `Private`,
value: true
}],
validate: (input: boolean) => {
return validatePackageVisibility(
context.rawInput.packageData.registry.getRegistryType(),
context.rawInput.packageData.name,
input
);
},
}, {
type: "input",
message: "Short description",
name: "description",
default: context.runtime.trmPackage.manifest.description,
validate: (input) => {
if(context.rawInput.packageData.registry.getRegistryType() === RegistryType.PUBLIC){
if(input.length > 50){
if (context.rawInput.packageData.registry.getRegistryType() === RegistryType.PUBLIC) {
if (input.length > 50) {
return "Maximum length: 50 characters";
}else{
} else {
return true;
}
}else{
} else {
return true;
}
}
Expand All @@ -79,13 +96,13 @@ export const setManifestValues: Step<PublishWorkflowContext> = {
name: "website",
default: context.runtime.trmPackage.manifest.website,
validate: (input) => {
if(context.rawInput.packageData.registry.getRegistryType() === RegistryType.PUBLIC){
if(input.length > 100){
if (context.rawInput.packageData.registry.getRegistryType() === RegistryType.PUBLIC) {
if (input.length > 100) {
return "Maximum length: 100 characters";
}else{
} else {
return true;
}
}else{
} else {
return true;
}
}
Expand All @@ -95,13 +112,13 @@ export const setManifestValues: Step<PublishWorkflowContext> = {
name: "git",
default: context.runtime.trmPackage.manifest.git,
validate: (input) => {
if(context.rawInput.packageData.registry.getRegistryType() === RegistryType.PUBLIC){
if(input.length > 100){
if (context.rawInput.packageData.registry.getRegistryType() === RegistryType.PUBLIC) {
if (input.length > 100) {
return "Maximum length: 100 characters";
}else{
} else {
return true;
}
}else{
} else {
return true;
}
}
Expand All @@ -122,29 +139,20 @@ export const setManifestValues: Step<PublishWorkflowContext> = {
default: context.runtime.trmPackage.manifest.license
//validate -> TODO should validate if on public registry!
}]);
inq.authors = inq.authors.split(',').map(s => {
const match = s.trim().match(/^(.*?)(?:\s*<([^>]+)>)?$/);
if(match && match.length >= 3){
return {
name: match[1] ? match[1].trim() : undefined,
email: match[2] ? match[2].trim() : undefined
}
}else{
throw new Error(`Invalid manifest values: authors.`);
}
});
inq.keywords = inq.keywords.split(',').map(s => {
if(s){
return s.trim();
}else{
throw new Error(`Invalid manifest values: keywords.`);
}
});
context.runtime.trmPackage.manifest = {...context.runtime.trmPackage.manifest, ...inq};
context.runtime.trmPackage.manifest = { ...context.runtime.trmPackage.manifest, ...inq };
}else{
const validateVisibility = validatePackageVisibility(
context.rawInput.packageData.registry.getRegistryType(),
context.rawInput.packageData.name,
context.runtime.trmPackage.manifest.private
);
if(validateVisibility !== true){
throw new Error(validateVisibility);
}
}

//3- set namespace values (if necessary)
if(context.runtime.packageData.namespace){
if (context.runtime.packageData.namespace) {
context.runtime.trmPackage.manifest.namespace = {
replicense: context.runtime.packageData.namespace.trnspacet.replicense,
texts: context.runtime.packageData.namespace.trnspacett.map(o => {
Expand All @@ -156,7 +164,7 @@ export const setManifestValues: Step<PublishWorkflowContext> = {
})
};
}

//4- normalize manifest values
context.runtime.trmPackage.manifest = Manifest.normalize(context.runtime.trmPackage.manifest, false);
}
Expand Down
2 changes: 1 addition & 1 deletion src/actions/publish/setTransportTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const setTransportTarget: Step<PublishWorkflowContext> = {
if (validate && validate !== true) {
throw new Error(validate);
}
Logger.info(`Publish transport target: "${transportTarget}"`);
Logger.info(`Publish transport release target: ${transportTarget}`);
}


Expand Down
3 changes: 2 additions & 1 deletion src/inquirer/validators/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./validateDevclass";
export * from "./validateTransportTarget";
export * from "./validateTransportTarget";
export * from "./validatePackageVisibility";
2 changes: 1 addition & 1 deletion src/inquirer/validators/validateDevclass.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DEVCLASS } from "../../client";
import { SystemConnector } from "../../systemConnector";

export async function validateDevclass(devclass: DEVCLASS, allowTemporaryPackages?: boolean): Promise<string|true|void> {
export async function validateDevclass(devclass: DEVCLASS, allowTemporaryPackages?: boolean): Promise<string|true> {
if (devclass) {
devclass = devclass.trim().toUpperCase();
const c = devclass.charAt(0);
Expand Down
21 changes: 21 additions & 0 deletions src/inquirer/validators/validatePackageVisibility.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { parsePackageName } from "../../commons";
import { RegistryType } from "../../registry";

export function validatePackageVisibility(registryType: RegistryType, packageName: string, isPrivate: boolean): string|true {
if(registryType === RegistryType.PUBLIC){
if(isPrivate){
const packageNameParsed = parsePackageName({
fullName: packageName
});
if(!packageNameParsed.organization){
return `Private packages on public registry need a scope!`;
}else{
return true;
}
}else{
return true;
}
}else{
return true;
}
}
4 changes: 3 additions & 1 deletion src/inquirer/validators/validateTransportTarget.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { TR_TARGET, TMSCSYS } from "../../client";

export async function validateTransportTarget(target: TR_TARGET, systemTmscsys: TMSCSYS[]): Promise<string|true|void> {
export async function validateTransportTarget(target: TR_TARGET, systemTmscsys: TMSCSYS[]): Promise<string|true> {
if (target) {
target = target.trim().toUpperCase();
if(!systemTmscsys.find(o => o.sysnam === target)){
return `Transport target ${target} does not exist.`;
}else{
return true;
}
}else{
return `Transport target ${target} not provided.`;
}
}
Loading

0 comments on commit 1b3d05f

Please sign in to comment.