From 38772222ce4e3592229e8f46d81b222386767f40 Mon Sep 17 00:00:00 2001 From: p-zielinski <82354717+p-zielinski@users.noreply.github.com> Date: Mon, 16 Oct 2023 17:04:01 +0200 Subject: [PATCH 01/16] in progress --- .../Locking-Validation-Session.md | 2 +- .../campaign_recipes/Loyalty Program.md | 2 +- .../campaign_recipes/Prepaid-Gift-Cards.md | 2 +- .../guides/campaign_recipes/Qualifications.md | 2 +- .../campaign_recipes/Referral-Program.md | 2 +- .../Stacking-Promotion-Tiers.md | 2 +- .../Transfer-Loyalty-Points.md | 2 +- .../discounts_recipes/Discount-Effects.md | 2 +- .../Free-Shipping-Discount.md | 2 +- .../Give-Items-For-Free-Unit-Discount.md | 2 +- .../Product-Specific-Discounts.md | 2 +- .../Stackable-Discounts-API.md | 2 +- .../CSV-Export-With-API.md | 2 +- .../distributions_recipes/Geofencing.md | 2 +- .../Import-Legacy-Codes.md | 2 +- .../Messaging-Automation.md | 2 +- package.json | 5 +- scripts/index.ts | 108 ++++++++++++++++++ ...-order.ts => readme-fix-reference-docs.ts} | 84 +++++++------- 19 files changed, 168 insertions(+), 61 deletions(-) create mode 100644 scripts/index.ts rename scripts/{readme-fix-docs-order.ts => readme-fix-reference-docs.ts} (76%) diff --git a/docs/guides/campaign_recipes/Locking-Validation-Session.md b/docs/guides/campaign_recipes/Locking-Validation-Session.md index 687dab4d3..40ec56eb6 100644 --- a/docs/guides/campaign_recipes/Locking-Validation-Session.md +++ b/docs/guides/campaign_recipes/Locking-Validation-Session.md @@ -1,7 +1,7 @@ --- title: Locking Validation Session excerpt: Temporary lock the voucher's usage until redemption is successful. -categorySlug: campaigns-1 +categorySlug: campaigns-recipes slug: locking-validation-session type: basic hidden: false diff --git a/docs/guides/campaign_recipes/Loyalty Program.md b/docs/guides/campaign_recipes/Loyalty Program.md index c53b48cbe..264a10571 100644 --- a/docs/guides/campaign_recipes/Loyalty Program.md +++ b/docs/guides/campaign_recipes/Loyalty Program.md @@ -1,7 +1,7 @@ --- title: Loyalty Program excerpt: null -categorySlug: campaigns-1 +categorySlug: campaigns-recipes slug: loyalty-program type: basic hidden: false diff --git a/docs/guides/campaign_recipes/Prepaid-Gift-Cards.md b/docs/guides/campaign_recipes/Prepaid-Gift-Cards.md index 0ebbf105f..58682b91e 100644 --- a/docs/guides/campaign_recipes/Prepaid-Gift-Cards.md +++ b/docs/guides/campaign_recipes/Prepaid-Gift-Cards.md @@ -1,7 +1,7 @@ --- title: Prepaid Gift Cards excerpt: null -categorySlug: campaigns-1 +categorySlug: campaigns-recipes slug: prepaid-gift-cards type: basic hidden: false diff --git a/docs/guides/campaign_recipes/Qualifications.md b/docs/guides/campaign_recipes/Qualifications.md index 518e12f26..c40da5f11 100644 --- a/docs/guides/campaign_recipes/Qualifications.md +++ b/docs/guides/campaign_recipes/Qualifications.md @@ -1,7 +1,7 @@ --- title: Qualification - Checking eligibility excerpt: null -categorySlug: campaigns-1 +categorySlug: campaigns-recipes slug: checking-eligibility type: basic hidden: false diff --git a/docs/guides/campaign_recipes/Referral-Program.md b/docs/guides/campaign_recipes/Referral-Program.md index 8fa21ede1..98c677d71 100644 --- a/docs/guides/campaign_recipes/Referral-Program.md +++ b/docs/guides/campaign_recipes/Referral-Program.md @@ -1,7 +1,7 @@ --- title: Referral Program excerpt: null -categorySlug: campaigns-1 +categorySlug: campaigns-recipes slug: referral-program type: link hidden: false diff --git a/docs/guides/campaign_recipes/Stacking-Promotion-Tiers.md b/docs/guides/campaign_recipes/Stacking-Promotion-Tiers.md index b1edb1464..e19939efa 100644 --- a/docs/guides/campaign_recipes/Stacking-Promotion-Tiers.md +++ b/docs/guides/campaign_recipes/Stacking-Promotion-Tiers.md @@ -1,7 +1,7 @@ --- title: Stacking Promotion Tiers excerpt: 'In this tutorial, you will learn how to validate, redeem, and manage promotion stacks using API.' -categorySlug: campaigns-1 +categorySlug: campaigns-recipes slug: stacking-promotion-tiers type: basic hidden: false diff --git a/docs/guides/campaign_recipes/Transfer-Loyalty-Points.md b/docs/guides/campaign_recipes/Transfer-Loyalty-Points.md index 937388a41..44238cbc0 100644 --- a/docs/guides/campaign_recipes/Transfer-Loyalty-Points.md +++ b/docs/guides/campaign_recipes/Transfer-Loyalty-Points.md @@ -1,7 +1,7 @@ --- title: Transfer Loyalty Points excerpt: See how to transfer points between loyalty cards. -categorySlug: campaigns-1 +categorySlug: campaigns-recipes slug: transfer-loyalty-points type: basic hidden: false diff --git a/docs/guides/discounts_recipes/Discount-Effects.md b/docs/guides/discounts_recipes/Discount-Effects.md index 6529481fd..367f4833c 100644 --- a/docs/guides/discounts_recipes/Discount-Effects.md +++ b/docs/guides/discounts_recipes/Discount-Effects.md @@ -1,7 +1,7 @@ --- title: Discount Effects excerpt: The discount effect defines how the discount will be applied to the customer's cart. In this article, we're going to show you how different effects work with discounts. -categorySlug: discounts +categorySlug: discounts-recipes slug: discount-effects type: basic hidden: false diff --git a/docs/guides/discounts_recipes/Free-Shipping-Discount.md b/docs/guides/discounts_recipes/Free-Shipping-Discount.md index df908f3a8..094080735 100644 --- a/docs/guides/discounts_recipes/Free-Shipping-Discount.md +++ b/docs/guides/discounts_recipes/Free-Shipping-Discount.md @@ -1,7 +1,7 @@ --- title: Free shipping disount excerpt: How to use free shipping discounts? -categorySlug: discounts +categorySlug: discounts-recipes slug: free-shipping-discount type: basic hidden: false diff --git a/docs/guides/discounts_recipes/Give-Items-For-Free-Unit-Discount.md b/docs/guides/discounts_recipes/Give-Items-For-Free-Unit-Discount.md index c2e9ecb11..862c5c661 100644 --- a/docs/guides/discounts_recipes/Give-Items-For-Free-Unit-Discount.md +++ b/docs/guides/discounts_recipes/Give-Items-For-Free-Unit-Discount.md @@ -1,7 +1,7 @@ --- title: Give item(s) for free - unit discount excerpt: How to add free items to customers' orders? -categorySlug: discounts +categorySlug: discounts-recipes slug: give-item-for-free-unit-discount type: basic hidden: false diff --git a/docs/guides/discounts_recipes/Product-Specific-Discounts.md b/docs/guides/discounts_recipes/Product-Specific-Discounts.md index 002893d6e..71bdcdeea 100644 --- a/docs/guides/discounts_recipes/Product-Specific-Discounts.md +++ b/docs/guides/discounts_recipes/Product-Specific-Discounts.md @@ -1,7 +1,7 @@ --- title: Product-specific discounts excerpt: A recipe for using *applicable_to* validation rule -categorySlug: discounts +categorySlug: discounts-recipes slug: discount-for-particular-product type: basic hidden: false diff --git a/docs/guides/discounts_recipes/Stackable-Discounts-API.md b/docs/guides/discounts_recipes/Stackable-Discounts-API.md index 6394c6ffd..083ce7f69 100644 --- a/docs/guides/discounts_recipes/Stackable-Discounts-API.md +++ b/docs/guides/discounts_recipes/Stackable-Discounts-API.md @@ -1,7 +1,7 @@ --- title: Stackable discounts API excerpt: -categorySlug: discounts +categorySlug: discounts-recipes slug: manage-stackable-discounts type: basic hidden: false diff --git a/docs/guides/distributions_recipes/CSV-Export-With-API.md b/docs/guides/distributions_recipes/CSV-Export-With-API.md index 4852bd75e..c96128a65 100644 --- a/docs/guides/distributions_recipes/CSV-Export-With-API.md +++ b/docs/guides/distributions_recipes/CSV-Export-With-API.md @@ -1,7 +1,7 @@ --- title: CSV export with API excerpt: null -categorySlug: distribution-1 +categorySlug: distributions-recipes slug: csv-export type: basic hidden: false diff --git a/docs/guides/distributions_recipes/Geofencing.md b/docs/guides/distributions_recipes/Geofencing.md index 13f7c5ddc..4deb1e3a6 100644 --- a/docs/guides/distributions_recipes/Geofencing.md +++ b/docs/guides/distributions_recipes/Geofencing.md @@ -1,7 +1,7 @@ --- title: Geofencing excerpt: -categorySlug: distribution-1 +categorySlug: distributions-recipes slug: geofencing type: link hidden: false diff --git a/docs/guides/distributions_recipes/Import-Legacy-Codes.md b/docs/guides/distributions_recipes/Import-Legacy-Codes.md index 07efe095d..ee3df7b3d 100644 --- a/docs/guides/distributions_recipes/Import-Legacy-Codes.md +++ b/docs/guides/distributions_recipes/Import-Legacy-Codes.md @@ -1,7 +1,7 @@ --- title: Import legacy codes excerpt: null -categorySlug: distribution-1 +categorySlug: distributions-recipes slug: import-codes type: basic hidden: false diff --git a/docs/guides/distributions_recipes/Messaging-Automation.md b/docs/guides/distributions_recipes/Messaging-Automation.md index 62ebde939..ed9f15c34 100644 --- a/docs/guides/distributions_recipes/Messaging-Automation.md +++ b/docs/guides/distributions_recipes/Messaging-Automation.md @@ -1,7 +1,7 @@ --- title: Messaging automation excerpt: How to set up an automatic promotion delivery for a dynamic customer segment? -categorySlug: distribution-1 +categorySlug: distributions-recipes slug: automatic-delivery type: basic hidden: false diff --git a/package.json b/package.json index 665b78342..b23047b4c 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,9 @@ "scripts": { "update-md-tables-in-doc": "ts-node ./scripts/update-md-tables-in-doc.ts", "build-md-tables-from-openapi": "ts-node ./scripts/build-md-tables-from-openapi.ts", - "readme-fix-docs-order": "ts-node ./scripts/readme-fix-docs-order.ts", - "remove-stoplight-tags-from-openapi": "ts-node ./scripts/remove-stoplight-tags-from-openapi.ts" + "readme-fix-reference-docs": "ts-node ./scripts/readme-fix-reference-docs.ts", + "remove-stoplight-tags-from-openapi": "ts-node ./scripts/remove-stoplight-tags-from-openapi.ts", + "all": "ts-node ./scripts/index.ts" }, "dependencies": { "dotenv": "^16.3.1", diff --git a/scripts/index.ts b/scripts/index.ts new file mode 100644 index 000000000..edf30cf11 --- /dev/null +++ b/scripts/index.ts @@ -0,0 +1,108 @@ +import * as fsPromises from "fs/promises"; +import path from "path"; +import dotenv from "dotenv"; +import minimist from "minimist"; + +dotenv.config(); +const { versionTag } = minimist(process.argv.slice(2)); + +const mainVersion = "v2018-08-01"; + +const listOfGuideCategories = [ + "Getting started", + "Development", + "Building blocks", + "Campaigns Recipes", + "Discounts Recipes", + "Distributions Recipes", + "More", +]; + +const listOfReferenceCategories = ["Introduction"]; + +const main = async () => { + if (!versionTag) { + console.log( + "`version` argument was not provided :/, next time try add `-- --version=************` at the end of file execution command" + ); + return; + } + const version = `${mainVersion}-${versionTag}`; + //create fork + try { + const response = await fetch( + ` +https://dash.readme.com/api/v1/version`, + { + method: "POST", + headers: { + authorization: "Basic " + btoa(process.env.README_IO_AUTH + ":"), + "content-type": "application/json", + accept: "application/json", + }, + body: JSON.stringify({ + is_beta: false, + is_stable: false, + is_hidden: true, + is_deprecated: false, + from: mainVersion, + version, + }), + } + ); + if (response.status !== 200) { + throw new Error(`Response status: ${response.status}`); + } + } catch (error) { + console.log(`Error while creating fork from ${mainVersion}`, error); + throw new Error(error); + } + const categoriesToDelete = await ( + await fetch( + `https://dash.readme.com/api/v1/categories?perPage=100&page=1`, + { + method: "GET", + headers: { + "x-readme-version": version, + authorization: "Basic " + btoa(process.env.README_IO_AUTH + ":"), + }, + } + ) + ).json(); + await asyncMap(categoriesToDelete, (category) => + deleteCategory(version, category.slug) + ); + // console.log(await categories.json()); + // // categories.push(...responseJSON.categories); + // // asyncMap(categories, (categoryId) => deleteCategory()); +}; + +const deleteCategory = async (version, slug) => { + await fetch(`https://dash.readme.com/api/v1/categories/${slug}`, { + method: "DELETE", + headers: { + "x-readme-version": version, + authorization: "Basic " + btoa(process.env.README_IO_AUTH + ":"), + accept: "application/json", + }, + }); +}; + +const createCategory = async (version, title) => { + const response = await fetch(`https://dash.readme.com/api/v1/categories`, { + method: "POST", + headers: { + "x-readme-version": version, + authorization: "Basic " + btoa(process.env.README_IO_AUTH + ":"), + "content-type": "application/json", + accept: "application/json", + }, + body: JSON.stringify({ title }), + }); +}; + +const asyncMap = (arr, asyncFn) => { + return Promise.all(arr.map(asyncFn)); +}; + +main(); diff --git a/scripts/readme-fix-docs-order.ts b/scripts/readme-fix-reference-docs.ts similarity index 76% rename from scripts/readme-fix-docs-order.ts rename to scripts/readme-fix-reference-docs.ts index 64e5926d3..ef6c0a1a8 100644 --- a/scripts/readme-fix-docs-order.ts +++ b/scripts/readme-fix-reference-docs.ts @@ -1,14 +1,45 @@ - -import * as fs from 'fs/promises' +import * as fsPromises from 'fs/promises' import path from 'path'; import dotenv from 'dotenv' import minimist from 'minimist'; -import { ok } from 'assert'; dotenv.config(); const { version } = minimist(process.argv.slice(2)); -const updateDoc = async ({ slug, order, pathToFile }) => { +const readmeFixReferenceDocs = async () => { + if (!version) { + console.log( + "`version` argument was not provided :/, next time try add `-- --version=************` at the end of file execution command" + ); + return; + } + if (process.env.README_IO_AUTH?.length < 10) { + console.log("`README_IO_AUTH` was not provided in `.env` file :/"); + return; + } + const basePath = path.join(__dirname, "../docs"); + const pathsToFiles = await getFiles(basePath); + + const dataToProcess = []; + for (const pathToFile of pathsToFiles) { + const data = await fsPromises.readFile(pathToFile, { encoding: "utf8" }); + const slug = data.match(/slug: .*/)?.[0]?.split?.("slug: ")?.[1]; + const type = data.match(/type: .*/)?.[0]?.split?.("type: ")?.[1]; + const order = parseInt( + data.match(/order: .*/)?.[0]?.split?.("order: ")?.[1] + ); + if (!slug || isNaN(order)) { + throw new Error("Invalid slug or order in " + pathToFile); + } + dataToProcess.push({ slug, order, pathToFile, type }); + } + for (const chunk of chunkArray(dataToProcess, 10)) { + await asyncMap(chunk, updateDoc); + } + console.log("Done!"); +}; + +const updateDoc = async ({ slug, order, type, pathToFile }) => { const options = { method: "PUT", headers: { @@ -17,7 +48,7 @@ const updateDoc = async ({ slug, order, pathToFile }) => { "content-type": "application/json", accept: "application/json", }, - body: JSON.stringify({ order }), + body: JSON.stringify({ order, type }), }; try{ @@ -27,18 +58,18 @@ const updateDoc = async ({ slug, order, pathToFile }) => { ); const responseJSON = await response.json(); - + if (responseJSON.error) { console.log(`Error in json response from readme for ${slug}`, { responseJSON }); throw new Error(responseJSON.error); } - + if (order === responseJSON.order) { console.log(`Updated successfully ${pathToFile}!`); } else { console.log(`Not updated ${pathToFile}!`); } - + return responseJSON; }catch(error){ console.log(`Error when reqesting readme for ${slug}`, error); @@ -53,7 +84,7 @@ const chunkArray = (list, chunkSize) => const getFiles = async (path: string) => { const pathsToFiles: string[] = []; - const items = await fs.readdir(path, { + const items = await fsPromises.readdir(path, { withFileTypes: true, }); for (const item of items) { @@ -76,38 +107,5 @@ const asyncMap = (arr, asyncFn) => { }; -const readmeFixDocsOrder = async () => { - if (!version) { - console.log( - "`version` argument was not provided :/, next time try add `-- --version=************` at the end of file execution command" - ); - return; - } - if (process.env.README_IO_AUTH?.length < 10) { - console.log("`README_IO_AUTH` was not provided in `.env` file :/"); - return; - } - const basePath = path.join(__dirname, "../docs"); - const pathsToFiles = await getFiles(basePath); - - const dataToProcess = []; - for (const pathToFile of pathsToFiles) { - const data = await fs.readFile(pathToFile, { encoding: "utf8" }); - const slug = data.match(/slug: .*/)?.[0]?.split?.("slug: ")?.[1]; - const order = parseInt( - data.match(/order: .*/)?.[0]?.split?.("order: ")?.[1] - ); - if (!slug || isNaN(order)) { - throw new Error("Invalid slug or order in " + pathToFile); - } - dataToProcess.push({ slug, order, pathToFile }); - } - for (const chunk of chunkArray(dataToProcess, 6)) { - await asyncMap(chunk, updateDoc); - } - console.log("Done!"); -}; - - -readmeFixDocsOrder() +readmeFixReferenceDocs() From 22d6fb18e223b8906c2c41ecfc800c9bdd819edc Mon Sep 17 00:00:00 2001 From: p-zielinski <82354717+p-zielinski@users.noreply.github.com> Date: Mon, 16 Oct 2023 20:32:08 +0200 Subject: [PATCH 02/16] Update index.ts --- scripts/index.ts | 89 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 79 insertions(+), 10 deletions(-) diff --git a/scripts/index.ts b/scripts/index.ts index edf30cf11..a22a79ffa 100644 --- a/scripts/index.ts +++ b/scripts/index.ts @@ -51,13 +51,65 @@ https://dash.readme.com/api/v1/version`, } ); if (response.status !== 200) { - throw new Error(`Response status: ${response.status}`); + throw new Error( + `Response status: ${response.status}, maybe this versionTag is already used?` + ); } + console.log(`FORK CREATED!`); } catch (error) { console.log(`Error while creating fork from ${mainVersion}`, error); throw new Error(error); } - const categoriesToDelete = await ( +}; + +const createNewVersion = + +const cleanProject = async (version) => { + const categoriesToDelete = await getAllCategories(version); + //delete all categories + await asyncMap( + categoriesToDelete, + async (category) => await deleteCategory(version, category.slug) + ); + console.log(`OLD CATEGORIES DELETED`); + //create categories + await asyncMap( + [...listOfGuideCategories, ...listOfReferenceCategories], + async (title) => await createCategory(version, title) + ); + console.log(`NEW CATEGORIES CREATED`); + const allCategories = await getAllCategories(version); + //update reference categories types + await asyncMap( + listOfReferenceCategories, + async (categoryTitle) => + await updateCategory( + version, + allCategories.find((category) => category.title === categoryTitle).slug, + { type: "reference" } + ) + ); + console.log(`REFERENCE CATEGORIES UPDATED`); + const allApiSpecifications = await getAllApiSpecifications(version); + await asyncMap(allApiSpecifications, deleteSpecification); + console.log(`API SPECIFICATIONS DELETED`); +}; + +const updateCategory = async (version, slug, data = {}) => { + await fetch(`https://dash.readme.com/api/v1/categories/${slug}`, { + method: "PUT", + headers: { + "x-readme-version": version, + authorization: "Basic " + btoa(process.env.README_IO_AUTH + ":"), + "content-type": "application/json", + accept: "application/json", + }, + body: JSON.stringify(data), + }); +}; + +const getAllCategories = async (version) => + await ( await fetch( `https://dash.readme.com/api/v1/categories?perPage=100&page=1`, { @@ -69,13 +121,6 @@ https://dash.readme.com/api/v1/version`, } ) ).json(); - await asyncMap(categoriesToDelete, (category) => - deleteCategory(version, category.slug) - ); - // console.log(await categories.json()); - // // categories.push(...responseJSON.categories); - // // asyncMap(categories, (categoryId) => deleteCategory()); -}; const deleteCategory = async (version, slug) => { await fetch(`https://dash.readme.com/api/v1/categories/${slug}`, { @@ -89,7 +134,7 @@ const deleteCategory = async (version, slug) => { }; const createCategory = async (version, title) => { - const response = await fetch(`https://dash.readme.com/api/v1/categories`, { + await fetch(`https://dash.readme.com/api/v1/categories`, { method: "POST", headers: { "x-readme-version": version, @@ -101,6 +146,30 @@ const createCategory = async (version, title) => { }); }; +const getAllApiSpecifications = async (version) => + await ( + await fetch( + `https://dash.readme.com/api/v1/api-specification?perPage=100&page=1`, + { + method: "GET", + headers: { + "x-readme-version": version, + authorization: "Basic " + btoa(process.env.README_IO_AUTH + ":"), + }, + } + ) + ).json(); + +const deleteSpecification = async (id) => { + await fetch(`https://dash.readme.com/api/v1/api-specification/${id}`, { + method: "DELETE", + headers: { + authorization: "Basic " + btoa(process.env.README_IO_AUTH + ":"), + accept: "application/json", + }, + }); +}; + const asyncMap = (arr, asyncFn) => { return Promise.all(arr.map(asyncFn)); }; From a769187f53d784cf0710a0d2fcce5deb0ee1e01a Mon Sep 17 00:00:00 2001 From: p-zielinski <82354717+p-zielinski@users.noreply.github.com> Date: Tue, 17 Oct 2023 10:57:35 +0200 Subject: [PATCH 03/16] done? --- CONTRIBUTING.md | 2 +- package-lock.json | 9 ++++ package.json | 3 +- scripts/{index.ts => manage-project.ts} | 55 ++++++++++++++++++------- 4 files changed, 53 insertions(+), 16 deletions(-) rename scripts/{index.ts => manage-project.ts} (71%) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bc5258e7a..9a78df7b8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -140,7 +140,7 @@ Good practices: - Test changes on readme (you can use the version prepared by the contributor). - Ensure the changelog was updated. - Merge PR to `master` branch -- In reamde.io, change the current documentation version from `v2018-08-01` to `v2018-08-01-deprecated-mm-dd-yyyy` +- In readme.io, change the current documentation version from `v2018-08-01` to `v2018-08-01-deprecated-mm-dd-yyyy` - Change the name of your new release version from `2018-08-01-{your name}-{pull request number}` to `v2018-08-01` > [!NOTE] Readme.io cache pages for 15 minutes, for only logged out users. If you are logged in, then you will always receive the most recent content. diff --git a/package-lock.json b/package-lock.json index 89e83ad65..b987351eb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,6 +7,7 @@ "": { "version": "1.0.0", "dependencies": { + "colors": "^1.4.0", "dotenv": "^16.3.1", "markdown-it": "^13.0.2", "minimist": "^1.2.8", @@ -105,6 +106,14 @@ "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==" }, + "node_modules/colors": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz", + "integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==", + "engines": { + "node": ">=0.1.90" + } + }, "node_modules/create-require": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", diff --git a/package.json b/package.json index b23047b4c..077d58609 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,10 @@ "build-md-tables-from-openapi": "ts-node ./scripts/build-md-tables-from-openapi.ts", "readme-fix-reference-docs": "ts-node ./scripts/readme-fix-reference-docs.ts", "remove-stoplight-tags-from-openapi": "ts-node ./scripts/remove-stoplight-tags-from-openapi.ts", - "all": "ts-node ./scripts/index.ts" + "manage-project": "ts-node ./scripts/manage-project.ts" }, "dependencies": { + "colors": "^1.4.0", "dotenv": "^16.3.1", "markdown-it": "^13.0.2", "minimist": "^1.2.8", diff --git a/scripts/index.ts b/scripts/manage-project.ts similarity index 71% rename from scripts/index.ts rename to scripts/manage-project.ts index a22a79ffa..239217d37 100644 --- a/scripts/index.ts +++ b/scripts/manage-project.ts @@ -1,12 +1,18 @@ -import * as fsPromises from "fs/promises"; -import path from "path"; import dotenv from "dotenv"; import minimist from "minimist"; +import colors from "colors"; dotenv.config(); -const { versionTag } = minimist(process.argv.slice(2)); +const options = minimist(process.argv.slice(2)); +const versionTag = options.versionTag || options.vt; +const versionOption = options.version || options.v; + +const cleanOnly = options.cleanOnly || options.co; +const help = options.help || options.h; const mainVersion = "v2018-08-01"; +const version = + versionOption || versionTag ? `${mainVersion}-${versionTag}` : undefined; const listOfGuideCategories = [ "Getting started", @@ -21,13 +27,34 @@ const listOfGuideCategories = [ const listOfReferenceCategories = ["Introduction"]; const main = async () => { - if (!versionTag) { + if (help) { console.log( - "`version` argument was not provided :/, next time try add `-- --version=************` at the end of file execution command" + colors.green( + `options:` + + `\n"versionTag" or "vt" for versionTag, for example "npm run manage-project -- --vt=piotr-1234"` + + `\n"version" or "v" for version, for example "npm run manage-project -- --v=v2018-08-01-piotr-1234"` + + `\n"cleanOnly" or "co" for version, for example "npm run manage-project -- --vt=piotr-1234" --co` + + `\n\nuse "versionTag" or "version" for version, not both!` + ) ); return; } - const version = `${mainVersion}-${versionTag}`; + if (!version) { + console.log( + colors.red( + "invalid arguments, check `help` for more information\nrun 'npm run manage-project -- --help'" + ) + ); + return; + } + if (!cleanOnly) { + await createNewVersion(version); + } + await cleanProject(version); + console.log(colors.green(`\nVisit: https://docs.voucherify.io/${version}/`)); +}; + +const createNewVersion = async (version) => { //create fork try { const response = await fetch( @@ -55,15 +82,14 @@ https://dash.readme.com/api/v1/version`, `Response status: ${response.status}, maybe this versionTag is already used?` ); } - console.log(`FORK CREATED!`); + console.log(colors.green(`FORK CREATED! VERSION "${version}"`)); } catch (error) { - console.log(`Error while creating fork from ${mainVersion}`, error); + console.log(colors.red(`Error while creating fork from ${mainVersion}!`)), + error; throw new Error(error); } }; -const createNewVersion = - const cleanProject = async (version) => { const categoriesToDelete = await getAllCategories(version); //delete all categories @@ -71,13 +97,13 @@ const cleanProject = async (version) => { categoriesToDelete, async (category) => await deleteCategory(version, category.slug) ); - console.log(`OLD CATEGORIES DELETED`); + console.log(colors.green(`OLD CATEGORIES DELETED!`)); //create categories await asyncMap( [...listOfGuideCategories, ...listOfReferenceCategories], async (title) => await createCategory(version, title) ); - console.log(`NEW CATEGORIES CREATED`); + console.log(colors.green(`NEW CATEGORIES CREATED!`)); const allCategories = await getAllCategories(version); //update reference categories types await asyncMap( @@ -89,10 +115,11 @@ const cleanProject = async (version) => { { type: "reference" } ) ); - console.log(`REFERENCE CATEGORIES UPDATED`); + console.log(colors.green(`REFERENCE CATEGORIES UPDATED!`)); const allApiSpecifications = await getAllApiSpecifications(version); await asyncMap(allApiSpecifications, deleteSpecification); - console.log(`API SPECIFICATIONS DELETED`); + console.log(colors.green(`API SPECIFICATIONS DELETED!`)); + console.log(colors.green(`VERSION "${version}" IS CLEANED UP!`)); }; const updateCategory = async (version, slug, data = {}) => { From 21680217b899f5a0348ecafc70b978af1ca92fe2 Mon Sep 17 00:00:00 2001 From: p-zielinski <82354717+p-zielinski@users.noreply.github.com> Date: Tue, 17 Oct 2023 11:14:00 +0200 Subject: [PATCH 04/16] Update CONTRIBUTING.md --- CONTRIBUTING.md | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9a78df7b8..07d5a153b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -107,25 +107,14 @@ Good practices: ### Development process - For each change / pull request, create your copy of the current documentation, where you will test changes. - - Create your own branch from `master`, - - Create a draft pull request, - - Go to `Manage Versions` page in readme.io - - Click `Add New Version` from top right corner. - - Select the current public version in `Fork from` field, most likely `2018-08-01` - - Type your version name in `Create version` field following the pattern: - `2018-08-01-{your name}-{pull request number}` + - `npm run manage-project -- --vt={your name}-{pull request number}` - Make changes in the repository following patterns and good practices. - Deploy changes to test your documentation: - - Update tables in markdown tables: + - Deploy OpenAPI file by command `rdme openapi ./reference/OpenAPI.json --version=2018-08-01-{your name}-{pull request number}`, choose `Create a new spec` option. Command most likely will fail with the message: `We're sorry, your upload request timed out. Please try again or split your file up into smaller chunks`, but so far, we see that this operation still works correctly. + - Update tables in mark down tables: - `npm run build-md-tables-from-openapi` - `npm run update-md-tables-in-doc` - - from API Reference page in readme dashboard: - - remove Voucherify OpenAPI Definition - - refresh the page and remove `VOUCHERIFY API` category from left sidebar, DO NOT REMOVE `INTRODUCTION` catregory from left sidebar - the existing OpenAPI file and all specification files. - - Deploy OpenAPI file by command `rdme openapi ./reference/OpenAPI.json --version=2018-08-01-{your name}-{pull request number}`, choose `Create a new spec` option. Command most likely will fail with the message: `We're sorry, your upload request timed out. Please try again or split your file up into smaller chunks`, but so far, we see that this operation still works correctly. - - Deploy guides pages: `rdme docs ./docs/guides --version=2018-08-01-{your name}-{pull request number}` - - Deploy api reference pages: `rdme docs ./docs/reference-docs --version=2018-08-01-{your name}-{pull request number}` + - Deploy guides and reference pages: `rdme docs ./docs --version=2018-08-01-{your name}-{pull request number}` - Fix docs order: `npm run readme-fix-docs-order -- --version=v2018-08-01-{your name}-{pull request number}` - test changes using preview on readme.io - if changes are fine, then: From 8b5b2e2eca30da62b916301f3dfd4481b23ec4b9 Mon Sep 17 00:00:00 2001 From: p-zielinski <82354717+p-zielinski@users.noreply.github.com> Date: Tue, 17 Oct 2023 12:39:50 +0200 Subject: [PATCH 05/16] in progress --- CONTRIBUTING.md | 2 +- scripts/build-md-tables-from-openapi.ts | 51 ++++++---- scripts/manage-project.ts | 81 +++++++++++++++- scripts/update-md-tables-in-doc.ts | 120 +++++++++++++----------- 4 files changed, 175 insertions(+), 79 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 07d5a153b..d3c1e7d0c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -110,7 +110,7 @@ Good practices: - `npm run manage-project -- --vt={your name}-{pull request number}` - Make changes in the repository following patterns and good practices. - Deploy changes to test your documentation: - - Deploy OpenAPI file by command `rdme openapi ./reference/OpenAPI.json --version=2018-08-01-{your name}-{pull request number}`, choose `Create a new spec` option. Command most likely will fail with the message: `We're sorry, your upload request timed out. Please try again or split your file up into smaller chunks`, but so far, we see that this operation still works correctly. + - Deploy OpenAPI file by command `rdme openapi ./reference/OpenAPI.json --version=2018-08-01-{your name}-{pull request number} --create`. - Update tables in mark down tables: - `npm run build-md-tables-from-openapi` - `npm run update-md-tables-in-doc` diff --git a/scripts/build-md-tables-from-openapi.ts b/scripts/build-md-tables-from-openapi.ts index 20c29655e..4adf003c2 100644 --- a/scripts/build-md-tables-from-openapi.ts +++ b/scripts/build-md-tables-from-openapi.ts @@ -1,23 +1,34 @@ -import * as fs from 'fs/promises' -import path from 'path'; -import './globals.t' -import * as openApi from '../reference/OpenAPI.json'; -import { mdTables } from './md-tables'; -import SchemaToMarkdownTable, {RenderMode, ExamplesRenderedAs} from './src/schema-to-md-table'; +import * as fs from "fs/promises"; +import path from "path"; +import "./globals.t"; +import * as openApi from "../reference/OpenAPI.json"; +import { mdTables } from "./md-tables"; +import SchemaToMarkdownTable, { + RenderMode, + ExamplesRenderedAs, +} from "./src/schema-to-md-table"; -const PATH_TO_GERENATED_TABLES = [__dirname, './output']; +const PATH_TO_GERENATED_TABLES = [__dirname, "./output"]; -(async () => { - const stm = new SchemaToMarkdownTable(openApi.components.schemas, RenderMode.List, ExamplesRenderedAs.PartOfDescription); - for(const [objectName] of mdTables){ - try{ - const fileName = `${objectName}.md`; - await fs.writeFile(path.join(...PATH_TO_GERENATED_TABLES, fileName), stm.render(objectName)) - console.log(`Generated markdown table in ${fileName}`) - }catch(e){ - console.log(`Error for ${objectName}`, e) - - } +export const buildMdTablesFromOpenApi = async () => { + const stm = new SchemaToMarkdownTable( + openApi.components.schemas, + RenderMode.List, + ExamplesRenderedAs.PartOfDescription + ); + for (const [objectName] of mdTables) { + try { + const fileName = `${objectName}.md`; + await fs.writeFile( + path.join(...PATH_TO_GERENATED_TABLES, fileName), + stm.render(objectName) + ); + console.log(`Generated markdown table in ${fileName}`); + } catch (e) { + console.log(`Error for ${objectName}`, e); } - console.log('done') -})() \ No newline at end of file + } + console.log("done"); +}; + +buildMdTablesFromOpenApi(); diff --git a/scripts/manage-project.ts b/scripts/manage-project.ts index 239217d37..9726d38b8 100644 --- a/scripts/manage-project.ts +++ b/scripts/manage-project.ts @@ -1,13 +1,16 @@ import dotenv from "dotenv"; import minimist from "minimist"; import colors from "colors"; +import { exec } from "child_process"; +import { buildMdTablesFromOpenApi } from "./build-md-tables-from-openapi"; +import { updateMdTablesInDoc } from "./update-md-tables-in-doc"; dotenv.config(); const options = minimist(process.argv.slice(2)); const versionTag = options.versionTag || options.vt; const versionOption = options.version || options.v; -const cleanOnly = options.cleanOnly || options.co; +const createNew = options.create || options.c; const help = options.help || options.h; const mainVersion = "v2018-08-01"; @@ -33,8 +36,9 @@ const main = async () => { `options:` + `\n"versionTag" or "vt" for versionTag, for example "npm run manage-project -- --vt=piotr-1234"` + `\n"version" or "v" for version, for example "npm run manage-project -- --v=v2018-08-01-piotr-1234"` + - `\n"cleanOnly" or "co" for version, for example "npm run manage-project -- --vt=piotr-1234" --co` + - `\n\nuse "versionTag" or "version" for version, not both!` + `\n"create" or "c" for version, for example "npm run manage-project -- --vt=piotr-1234" --c` + + `\n\nuse "versionTag" or "version" for version, not both!` + + `\n\nby default, cleans up version (not creates one)` ) ); return; @@ -47,11 +51,78 @@ const main = async () => { ); return; } - if (!cleanOnly) { + if (createNew) { await createNewVersion(version); } await cleanProject(version); - console.log(colors.green(`\nVisit: https://docs.voucherify.io/${version}/`)); + console.log( + colors.green( + "UPLOADING OPEN API FILE... PLEASE WAIT... THIS MAY TAKE UP TO A MINUTE" + ) + ); + await new Promise((resolve) => { + exec( + `rdme openapi ./reference/OpenAPI.json --version=${version} --create`, + (error, stdout, stderr) => { + if ( + error + ?.toString?.() + ?.includes?.( + `We're sorry, your upload request timed out. Please try again or split your file up into smaller chunks.` + ) || + stderr + ) { + console.log(colors.green("OPEN API FILE WAS UPLOADED")); + return resolve(true); + } + throw new Error( + error?.toString?.() || "OPEN API FILE WAS NOT UPLOADED" + ); + } + ); + }); + console.log(colors.green("BUILDING MD TABLES FROM OPEN API...")); + await new Promise((resolve) => { + exec(`npm run build-md-tables-from-openapi`, (error, stdout, stderr) => { + if (stderr) { + console.log(colors.green("MD TABLES WERE BUILDED SUCCESSFULLY!")); + return resolve(true); + } + console.log(colors.red(error?.toString?.())); + throw new Error("MD TABLES WERE NOT BUILDED!"); + }); + }); + console.log(colors.green("UPDATING MD TABLES IN DOCS...")); + await new Promise((resolve) => { + exec(`npm run update-md-tables-in-doc`, (error, stdout, stderr) => { + if (stderr) { + console.log( + colors.green("MD TABLES WERE UPDATED IN DOCS SUCCESSFULLY!") + ); + return resolve(true); + } + console.log(colors.red(error?.toString?.())); + throw new Error("MD TABLES WERE NOT UPDATED IN DOCS!"); + }); + }); + console.log(colors.green("UPLOADING GUIDES DOC FILES...")); + await new Promise((resolve) => { + exec( + `rdme docs ./docs/guides --version=${version} --create`, + (error, stdout, stderr) => { + if (stderr) { + console.log(colors.green("GUIDES FILES WERE UPLOADED!")); + return resolve(true); + } + console.log(colors.red(error?.toString?.())); + throw new Error("GUIDES WERE NOT UPLOADED!"); + } + ); + }); + + console.log( + colors.green(`\n\nDONE!\nVisit: https://docs.voucherify.io/${version}/`) + ); }; const createNewVersion = async (version) => { diff --git a/scripts/update-md-tables-in-doc.ts b/scripts/update-md-tables-in-doc.ts index ba3bc0ee7..8014e3861 100644 --- a/scripts/update-md-tables-in-doc.ts +++ b/scripts/update-md-tables-in-doc.ts @@ -1,56 +1,70 @@ -import * as fs from 'fs/promises' -import path from 'path'; -import { EOL } from 'os'; -import { mdTables } from './md-tables'; - -const PATH_TO_DOCS_REFERENCE = [__dirname, '../docs/reference-docs']; -const PATH_TO_GENERATED_TABLES = [__dirname, './output']; - -const updateMdTablesInDoc = async () => { - for (const [objectName, docFile] of mdTables) { - if (!docFile) { - continue; - } - try { - const docPath = path.join(...PATH_TO_DOCS_REFERENCE, docFile); - const fileContent = await fs.readFile(docPath) - const fileContentBlocks = fileContent - .toString() - .split(/(^---$)|(^\[block\:html\]$)/m) // Split by `---` and [block:html] that surrounds the table - .filter(e => !!e); - - // Find block with table by part of the markdown table syntax - const contentBlockIndexWithTableToReplace = fileContentBlocks.findIndex(block => block.indexOf('|:-----') >= 0) - - if (contentBlockIndexWithTableToReplace < 0) { - throw new Error(`Could not find table to replace in file ${docFile} (object: ${objectName}) `) - } - - const additionalBlockquotes = fileContentBlocks[contentBlockIndexWithTableToReplace].match(/^\>.*$/gm) - - const contentBeforeTable = fileContentBlocks.slice(0, contentBlockIndexWithTableToReplace).join('') - const contentAfterTable = fileContentBlocks.slice(contentBlockIndexWithTableToReplace + 1).join('') - - const newTable = (await fs.readFile(path.join(...PATH_TO_GENERATED_TABLES, `${objectName}.md`))) - .toString(); - // .replace((/^\# .*$/m), ''); // Remove first header as in readme.io it already exists - - const newFileContent = [ - contentBeforeTable, - additionalBlockquotes?.length? additionalBlockquotes.join(EOL) : false, - newTable, - contentAfterTable - ].filter(e => !!e) - .join(`${EOL}${EOL}`) - - await fs.writeFile(docPath, newFileContent) - console.log(`Updated table in ${docFile} `) - } catch (e) { - console.log(`Error for ${objectName}`, e) - - } +import * as fs from "fs/promises"; +import path from "path"; +import { EOL } from "os"; +import { mdTables } from "./md-tables"; + +const PATH_TO_DOCS_REFERENCE = [__dirname, "../docs/reference-docs"]; +const PATH_TO_GENERATED_TABLES = [__dirname, "./output"]; + +export const updateMdTablesInDoc = async () => { + for (const [objectName, docFile] of mdTables) { + if (!docFile) { + continue; + } + try { + const docPath = path.join(...PATH_TO_DOCS_REFERENCE, docFile); + const fileContent = await fs.readFile(docPath); + const fileContentBlocks = fileContent + .toString() + .split(/(^---$)|(^\[block\:html\]$)/m) // Split by `---` and [block:html] that surrounds the table + .filter((e) => !!e); + + // Find block with table by part of the markdown table syntax + const contentBlockIndexWithTableToReplace = fileContentBlocks.findIndex( + (block) => block.indexOf("|:-----") >= 0 + ); + + if (contentBlockIndexWithTableToReplace < 0) { + throw new Error( + `Could not find table to replace in file ${docFile} (object: ${objectName}) ` + ); + } + + const additionalBlockquotes = + fileContentBlocks[contentBlockIndexWithTableToReplace].match( + /^\>.*$/gm + ); + + const contentBeforeTable = fileContentBlocks + .slice(0, contentBlockIndexWithTableToReplace) + .join(""); + const contentAfterTable = fileContentBlocks + .slice(contentBlockIndexWithTableToReplace + 1) + .join(""); + + const newTable = ( + await fs.readFile( + path.join(...PATH_TO_GENERATED_TABLES, `${objectName}.md`) + ) + ).toString(); + // .replace((/^\# .*$/m), ''); // Remove first header as in readme.io it already exists + + const newFileContent = [ + contentBeforeTable, + additionalBlockquotes?.length ? additionalBlockquotes.join(EOL) : false, + newTable, + contentAfterTable, + ] + .filter((e) => !!e) + .join(`${EOL}${EOL}`); + + await fs.writeFile(docPath, newFileContent); + console.log(`Updated table in ${docFile} `); + } catch (e) { + console.log(`Error for ${objectName}`, e); } - console.log('done') -} + } + console.log("done"); +}; updateMdTablesInDoc(); From 41e78a5b3cde50a900f7683f469e996873ea93f8 Mon Sep 17 00:00:00 2001 From: p-zielinski <82354717+p-zielinski@users.noreply.github.com> Date: Tue, 17 Oct 2023 13:33:10 +0200 Subject: [PATCH 06/16] done --- scripts/manage-project.ts | 125 +++++++++++++++++++++++++++++++------- 1 file changed, 103 insertions(+), 22 deletions(-) diff --git a/scripts/manage-project.ts b/scripts/manage-project.ts index 9726d38b8..8dcee5825 100644 --- a/scripts/manage-project.ts +++ b/scripts/manage-project.ts @@ -9,8 +9,7 @@ dotenv.config(); const options = minimist(process.argv.slice(2)); const versionTag = options.versionTag || options.vt; const versionOption = options.version || options.v; - -const createNew = options.create || options.c; +const { create, update } = options; const help = options.help || options.h; const mainVersion = "v2018-08-01"; @@ -34,11 +33,17 @@ const main = async () => { console.log( colors.green( `options:` + - `\n"versionTag" or "vt" for versionTag, for example "npm run manage-project -- --vt=piotr-1234"` + - `\n"version" or "v" for version, for example "npm run manage-project -- --v=v2018-08-01-piotr-1234"` + - `\n"create" or "c" for version, for example "npm run manage-project -- --vt=piotr-1234" --c` + - `\n\nuse "versionTag" or "version" for version, not both!` + - `\n\nby default, cleans up version (not creates one)` + `\n"versionTag" or "vt" for versionTag` + + `\n"version" or "v" for version` + + `\n"create" if you want to create such version` + + `\n"update" if you want to update such version` + + `\n\nversionTag or version is required!` + + `\ncreate or update option is required!` + + `\n\nexamples:` + + `\nnpm run manage-project -- --vt=piotr-123 --create` + + `\nnpm run manage-project -- --v=v2018-08-01-piotr-123 --create` + + `\nnpm run manage-project -- --vt=piotr-123 --update` + + `\nnpm run manage-project -- --v=v2018-08-01-piotr-123 --update` ) ); return; @@ -46,12 +51,28 @@ const main = async () => { if (!version) { console.log( colors.red( - "invalid arguments, check `help` for more information\nrun 'npm run manage-project -- --help'" + "invalid arguments, missing `version` or `versionTag`, check `help` for more information\nrun 'npm run manage-project -- --help'" + ) + ); + return; + } + if (!create && !update) { + console.log( + colors.red( + "invalid arguments, missing `update` or `create`, check `help` for more information\nrun 'npm run manage-project -- --help'" + ) + ); + return; + } + if (create && update) { + console.log( + colors.red( + "invalid arguments, you provided conflicting arguments `update` and `create`, check `help` for more information\nrun 'npm run manage-project -- --help'" ) ); return; } - if (createNew) { + if (create) { await createNewVersion(version); } await cleanProject(version); @@ -70,7 +91,7 @@ const main = async () => { ?.includes?.( `We're sorry, your upload request timed out. Please try again or split your file up into smaller chunks.` ) || - stderr + stdout ) { console.log(colors.green("OPEN API FILE WAS UPLOADED")); return resolve(true); @@ -84,7 +105,7 @@ const main = async () => { console.log(colors.green("BUILDING MD TABLES FROM OPEN API...")); await new Promise((resolve) => { exec(`npm run build-md-tables-from-openapi`, (error, stdout, stderr) => { - if (stderr) { + if (stdout) { console.log(colors.green("MD TABLES WERE BUILDED SUCCESSFULLY!")); return resolve(true); } @@ -95,7 +116,7 @@ const main = async () => { console.log(colors.green("UPDATING MD TABLES IN DOCS...")); await new Promise((resolve) => { exec(`npm run update-md-tables-in-doc`, (error, stdout, stderr) => { - if (stderr) { + if (stdout) { console.log( colors.green("MD TABLES WERE UPDATED IN DOCS SUCCESSFULLY!") ); @@ -108,23 +129,80 @@ const main = async () => { console.log(colors.green("UPLOADING GUIDES DOC FILES...")); await new Promise((resolve) => { exec( - `rdme docs ./docs/guides --version=${version} --create`, + `rdme docs ./docs/guides --version=${version}`, (error, stdout, stderr) => { - if (stderr) { - console.log(colors.green("GUIDES FILES WERE UPLOADED!")); + if (stdout?.includes("successfully created")) { + console.log(colors.green("GUIDES DOC FILES WERE UPLOADED!")); return resolve(true); } console.log(colors.red(error?.toString?.())); - throw new Error("GUIDES WERE NOT UPLOADED!"); + throw new Error("GUIDES DOC WERE NOT UPLOADED!"); } ); }); - + console.log(colors.green("UPLOADING REFERENCE DOC FILES...")); + const maxNumberOfUploadingAttempts = 3; + for (let i = 1; i <= maxNumberOfUploadingAttempts; i++) { + const success = await updateReferenceDocs(version); + if (success) { + console.log(colors.green("REFERENCE DOC FILES WERE UPLOADED!")); + break; + } + if (i === maxNumberOfUploadingAttempts) { + throw new Error("REFERENCE DOC WERE NOT UPLOADED!"); + } + await new Promise((r) => setTimeout(r, 10000)); + } + // console.log( + // colors.green( + // "FIXING TYPES AND ORDER OF OPEN API REFERENCES IN README.IO..." + // ) + // ); + // await new Promise((resolve) => { + // exec( + // `npm run readme-fix-reference-docs -- --version=${version}`, + // (error, stdout, stderr) => { + // if (stdout) { + // console.log( + // colors.green( + // "TYPES AND ORDER OF OPEN API REFERENCES IN README.IO WERE FIXED!" + // ) + // ); + // return resolve(true); + // } + // console.log(colors.red(error?.toString?.())); + // throw new Error( + // "TYPES AND ORDER OF OPEN API REFERENCES IN README.IO WERE NOT FIXED!" + // ); + // } + // ); + // }); console.log( colors.green(`\n\nDONE!\nVisit: https://docs.voucherify.io/${version}/`) ); }; +const updateReferenceDocs = async (version) => { + return await new Promise((resolve, reject) => { + exec( + `rdme docs ./docs/reference-docs --version=${version}`, + (error, stdout, stderr) => { + if ( + stderr?.includes( + `We couldn't save this doc (Unable to find a category with the slug 'voucherify-api')` + ) + ) { + return resolve(false); + } + if (stdout?.includes("successfully created")) { + return resolve(true); + } + return resolve(false); + } + ); + }); +}; + const createNewVersion = async (version) => { //create fork try { @@ -169,11 +247,13 @@ const cleanProject = async (version) => { async (category) => await deleteCategory(version, category.slug) ); console.log(colors.green(`OLD CATEGORIES DELETED!`)); - //create categories - await asyncMap( - [...listOfGuideCategories, ...listOfReferenceCategories], - async (title) => await createCategory(version, title) - ); + //create categories one by one (creation order is important) + for (const categoryTitle of [ + ...listOfGuideCategories, + ...listOfReferenceCategories, + ]) { + await createCategory(version, categoryTitle); + } console.log(colors.green(`NEW CATEGORIES CREATED!`)); const allCategories = await getAllCategories(version); //update reference categories types @@ -191,6 +271,7 @@ const cleanProject = async (version) => { await asyncMap(allApiSpecifications, deleteSpecification); console.log(colors.green(`API SPECIFICATIONS DELETED!`)); console.log(colors.green(`VERSION "${version}" IS CLEANED UP!`)); + return; }; const updateCategory = async (version, slug, data = {}) => { From 76bdbcd4e66d964e18e11b47c67669b43df66f0b Mon Sep 17 00:00:00 2001 From: p-zielinski <82354717+p-zielinski@users.noreply.github.com> Date: Tue, 17 Oct 2023 13:40:38 +0200 Subject: [PATCH 07/16] Update manage-project.ts --- scripts/manage-project.ts | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/scripts/manage-project.ts b/scripts/manage-project.ts index 8dcee5825..f83b96f8c 100644 --- a/scripts/manage-project.ts +++ b/scripts/manage-project.ts @@ -153,30 +153,6 @@ const main = async () => { } await new Promise((r) => setTimeout(r, 10000)); } - // console.log( - // colors.green( - // "FIXING TYPES AND ORDER OF OPEN API REFERENCES IN README.IO..." - // ) - // ); - // await new Promise((resolve) => { - // exec( - // `npm run readme-fix-reference-docs -- --version=${version}`, - // (error, stdout, stderr) => { - // if (stdout) { - // console.log( - // colors.green( - // "TYPES AND ORDER OF OPEN API REFERENCES IN README.IO WERE FIXED!" - // ) - // ); - // return resolve(true); - // } - // console.log(colors.red(error?.toString?.())); - // throw new Error( - // "TYPES AND ORDER OF OPEN API REFERENCES IN README.IO WERE NOT FIXED!" - // ); - // } - // ); - // }); console.log( colors.green(`\n\nDONE!\nVisit: https://docs.voucherify.io/${version}/`) ); @@ -228,7 +204,7 @@ https://dash.readme.com/api/v1/version`, ); if (response.status !== 200) { throw new Error( - `Response status: ${response.status}, maybe this versionTag is already used?` + `Response status: ${response.status}, maybe this versionTag is already created?` ); } console.log(colors.green(`FORK CREATED! VERSION "${version}"`)); From a4f071876f64656a56ff870f12193e29b3acf196 Mon Sep 17 00:00:00 2001 From: p-zielinski <82354717+p-zielinski@users.noreply.github.com> Date: Tue, 17 Oct 2023 15:14:56 +0200 Subject: [PATCH 08/16] Update manage-project.ts --- scripts/manage-project.ts | 243 ++++++++++++++++++++++++-------------- 1 file changed, 152 insertions(+), 91 deletions(-) diff --git a/scripts/manage-project.ts b/scripts/manage-project.ts index f83b96f8c..ebb556816 100644 --- a/scripts/manage-project.ts +++ b/scripts/manage-project.ts @@ -4,14 +4,16 @@ import colors from "colors"; import { exec } from "child_process"; import { buildMdTablesFromOpenApi } from "./build-md-tables-from-openapi"; import { updateMdTablesInDoc } from "./update-md-tables-in-doc"; +import { boolean } from "yup"; dotenv.config(); const options = minimist(process.argv.slice(2)); const versionTag = options.versionTag || options.vt; const versionOption = options.version || options.v; + +//globals const { create, update } = options; const help = options.help || options.h; - const mainVersion = "v2018-08-01"; const version = versionOption || versionTag ? `${mainVersion}-${versionTag}` : undefined; @@ -28,134 +30,169 @@ const listOfGuideCategories = [ const listOfReferenceCategories = ["Introduction"]; -const main = async () => { - if (help) { - console.log( - colors.green( - `options:` + - `\n"versionTag" or "vt" for versionTag` + - `\n"version" or "v" for version` + - `\n"create" if you want to create such version` + - `\n"update" if you want to update such version` + - `\n\nversionTag or version is required!` + - `\ncreate or update option is required!` + - `\n\nexamples:` + - `\nnpm run manage-project -- --vt=piotr-123 --create` + - `\nnpm run manage-project -- --v=v2018-08-01-piotr-123 --create` + - `\nnpm run manage-project -- --vt=piotr-123 --update` + - `\nnpm run manage-project -- --v=v2018-08-01-piotr-123 --update` - ) - ); - return; - } - if (!version) { - console.log( - colors.red( - "invalid arguments, missing `version` or `versionTag`, check `help` for more information\nrun 'npm run manage-project -- --help'" - ) - ); - return; - } - if (!create && !update) { - console.log( - colors.red( - "invalid arguments, missing `update` or `create`, check `help` for more information\nrun 'npm run manage-project -- --help'" - ) - ); - return; - } - if (create && update) { - console.log( - colors.red( - "invalid arguments, you provided conflicting arguments `update` and `create`, check `help` for more information\nrun 'npm run manage-project -- --help'" - ) - ); +const main = async ({ + help, + version, + create, + update, +}: { + help?: boolean; + version?: string; + create?: boolean; + update?: boolean; +}) => { + const valid = validateOptions({ help, version, create, update }); + if (!valid) { return; } if (create) { await createNewVersion(version); } await cleanProject(version); + await uploadOpenApiFile(version); + await buildMdTables(); + await updateMdTablesInDocs(); + await uploadGuideFiles(version); + await uploadReferenceDocsWithMaxNumberOfAttempts(version); console.log( - colors.green( - "UPLOADING OPEN API FILE... PLEASE WAIT... THIS MAY TAKE UP TO A MINUTE" - ) + colors.green(`\n\nDONE!\nVisit: https://docs.voucherify.io/${version}/`) ); +}; + +const uploadReferenceDocsWithMaxNumberOfAttempts = async ( + version, + maxNumberOfUploadingAttempts = 6, + timeoutAfterEachFail = 5000 +) => { + console.log(colors.green("UPLOADING REFERENCE DOC FILES...")); + for (let i = 1; i <= maxNumberOfUploadingAttempts; i++) { + const success = await updateReferenceDocs(version); + if (success) { + console.log(colors.green("REFERENCE DOC FILES WERE UPLOADED!")); + break; + } + if (i === maxNumberOfUploadingAttempts) { + throw new Error("REFERENCE DOC WERE NOT UPLOADED!"); + } + await new Promise((r) => setTimeout(r, timeoutAfterEachFail)); + } +}; + +const uploadGuideFiles = async (version) => { + console.log(colors.green("UPLOADING GUIDES DOC FILES...")); await new Promise((resolve) => { exec( - `rdme openapi ./reference/OpenAPI.json --version=${version} --create`, + `rdme docs ./docs/guides --version=${version}`, (error, stdout, stderr) => { - if ( - error - ?.toString?.() - ?.includes?.( - `We're sorry, your upload request timed out. Please try again or split your file up into smaller chunks.` - ) || - stdout - ) { - console.log(colors.green("OPEN API FILE WAS UPLOADED")); + if (stdout?.includes("successfully created")) { + console.log(colors.green("GUIDES DOC FILES WERE UPLOADED!")); return resolve(true); } - throw new Error( - error?.toString?.() || "OPEN API FILE WAS NOT UPLOADED" - ); + console.log(colors.red(error?.toString?.())); + throw new Error("GUIDES DOC WERE NOT UPLOADED!"); } ); }); - console.log(colors.green("BUILDING MD TABLES FROM OPEN API...")); +}; + +const updateMdTablesInDocs = async () => { + console.log(colors.green("UPDATING MD TABLES IN DOCS...")); await new Promise((resolve) => { - exec(`npm run build-md-tables-from-openapi`, (error, stdout, stderr) => { + exec(`npm run update-md-tables-in-doc`, (error, stdout, stderr) => { if (stdout) { - console.log(colors.green("MD TABLES WERE BUILDED SUCCESSFULLY!")); + console.log( + colors.green("MD TABLES WERE UPDATED IN DOCS SUCCESSFULLY!") + ); return resolve(true); } console.log(colors.red(error?.toString?.())); - throw new Error("MD TABLES WERE NOT BUILDED!"); + throw new Error("MD TABLES WERE NOT UPDATED IN DOCS!"); }); }); - console.log(colors.green("UPDATING MD TABLES IN DOCS...")); +}; +const buildMdTables = async () => { + console.log(colors.green("BUILDING MD TABLES FROM OPEN API...")); await new Promise((resolve) => { - exec(`npm run update-md-tables-in-doc`, (error, stdout, stderr) => { + exec(`npm run build-md-tables-from-openapi`, (error, stdout, stderr) => { if (stdout) { - console.log( - colors.green("MD TABLES WERE UPDATED IN DOCS SUCCESSFULLY!") - ); + console.log(colors.green("MD TABLES WERE BUILDED SUCCESSFULLY!")); return resolve(true); } console.log(colors.red(error?.toString?.())); - throw new Error("MD TABLES WERE NOT UPDATED IN DOCS!"); + throw new Error("MD TABLES WERE NOT BUILDED!"); }); }); - console.log(colors.green("UPLOADING GUIDES DOC FILES...")); +}; + +const uploadOpenApiFile = async (version) => { + console.log( + colors.green( + "UPLOADING OPEN API FILE... PLEASE WAIT... THIS MAY TAKE UP TO A MINUTE" + ) + ); await new Promise((resolve) => { exec( - `rdme docs ./docs/guides --version=${version}`, + `rdme openapi ./reference/OpenAPI.json --version=${version} --create`, (error, stdout, stderr) => { - if (stdout?.includes("successfully created")) { - console.log(colors.green("GUIDES DOC FILES WERE UPLOADED!")); + if ( + error + ?.toString?.() + ?.includes?.( + `We're sorry, your upload request timed out. Please try again or split your file up into smaller chunks.` + ) || + stdout + ) { + console.log(colors.green("OPEN API FILE WAS UPLOADED")); return resolve(true); } - console.log(colors.red(error?.toString?.())); - throw new Error("GUIDES DOC WERE NOT UPLOADED!"); + throw new Error( + error?.toString?.() || "OPEN API FILE WAS NOT UPLOADED" + ); } ); }); - console.log(colors.green("UPLOADING REFERENCE DOC FILES...")); - const maxNumberOfUploadingAttempts = 3; - for (let i = 1; i <= maxNumberOfUploadingAttempts; i++) { - const success = await updateReferenceDocs(version); - if (success) { - console.log(colors.green("REFERENCE DOC FILES WERE UPLOADED!")); - break; - } - if (i === maxNumberOfUploadingAttempts) { - throw new Error("REFERENCE DOC WERE NOT UPLOADED!"); - } - await new Promise((r) => setTimeout(r, 10000)); +}; + +const validateOptions = ({ + help, + version, + create, + update, +}: { + help?: boolean; + version?: string; + create?: boolean; + update?: boolean; +}) => { + if (help || (!version && !create && !update)) { + printHelp(); + return false; } - console.log( - colors.green(`\n\nDONE!\nVisit: https://docs.voucherify.io/${version}/`) - ); + if (!version) { + console.log( + colors.red( + "invalid arguments, missing `version` or `versionTag`, check `help` for more information\nrun 'npm run manage-project -- --help'" + ) + ); + return false; + } + if (!create && !update) { + console.log( + colors.red( + "invalid arguments, missing `update` or `create`, check `help` for more information\nrun 'npm run manage-project -- --help'" + ) + ); + return false; + } + if (create && update) { + console.log( + colors.red( + "invalid arguments, you provided conflicting arguments `update` and `create`, check `help` for more information\nrun 'npm run manage-project -- --help'" + ) + ); + return false; + } + return true; }; const updateReferenceDocs = async (version) => { @@ -329,4 +366,28 @@ const asyncMap = (arr, asyncFn) => { return Promise.all(arr.map(asyncFn)); }; -main(); +const printHelp = () => { + console.log( + colors.green( + `options:` + + `\n"versionTag" or "vt" for versionTag` + + `\n"version" or "v" for version` + + `\n"create" if you want to create such version` + + `\n"update" if you want to update such version` + + `\n\nversionTag or version is required!` + + `\ncreate or update option is required!` + + `\n\nexamples:` + + `\nnpm run manage-project -- --vt=piotr-123 --create` + + `\nnpm run manage-project -- --v=v2018-08-01-piotr-123 --create` + + `\nnpm run manage-project -- --vt=piotr-123 --update` + + `\nnpm run manage-project -- --v=v2018-08-01-piotr-123 --update` + ) + ); +}; + +main({ + help, + version, + create, + update, +}); From af514be09671abda856458455065e1aa5e830020 Mon Sep 17 00:00:00 2001 From: p-zielinski <82354717+p-zielinski@users.noreply.github.com> Date: Tue, 17 Oct 2023 15:15:07 +0200 Subject: [PATCH 09/16] Update manage-project.ts --- scripts/manage-project.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/scripts/manage-project.ts b/scripts/manage-project.ts index ebb556816..6891970d0 100644 --- a/scripts/manage-project.ts +++ b/scripts/manage-project.ts @@ -2,16 +2,11 @@ import dotenv from "dotenv"; import minimist from "minimist"; import colors from "colors"; import { exec } from "child_process"; -import { buildMdTablesFromOpenApi } from "./build-md-tables-from-openapi"; -import { updateMdTablesInDoc } from "./update-md-tables-in-doc"; -import { boolean } from "yup"; dotenv.config(); const options = minimist(process.argv.slice(2)); const versionTag = options.versionTag || options.vt; const versionOption = options.version || options.v; - -//globals const { create, update } = options; const help = options.help || options.h; const mainVersion = "v2018-08-01"; From b6f118ee72cff99c280f8959370ef9c8fe122e6a Mon Sep 17 00:00:00 2001 From: p-zielinski <82354717+p-zielinski@users.noreply.github.com> Date: Tue, 17 Oct 2023 15:41:06 +0200 Subject: [PATCH 10/16] Update manage-project.ts --- scripts/manage-project.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/scripts/manage-project.ts b/scripts/manage-project.ts index 6891970d0..517cf516b 100644 --- a/scripts/manage-project.ts +++ b/scripts/manage-project.ts @@ -73,6 +73,31 @@ const uploadReferenceDocsWithMaxNumberOfAttempts = async ( } }; +const runProcess = async ({ + command, + stdoutIncludes, + stderrIncludes, +}: { + command: string; + stdoutIncludes?: string; + stderrIncludes?: string; +}) => { + await new Promise((resolve) => { + exec(command, (error, stdout, stderr) => { + if ( + (stdoutIncludes && stdout?.includes(stdoutIncludes)) || + (!stdoutIncludes && stdout) || + (stderrIncludes && stderr.includes(stderrIncludes)) + ) { + return resolve(true); + } + if (stderr) { + console.log(stderr); + } + throw error; + }); + }); +}; const uploadGuideFiles = async (version) => { console.log(colors.green("UPLOADING GUIDES DOC FILES...")); await new Promise((resolve) => { From 286ffd4b7c57371491e86cc9d4c79e24f1d358cf Mon Sep 17 00:00:00 2001 From: p-zielinski <82354717+p-zielinski@users.noreply.github.com> Date: Tue, 17 Oct 2023 16:18:32 +0200 Subject: [PATCH 11/16] Update manage-project.ts --- scripts/manage-project.ts | 173 ++++++++++++++++---------------------- 1 file changed, 72 insertions(+), 101 deletions(-) diff --git a/scripts/manage-project.ts b/scripts/manage-project.ts index 517cf516b..d871a1ee9 100644 --- a/scripts/manage-project.ts +++ b/scripts/manage-project.ts @@ -56,33 +56,39 @@ const main = async ({ const uploadReferenceDocsWithMaxNumberOfAttempts = async ( version, - maxNumberOfUploadingAttempts = 6, - timeoutAfterEachFail = 5000 + maxNumberOfUploadingAttempts = 6 ) => { console.log(colors.green("UPLOADING REFERENCE DOC FILES...")); for (let i = 1; i <= maxNumberOfUploadingAttempts; i++) { - const success = await updateReferenceDocs(version); + await new Promise((r) => setTimeout(r, 5000)); + const success = await runCliProcess({ + command: `rdme docs ./docs/reference-docs --version=${version}`, + stdoutIncludes: "successfully created", + resolveErrorAsFalse: true, + }); if (success) { console.log(colors.green("REFERENCE DOC FILES WERE UPLOADED!")); break; } if (i === maxNumberOfUploadingAttempts) { - throw new Error("REFERENCE DOC WERE NOT UPLOADED!"); + throw new Error("REFERENCE DOC FILES WERE NOT UPLOADED!"); } - await new Promise((r) => setTimeout(r, timeoutAfterEachFail)); } + return; }; -const runProcess = async ({ +const runCliProcess = async ({ command, stdoutIncludes, stderrIncludes, + resolveErrorAsFalse = false, }: { command: string; stdoutIncludes?: string; stderrIncludes?: string; + resolveErrorAsFalse?: boolean; }) => { - await new Promise((resolve) => { + return await new Promise((resolve) => { exec(command, (error, stdout, stderr) => { if ( (stdoutIncludes && stdout?.includes(stdoutIncludes)) || @@ -91,6 +97,9 @@ const runProcess = async ({ ) { return resolve(true); } + if (resolveErrorAsFalse) { + return resolve(false); + } if (stderr) { console.log(stderr); } @@ -100,48 +109,26 @@ const runProcess = async ({ }; const uploadGuideFiles = async (version) => { console.log(colors.green("UPLOADING GUIDES DOC FILES...")); - await new Promise((resolve) => { - exec( - `rdme docs ./docs/guides --version=${version}`, - (error, stdout, stderr) => { - if (stdout?.includes("successfully created")) { - console.log(colors.green("GUIDES DOC FILES WERE UPLOADED!")); - return resolve(true); - } - console.log(colors.red(error?.toString?.())); - throw new Error("GUIDES DOC WERE NOT UPLOADED!"); - } - ); + await runCliProcess({ + command: `rdme docs ./docs/guides --version=${version}`, + stdoutIncludes: "successfully created", }); + console.log(colors.green("GUIDES DOC FILES WERE UPLOADED!")); }; const updateMdTablesInDocs = async () => { console.log(colors.green("UPDATING MD TABLES IN DOCS...")); - await new Promise((resolve) => { - exec(`npm run update-md-tables-in-doc`, (error, stdout, stderr) => { - if (stdout) { - console.log( - colors.green("MD TABLES WERE UPDATED IN DOCS SUCCESSFULLY!") - ); - return resolve(true); - } - console.log(colors.red(error?.toString?.())); - throw new Error("MD TABLES WERE NOT UPDATED IN DOCS!"); - }); + await runCliProcess({ + command: `npm run update-md-tables-in-doc`, }); + console.log(colors.green("MD TABLES WERE UPDATED IN DOCS SUCCESSFULLY!")); }; const buildMdTables = async () => { console.log(colors.green("BUILDING MD TABLES FROM OPEN API...")); - await new Promise((resolve) => { - exec(`npm run build-md-tables-from-openapi`, (error, stdout, stderr) => { - if (stdout) { - console.log(colors.green("MD TABLES WERE BUILDED SUCCESSFULLY!")); - return resolve(true); - } - console.log(colors.red(error?.toString?.())); - throw new Error("MD TABLES WERE NOT BUILDED!"); - }); + await runCliProcess({ + command: `npm run build-md-tables-from-openapi`, }); + console.log(colors.green("MD TABLES WERE BUILDED SUCCESSFULLY!")); }; const uploadOpenApiFile = async (version) => { @@ -150,69 +137,11 @@ const uploadOpenApiFile = async (version) => { "UPLOADING OPEN API FILE... PLEASE WAIT... THIS MAY TAKE UP TO A MINUTE" ) ); - await new Promise((resolve) => { - exec( - `rdme openapi ./reference/OpenAPI.json --version=${version} --create`, - (error, stdout, stderr) => { - if ( - error - ?.toString?.() - ?.includes?.( - `We're sorry, your upload request timed out. Please try again or split your file up into smaller chunks.` - ) || - stdout - ) { - console.log(colors.green("OPEN API FILE WAS UPLOADED")); - return resolve(true); - } - throw new Error( - error?.toString?.() || "OPEN API FILE WAS NOT UPLOADED" - ); - } - ); + await runCliProcess({ + command: `rdme openapi ./reference/OpenAPI.json --version=${version} --create`, + stderrIncludes: `We're sorry, your upload request timed out. Please try again or split your file up into smaller chunks.`, }); -}; - -const validateOptions = ({ - help, - version, - create, - update, -}: { - help?: boolean; - version?: string; - create?: boolean; - update?: boolean; -}) => { - if (help || (!version && !create && !update)) { - printHelp(); - return false; - } - if (!version) { - console.log( - colors.red( - "invalid arguments, missing `version` or `versionTag`, check `help` for more information\nrun 'npm run manage-project -- --help'" - ) - ); - return false; - } - if (!create && !update) { - console.log( - colors.red( - "invalid arguments, missing `update` or `create`, check `help` for more information\nrun 'npm run manage-project -- --help'" - ) - ); - return false; - } - if (create && update) { - console.log( - colors.red( - "invalid arguments, you provided conflicting arguments `update` and `create`, check `help` for more information\nrun 'npm run manage-project -- --help'" - ) - ); - return false; - } - return true; + console.log(colors.green("OPEN API FILE WAS UPLOADED")); }; const updateReferenceDocs = async (version) => { @@ -386,6 +315,48 @@ const asyncMap = (arr, asyncFn) => { return Promise.all(arr.map(asyncFn)); }; +const validateOptions = ({ + help, + version, + create, + update, +}: { + help?: boolean; + version?: string; + create?: boolean; + update?: boolean; +}) => { + if (help || (!version && !create && !update)) { + printHelp(); + return false; + } + if (!version) { + console.log( + colors.red( + "invalid arguments, missing `version` or `versionTag`, check `help` for more information\nrun 'npm run manage-project -- --help'" + ) + ); + return false; + } + if (!create && !update) { + console.log( + colors.red( + "invalid arguments, missing `update` or `create`, check `help` for more information\nrun 'npm run manage-project -- --help'" + ) + ); + return false; + } + if (create && update) { + console.log( + colors.red( + "invalid arguments, you provided conflicting arguments `update` and `create`, check `help` for more information\nrun 'npm run manage-project -- --help'" + ) + ); + return false; + } + return true; +}; + const printHelp = () => { console.log( colors.green( From f7c00d0395551d66ee477340697b4bbb1527c90f Mon Sep 17 00:00:00 2001 From: p-zielinski <82354717+p-zielinski@users.noreply.github.com> Date: Tue, 17 Oct 2023 16:25:07 +0200 Subject: [PATCH 12/16] Update CONTRIBUTING.md --- CONTRIBUTING.md | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d3c1e7d0c..f2ddafbfe 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -106,24 +106,19 @@ Good practices: - Copy `.env.example` to `.env` and add to this file your personal API Key created in readme.io: `dashboard` > `configuration` > `API Keys` ### Development process -- For each change / pull request, create your copy of the current documentation, where you will test changes. - - `npm run manage-project -- --vt={your name}-{pull request number}` - Make changes in the repository following patterns and good practices. -- Deploy changes to test your documentation: - - Deploy OpenAPI file by command `rdme openapi ./reference/OpenAPI.json --version=2018-08-01-{your name}-{pull request number} --create`. - - Update tables in mark down tables: - - `npm run build-md-tables-from-openapi` - - `npm run update-md-tables-in-doc` - - Deploy guides and reference pages: `rdme docs ./docs --version=2018-08-01-{your name}-{pull request number}` - - Fix docs order: `npm run readme-fix-docs-order -- --version=v2018-08-01-{your name}-{pull request number}` -- test changes using preview on readme.io -- if changes are fine, then: +- Run `npm run manage-project -- --vt={your name}-{pull request number or tag number} --create` - this will create new version project with your tag number. +- Visit url provided at the end of the script run to test changes using preview on readme.io +- If you need to make a change: + - Do changes... + - Run `npm run manage-project -- --vt={your name}-{pull request number or tag number} --update`- this will update your version. + - Test changes using preview on readme.io +- If changes are fine, then: - Add a note in the changelog. - `git commit` - `git push` - publish PR - ## How to merge PR and update public documentation - Test changes on readme (you can use the version prepared by the contributor). From e997b2f47cfe98ea4dd31f4768639934aff0a3b3 Mon Sep 17 00:00:00 2001 From: p-zielinski <82354717+p-zielinski@users.noreply.github.com> Date: Tue, 17 Oct 2023 16:25:27 +0200 Subject: [PATCH 13/16] Update CONTRIBUTING.md --- CONTRIBUTING.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f2ddafbfe..1436a5d58 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -115,8 +115,7 @@ Good practices: - Test changes using preview on readme.io - If changes are fine, then: - Add a note in the changelog. - - `git commit` - - `git push` + - `git commit; git push` - publish PR ## How to merge PR and update public documentation From 9248d4ce2b32c8887dd8f23eebc547c629636117 Mon Sep 17 00:00:00 2001 From: p-zielinski <82354717+p-zielinski@users.noreply.github.com> Date: Tue, 17 Oct 2023 16:31:36 +0200 Subject: [PATCH 14/16] minor changes --- CONTRIBUTING.md | 6 +++--- scripts/manage-project.ts | 36 ++++++++++++++++-------------------- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1436a5d58..53f009d51 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -110,9 +110,9 @@ Good practices: - Run `npm run manage-project -- --vt={your name}-{pull request number or tag number} --create` - this will create new version project with your tag number. - Visit url provided at the end of the script run to test changes using preview on readme.io - If you need to make a change: - - Do changes... - - Run `npm run manage-project -- --vt={your name}-{pull request number or tag number} --update`- this will update your version. - - Test changes using preview on readme.io + - Do changes... + - Run `npm run manage-project -- --vt={your name}-{pull request number or tag number} --update`- this will update your version. + - Test changes using preview on readme.io - If changes are fine, then: - Add a note in the changelog. - `git commit; git push` diff --git a/scripts/manage-project.ts b/scripts/manage-project.ts index d871a1ee9..91568583b 100644 --- a/scripts/manage-project.ts +++ b/scripts/manage-project.ts @@ -168,26 +168,22 @@ const updateReferenceDocs = async (version) => { const createNewVersion = async (version) => { //create fork try { - const response = await fetch( - ` -https://dash.readme.com/api/v1/version`, - { - method: "POST", - headers: { - authorization: "Basic " + btoa(process.env.README_IO_AUTH + ":"), - "content-type": "application/json", - accept: "application/json", - }, - body: JSON.stringify({ - is_beta: false, - is_stable: false, - is_hidden: true, - is_deprecated: false, - from: mainVersion, - version, - }), - } - ); + const response = await fetch(`https://dash.readme.com/api/v1/version`, { + method: "POST", + headers: { + authorization: "Basic " + btoa(process.env.README_IO_AUTH + ":"), + "content-type": "application/json", + accept: "application/json", + }, + body: JSON.stringify({ + is_beta: false, + is_stable: false, + is_hidden: true, + is_deprecated: false, + from: mainVersion, + version, + }), + }); if (response.status !== 200) { throw new Error( `Response status: ${response.status}, maybe this versionTag is already created?` From 74af90909ef76a2f9296db9d5bd50eda41726f06 Mon Sep 17 00:00:00 2001 From: p-zielinski <82354717+p-zielinski@users.noreply.github.com> Date: Tue, 17 Oct 2023 16:38:49 +0200 Subject: [PATCH 15/16] Update CONTRIBUTING.md --- CONTRIBUTING.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 53f009d51..6f5c0b131 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -106,13 +106,17 @@ Good practices: - Copy `.env.example` to `.env` and add to this file your personal API Key created in readme.io: `dashboard` > `configuration` > `API Keys` ### Development process +- For each change / pull request, create your copy of the current documentation, where you will test changes. + - Create your own branch from `master`, + - Create a draft pull request - Make changes in the repository following patterns and good practices. -- Run `npm run manage-project -- --vt={your name}-{pull request number or tag number} --create` - this will create new version project with your tag number. +- Run `npm run manage-project -- --vt={your name}-{pull request number} --create` - this will create new version project with your tag number. - Visit url provided at the end of the script run to test changes using preview on readme.io - If you need to make a change: - Do changes... - - Run `npm run manage-project -- --vt={your name}-{pull request number or tag number} --update`- this will update your version. + - Run `npm run manage-project -- --vt={your name}-{pull request number} --update`- this will update your version. - Test changes using preview on readme.io + - If needed - **REPEAT** - If changes are fine, then: - Add a note in the changelog. - `git commit; git push` From b6718159b8c6552333d78dc66e1f410f04dc5812 Mon Sep 17 00:00:00 2001 From: p-zielinski <82354717+p-zielinski@users.noreply.github.com> Date: Tue, 17 Oct 2023 16:45:50 +0200 Subject: [PATCH 16/16] Update manage-project.ts --- scripts/manage-project.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/scripts/manage-project.ts b/scripts/manage-project.ts index 91568583b..0a89ea43f 100644 --- a/scripts/manage-project.ts +++ b/scripts/manage-project.ts @@ -42,6 +42,13 @@ const main = async ({ } if (create) { await createNewVersion(version); + } else if (!(await isVersionExists(version))) { + console.log( + colors.red( + `Version ${version} does not exist! Create it first. Use parameter --update instead of --create` + ) + ); + return; } await cleanProject(version); await uploadOpenApiFile(version); @@ -54,6 +61,23 @@ const main = async ({ ); }; +const isVersionExists = async (version: string) => { + return ( + ( + await fetch( + `https://dash.readme.com/api/v1/api-specification?perPage=100&page=1`, + { + method: "GET", + headers: { + "x-readme-version": version, + authorization: "Basic " + btoa(process.env.README_IO_AUTH + ":"), + }, + } + ) + ).status === 200 + ); +}; + const uploadReferenceDocsWithMaxNumberOfAttempts = async ( version, maxNumberOfUploadingAttempts = 6