Skip to content

Commit

Permalink
Download artifacts by using pool and update dependencies (#20)
Browse files Browse the repository at this point in the history
* Init

* Fix yarn.lock

* Finalize

* Finalize

* Prepare v9.9.0

---------

Co-authored-by: Damien Guerin <[email protected]>
  • Loading branch information
gigaga and Damien Guerin authored Feb 13, 2025
1 parent 5889c4f commit ced22d8
Show file tree
Hide file tree
Showing 16 changed files with 2,442 additions and 1,784 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ Global Options
'artifact' config property) which will be downloaded by using this url. From
this url template '[ARTIFACT_ID]', '[GROUP_ID]' and '[VERSION]' will be
replaced.
--downloadPoolSize number Pool size used to download artifacts, default is "Infinity".
```

### Publishing
Expand Down Expand Up @@ -178,6 +179,7 @@ Global Options
'artifact' config property) which will be downloaded by using this url. From
this url template '[ARTIFACT_ID]', '[GROUP_ID]' and '[VERSION]' will be
replaced.
--downloadPoolSize number Pool size used to download artifacts, default is "Infinity".
```

### Publishing Locally
Expand Down Expand Up @@ -213,6 +215,7 @@ Global Options
'artifact' config property) which will be downloaded by using this url. From
this url template '[ARTIFACT_ID]', '[GROUP_ID]' and '[VERSION]' will be
replaced.
--downloadPoolSize number Pool size used to download artifacts, default is "Infinity".
```

> **Warning**
Expand Down Expand Up @@ -252,6 +255,7 @@ Global Options
'artifact' config property) which will be downloaded by using this url. From
this url template '[ARTIFACT_ID]', '[GROUP_ID]' and '[VERSION]' will be
replaced.
--downloadPoolSize number Pool size used to download artifacts, default is "Infinity".
```

## Configuration file
Expand Down
75 changes: 37 additions & 38 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lyra-network/openapi-dev-tool",
"version": "9.8.2",
"version": "9.9.0",
"description": "OpenAPI Development tool",
"main": "src/lib.js",
"scripts": {
Expand Down Expand Up @@ -34,62 +34,61 @@
]
},
"dependencies": {
"@apidevtools/swagger-parser": "^10.1.0",
"@apidevtools/swagger-parser": "^10.1.1",
"@lyra-network/nexus-deployer": "^0.1.15",
"adm-zip": "^0.5.10",
"ajv": "^8.12.0",
"adm-zip": "^0.5.16",
"ajv": "^8.17.1",
"ajv-draft-04": "^1.0.0",
"ajv-oai": "^1.2.1",
"archiver": "^5.3.1",
"async": "0.9.0",
"change-case": "^4.1.2",
"chokidar": "^3.5.3",
"archiver": "^7.0.1",
"async": "3.2.6",
"change-case": "5.4.4",
"chokidar": "^4.0.3",
"colors": "^1.4.0",
"command-exists": "^1.2.9",
"command-line-args": "^5.2.1",
"command-line-usage": "^6.1.3",
"commander": "^9.5.0",
"debug": "2.2.0",
"ejs": "^3.1.8",
"command-line-args": "^6.0.1",
"command-line-usage": "^7.0.3",
"commander": "^13.1.0",
"debug": "4.4.0",
"ejs": "^3.1.10",
"errno": "^1.0.0",
"express": "^4.18.2",
"figlet": "^1.5.2",
"gammautils": "0.0.54",
"glob": "^8.0.3",
"express": "^4.21.2",
"figlet": "1.8.0",
"gammautils": "0.0.81",
"glob": "^10.4.5",
"json-pointer": "^0.6.2",
"json-schema-ref-parser": "^9.0.9",
"jsonpath-plus": "^7.2.0",
"libnpmpublish": "^9.0.3",
"jsonpath-plus": "^10.2.0",
"libnpmpublish": "^10.0.1",
"lodash.clonedeep": "^4.5.0",
"lodash.flatmap": "^4.5.0",
"lodash.flatten": "^4.4.0",
"lodash.merge": "^4.6.2",
"maven": "^5.0.0",
"mkdirp": "^1.0.4",
"mkdirp": "^3.0.1",
"promise-settle": "^0.3.0",
"rc": "^1.2.8",
"redoc": "^2.0.0",
"reload": "^3.2.1",
"rimraf": "^4.0.4",
"redoc": "^2.4.0",
"reload": "^3.3.0",
"rimraf": "5.0.10",
"showdown": "^2.1.0",
"swagger-ui-dist": "^4.15.5",
"tmp": "^0.2.1",
"traverse": "0.6.6",
"unzipper": "^0.10.11",
"validator": "3.16.1",
"yaml": "^2.2.1"
"swagger-ui-dist": "^5.18.3",
"tmp": "^0.2.3",
"traverse": "0.6.11",
"unzipper": "^0.12.3",
"validator": "4.9.0",
"yaml": "^2.7.0"
},
"devDependencies": {
"@babel/plugin-syntax-import-assertions": "^7.20.0",
"husky": "^8.0.3",
"jest": "^29.3.1",
"markdown-magic": "^2.6.1",
"markdown-magic-branch-badge": "^1.0.1",
"@babel/plugin-syntax-import-assertions": "^7.26.0",
"husky": "^9.1.7",
"jest": "^29.7.0",
"markdown-magic": "^3.3.0",
"markdown-magic-branch-badge": "^1.1.0",
"node-stream-zip": "^1.15.0",
"nodemon": "^2.0.20",
"prettier": "^2.8.2",
"rimraf": "^4.0.4",
"supertest": "^6.3.3"
"nodemon": "^3.1.9",
"prettier": "^3.5.1",
"supertest": "^7.0.0"
},
"husky": {
"hooks": {
Expand Down
10 changes: 5 additions & 5 deletions src/commands/merge.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import colors from 'colors';
import path from 'path';
import { paramCase } from 'change-case';
import { kebabCase } from 'change-case';
import settle from 'promise-settle';
import fs from 'fs';

Expand Down Expand Up @@ -42,22 +42,22 @@ export function merge(config = { config: { specs: [] } }) {
const api = await bundleSpec(config, spec);

// Find doublon
if (artifactIds.indexOf(paramCase(api.info.title)) != -1) {
if (artifactIds.indexOf(kebabCase(api.info.title)) != -1) {
throw new Error(
`Spec "${api.info.title}" has an artifactId "${paramCase(
`Spec "${api.info.title}" has an artifactId "${kebabCase(
api.info.title
)}" already defined!`
);
}

const targetFile = writeOpenApiDocumentToFile(
outputDir,
paramCase(api.info.title) + path.extname(filename),
kebabCase(api.info.title) + path.extname(filename),
spec.file,
api
);

artifactIds.push(paramCase(api.info.title));
artifactIds.push(kebabCase(api.info.title));
resolve();
console.log(
'\tMerged split files into a single one: %s',
Expand Down
16 changes: 8 additions & 8 deletions src/commands/publish-local.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import colors from 'colors';
import path from 'path';
import { paramCase } from 'change-case';
import { kebabCase } from 'change-case';
import settle from 'promise-settle';
import fs from 'fs';

Expand Down Expand Up @@ -43,24 +43,24 @@ export function publishLocal(config = { config: { specs: [] } }) {
archive = await generateSpecsArchive(api, [fileToArchive], 'maven');

// Find doublon
if (artifactIds.indexOf(paramCase(api.info.title)) !== -1) {
if (artifactIds.indexOf(kebabCase(api.info.title)) !== -1) {
throw new Error(
`Spec "${api.info.title}" has an artifactId "${paramCase(
`Spec "${api.info.title}" has an artifactId "${kebabCase(
api.info.title
)}" already defined!`
);
}

if (paramCase(api.info.title) === api.info.title) {
if (kebabCase(api.info.title) === api.info.title) {
console.log(
'\tPublishing API name: %s, Version: %s',
paramCase(api.info.title),
kebabCase(api.info.title),
api.info.version
);
} else {
console.log(
'\tPublishing API name: %s (%s), Version: %s',
paramCase(api.info.title),
kebabCase(api.info.title),
api.info.title,
api.info.version
);
Expand All @@ -76,11 +76,11 @@ export function publishLocal(config = { config: { specs: [] } }) {
}
}

artifactIds.push(paramCase(api.info.title));
artifactIds.push(kebabCase(api.info.title));

// Write temporary pom file
const pomContent = getPOMContent(
paramCase(api.info.title),
kebabCase(api.info.title),
api.info.version,
config.groupId,
'zip'
Expand Down
22 changes: 11 additions & 11 deletions src/commands/publish.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import deployer from '@lyra-network/nexus-deployer';
import colors from 'colors';
import path from 'path';
import { paramCase } from 'change-case';
import { kebabCase } from 'change-case';
import settle from 'promise-settle';
import { publish as npmPublish } from 'libnpmpublish';
import fs from 'fs';
Expand Down Expand Up @@ -43,7 +43,7 @@ export function publish(config = { config: { specs: [] } }) {
const files = [fileToArchive];
// If npm, we have to add a package.json file
const packageNpm = {
name: `${config.groupId}/${paramCase(api.info.title)}`,
name: `${config.groupId}/${kebabCase(api.info.title)}`,
version: api.info.version,
main: path.basename(spec.file),
};
Expand All @@ -59,24 +59,24 @@ export function publish(config = { config: { specs: [] } }) {
archive = await generateSpecsArchive(api, files, config.repoType);

// Find doublon
if (artifactIds.indexOf(paramCase(api.info.title)) != -1) {
if (artifactIds.indexOf(kebabCase(api.info.title)) != -1) {
throw new Error(
`Spec "${api.info.title}" has an artifactId "${paramCase(
`Spec "${api.info.title}" has an artifactId "${kebabCase(
api.info.title
)}" already defined!`
);
}

if (paramCase(api.info.title) === api.info.title) {
if (kebabCase(api.info.title) === api.info.title) {
console.log(
'\tPublishing API name: %s, Version: %s',
paramCase(api.info.title),
kebabCase(api.info.title),
api.info.version
);
} else {
console.log(
'\tPublishing API name: %s (%s), Version: %s',
paramCase(api.info.title),
kebabCase(api.info.title),
api.info.title,
api.info.version
);
Expand Down Expand Up @@ -104,13 +104,13 @@ export function publish(config = { config: { specs: [] } }) {
server = config.repoSnapshotsServer;
}

artifactIds.push(paramCase(api.info.title));
artifactIds.push(kebabCase(api.info.title));

if (config.repoType === 'maven') {
deployer.deploy(
{
groupId: config.groupId,
artifactId: paramCase(api.info.title),
artifactId: kebabCase(api.info.title),
version: api.info.version,
packaging: 'zip',
auth: {
Expand All @@ -128,7 +128,7 @@ export function publish(config = { config: { specs: [] } }) {
reject();
console.error(
colors.red(
`Unable to publish specs '${paramCase(api.info.title)}'`
`Unable to publish specs '${kebabCase(api.info.title)}'`
)
);
} else {
Expand Down Expand Up @@ -157,7 +157,7 @@ export function publish(config = { config: { specs: [] } }) {
reject();
console.error(
colors.red(
`Unable to publish specs '${paramCase(
`Unable to publish specs '${kebabCase(
api.info.title
)}': ${err}`
)
Expand Down
6 changes: 3 additions & 3 deletions src/lib/archiver.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createWriteStream } from 'fs';
import archiver from 'archiver';
import path from 'path';
import { paramCase } from 'change-case';
import { kebabCase } from 'change-case';

import { getTempDir } from './utils.js';

Expand All @@ -17,8 +17,8 @@ export function generateSpecsArchive(api, files, repoType) {
// For npm, we generate a tar file
const fileResult =
repoType === 'maven'
? `${workDir.name}/${paramCase(api.info.title)}-${api.info.version}.zip`
: `${workDir.name}/${paramCase(api.info.title)}-${
? `${workDir.name}/${kebabCase(api.info.title)}-${api.info.version}.zip`
: `${workDir.name}/${kebabCase(api.info.title)}-${
api.info.version
}.tar`;
const zipOutput = createWriteStream(fileResult);
Expand Down
6 changes: 3 additions & 3 deletions src/lib/bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import SwaggerParser from '@apidevtools/swagger-parser';
import path from 'path';
import YAML from 'yaml';
import fs from 'fs';
import { paramCase } from 'change-case';
import { kebabCase } from 'change-case';

import { isJSONFile, validateExamples } from './utils.js';
import { parseFolder } from './templater.js';
Expand Down Expand Up @@ -49,7 +49,7 @@ export async function bundleSpec(config, spec) {

// Check title and version syntax
const titleRegex = /^[a-z\-0-9]+$/;
if (!paramCase(api.info.title).match(titleRegex)) {
if (!kebabCase(api.info.title).match(titleRegex)) {
throw new Error(
`title \'${api.info.title}\' is not valid. Should be correct with ${titleRegex}`
);
Expand All @@ -64,7 +64,7 @@ export async function bundleSpec(config, spec) {
}

if (config.verbose) {
console.log(`\tSpecification validated: ${paramCase(api.info.title)}`);
console.log(`\tSpecification validated: ${kebabCase(api.info.title)}`);
}
return api;
}
Expand Down
6 changes: 6 additions & 0 deletions src/lib/config-definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ const globalOptionsDefinitions = [
description:
"Rather to use specs from local FS, you can specify remote specs (using 'artifact' config property) which will be downloaded by using this url. From this url template '[ARTIFACT_ID]', '[GROUP_ID]' and '[VERSION]' will be replaced.",
},
{
name: 'downloadPoolSize',
type: Number,
defaultValue: Infinity,
description: 'Pool size used to download artifacts, default is "Infinity".',
},
];

const serveOptionsDefinitions = [
Expand Down
Loading

0 comments on commit ced22d8

Please sign in to comment.