From 31d46c87ba3ac9a23bc626bbfabb0f4afb2faeaa Mon Sep 17 00:00:00 2001 From: Adrien Maret Date: Thu, 23 Mar 2023 15:23:20 +0100 Subject: [PATCH] use repositories.json (#13) Co-authored-by: Aschen --- README.md | 35 ++++++++++++++++++++--------------- package-lock.json | 16 +--------------- package.json | 5 ++--- src/commands/add-repo.ts | 6 +++--- src/commands/install.ts | 4 ++-- src/lib/repo.ts | 27 +++++++++++++-------------- 6 files changed, 41 insertions(+), 52 deletions(-) diff --git a/README.md b/README.md index c782a7e..ab497a1 100644 --- a/README.md +++ b/README.md @@ -10,14 +10,16 @@ This is an internal tool used by the Kuzzle team to build the documentation of a [![License](https://img.shields.io/npm/l/kdoc.svg)](https://github.com/kuzzleio/kdoc/blob/master/package.json) -* [kuzdoc](#kuzdoc) -* [Usage](#usage) -* [Commands](#commands) + +- [kuzdoc](#kuzdoc) +- [Usage](#usage) +- [Commands](#commands) # Usage + ```sh-session $ npm install -g kuzdoc $ kuzdoc COMMAND @@ -29,24 +31,26 @@ USAGE $ kuzdoc COMMAND ... ``` + # Commands -* [`kuzdoc add-repo`](#kuzdoc-add-repo) -* [`kuzdoc add-section`](#kuzdoc-add-section) -* [`kuzdoc build-and-deploy`](#kuzdoc-build-and-deploy) -* [`kuzdoc dead-links`](#kuzdoc-dead-links) -* [`kuzdoc dev`](#kuzdoc-dev) -* [`kuzdoc generate:js FILEPATH`](#kuzdoc-generatejs-filepath) -* [`kuzdoc help [COMMAND]`](#kuzdoc-help-command) -* [`kuzdoc install`](#kuzdoc-install) -* [`kuzdoc local-deploy`](#kuzdoc-local-deploy) + +- [`kuzdoc add-repo`](#kuzdoc-add-repo) +- [`kuzdoc add-section`](#kuzdoc-add-section) +- [`kuzdoc build-and-deploy`](#kuzdoc-build-and-deploy) +- [`kuzdoc dead-links`](#kuzdoc-dead-links) +- [`kuzdoc dev`](#kuzdoc-dev) +- [`kuzdoc generate:js FILEPATH`](#kuzdoc-generatejs-filepath) +- [`kuzdoc help [COMMAND]`](#kuzdoc-help-command) +- [`kuzdoc install`](#kuzdoc-install) +- [`kuzdoc local-deploy`](#kuzdoc-local-deploy) ## `kuzdoc add-repo` -Wizard to add a new repo to repositories.yml. +Wizard to add a new repo to repositories.json. ``` USAGE @@ -244,10 +248,10 @@ OPTIONS DESCRIPTION NOTE: This command must be executed from the root of the framework meta-repo. - This command will install one or multiple repos, listed in the repositories.yml file, + This command will install one or multiple repos, listed in the repositories.json file, within the .repos directory of the documentation framework. Repositories will be either cloned from Github or symlink-ed from the local filesystem (--local-path flag). - The repositories.yml file will be fetched from the local instance of the documentation framework. + The repositories.json file will be fetched from the local instance of the documentation framework. Repositories are either specified via the --repo flag, or the KUZDOC_REPO: if no value is specified, kuzdoc will ask it via a prompt. Kuzdoc will not overwrite existing repositories. If a folder with the same name of a selected @@ -276,4 +280,5 @@ DESCRIPTION ``` _See code: [src/commands/local-deploy.ts](https://github.com/kuzzleio/kuzdoc/blob/v2.5.1/src/commands/local-deploy.ts)_ + diff --git a/package-lock.json b/package-lock.json index f4bb907..83246d7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,8 +22,7 @@ "inquirer": "^7.3.3", "listr": "^0.14.3", "ts-morph": "^13.0.2", - "tslib": "^2.1.0", - "yaml": "^1.10.0" + "tslib": "^2.1.0" }, "bin": { "kuzdoc": "bin/run" @@ -6594,14 +6593,6 @@ "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" }, - "node_modules/yaml": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/yaml/-/yaml-1.10.0.tgz", - "integrity": "sha512-yr2icI4glYaNG+KWONODapy2/jDdMSDnrONSjblABjD9B4Z5LgiircSt8m8sRZFNi08kG9Sm0uSHtEmP3zaEGg==", - "engines": { - "node": ">= 6" - } - }, "node_modules/yn": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", @@ -11611,11 +11602,6 @@ "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" }, - "yaml": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/yaml/-/yaml-1.10.0.tgz", - "integrity": "sha512-yr2icI4glYaNG+KWONODapy2/jDdMSDnrONSjblABjD9B4Z5LgiircSt8m8sRZFNi08kG9Sm0uSHtEmP3zaEGg==" - }, "yn": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", diff --git a/package.json b/package.json index 3168654..d73f01d 100644 --- a/package.json +++ b/package.json @@ -21,8 +21,7 @@ "inquirer": "^7.3.3", "listr": "^0.14.3", "ts-morph": "^13.0.2", - "tslib": "^2.1.0", - "yaml": "^1.10.0" + "tslib": "^2.1.0" }, "devDependencies": { "@oclif/dev-cli": "^1.26.0", @@ -68,4 +67,4 @@ "version": "oclif-dev readme && git add README.md" }, "types": "lib/index.d.ts" -} \ No newline at end of file +} diff --git a/src/commands/add-repo.ts b/src/commands/add-repo.ts index 2680581..5aedcb6 100644 --- a/src/commands/add-repo.ts +++ b/src/commands/add-repo.ts @@ -3,7 +3,7 @@ import { assertIsFrameworkRoot } from '../lib/assertions' import { addNewRepo } from '../lib/repo' export default class AddRepo extends Command { - static description = `Wizard to add a new repo to repositories.yml. + static description = `Wizard to add a new repo to repositories.json. NOTE: This command must be executed from the root of the framework meta-repo.` static flags = { @@ -11,7 +11,7 @@ export default class AddRepo extends Command { } async run() { - this.log('\n 📦 Add new repo to repositories.yml\n') + this.log('\n 📦 Add new repo to repositories.json\n') try { assertIsFrameworkRoot(process.cwd()) @@ -24,6 +24,6 @@ export default class AddRepo extends Command { await addNewRepo(process.cwd()) this.log('\n ✅ All done!') - this.log(' The new repo item has been added to the list in repositories.yml\n') + this.log(' The new repo item has been added to the list in repositories.json\n') } } diff --git a/src/commands/install.ts b/src/commands/install.ts index 556c13d..a346de7 100644 --- a/src/commands/install.ts +++ b/src/commands/install.ts @@ -10,10 +10,10 @@ export default class Install extends BaseCommand { static description = `Installs one or multiple repos in the framework meta-repo. NOTE: This command must be executed from the root of the framework meta-repo. -This command will install one or multiple repos, listed in the repositories.yml file, +This command will install one or multiple repos, listed in the repositories.json file, within the .repos directory of the documentation framework. Repositories will be either cloned from Github or symlink-ed from the local filesystem (--local-path flag). -The repositories.yml file will be fetched from the local instance of the documentation framework. +The repositories.json file will be fetched from the local instance of the documentation framework. Repositories are either specified via the --repo flag, or the ${ENV_REPO}: if no value is specified, kuzdoc will ask it via a prompt. Kuzdoc will not overwrite existing repositories. If a folder with the same name of a selected diff --git a/src/lib/repo.ts b/src/lib/repo.ts index a0445fc..19c121c 100644 --- a/src/lib/repo.ts +++ b/src/lib/repo.ts @@ -1,13 +1,12 @@ import { readdirSync, readFileSync, existsSync, writeFileSync } from 'fs' import path, { join } from 'path' import execa from 'execa' -import YAML from 'yaml' import inquirer from 'inquirer' import { docPathInRepo, reposPathInFw, VALUE_ALL_REPOS } from './constants' /** * Specifies what to expect from an element of the array - * contained in the repositories.yml file. + * contained in the repositories.json file. */ export interface RawRepo { url?: string @@ -22,7 +21,7 @@ export interface RawRepo { } /** - * Represents a Repository, parsed from the repositories.yml file. + * Represents a Repository, parsed from the repositories.json file. */ export class Repo { /** @@ -196,8 +195,8 @@ export class Repo { } } -const parseYMLRepos = (YMLRepos: Array): Repo[] => { - return YMLRepos.map(r => new Repo(r)) +const parseRepos = (repos: Array): Repo[] => { + return repos.map(r => new Repo(r)) } /** @@ -220,16 +219,16 @@ export const resolveStage = async (cwd: string) => { } /** - * Fetch the list of Repos from the `repositories.yml` file + * Fetch the list of Repos from the `repositories.json` file * located in the framework meta-repo. * * @param fwPath The path of the framework meta-repo * @returns The list of Repos */ export const fetchRepoList = (fwPath = process.cwd()): Repo[] => { - const fileContent = readFileSync(join(fwPath, reposPathInFw, 'repositories.yml')) - const YMLRepos = YAML.parse(fileContent.toString()) - return parseYMLRepos(YMLRepos) + const fileContent = readFileSync(join(fwPath, reposPathInFw, 'repositories.json')) + const repos = JSON.parse(fileContent.toString()) + return parseRepos(repos) } /** @@ -321,11 +320,11 @@ export async function addNewRepo(fwPath = process.cwd()) { name: 'dev' }]) - const repositoriesFilePath = join(fwPath, reposPathInFw, 'repositories.yml') + const repositoriesFilePath = join(fwPath, reposPathInFw, 'repositories.json') - const fileContent = readFileSync(repositoriesFilePath) - const YMLRepos: RawRepo[] = YAML.parse(fileContent.toString()) - YMLRepos.push({ + const fileContent = readFileSync(repositoriesFilePath, 'utf8'); + const repos = JSON.parse(fileContent); + repos.push({ repo_name: answers.repoName, doc_version: answers.version, stable: answers.stable, @@ -334,5 +333,5 @@ export async function addNewRepo(fwPath = process.cwd()) { name: answers.repoName, private: answers.private }) - writeFileSync(repositoriesFilePath, YAML.stringify(YMLRepos)) + writeFileSync(repositoriesFilePath, JSON.stringify(repos, null, 2)) }