Skip to content

Commit

Permalink
use repositories.json (#13)
Browse files Browse the repository at this point in the history
Co-authored-by: Aschen <[email protected]>
  • Loading branch information
Aschen and Aschen committed Mar 23, 2023
1 parent 9c99590 commit 31d46c8
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 52 deletions.
35 changes: 20 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

<!-- toc -->
* [kuzdoc](#kuzdoc)
* [Usage](#usage)
* [Commands](#commands)

- [kuzdoc](#kuzdoc)
- [Usage](#usage)
- [Commands](#commands)
<!-- tocstop -->

# Usage

<!-- usage -->

```sh-session
$ npm install -g kuzdoc
$ kuzdoc COMMAND
Expand All @@ -29,24 +31,26 @@ USAGE
$ kuzdoc COMMAND
...
```

<!-- usagestop -->

# Commands

<!-- 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)_

<!-- commandsstop -->
16 changes: 1 addition & 15 deletions package-lock.json

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

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -68,4 +67,4 @@
"version": "oclif-dev readme && git add README.md"
},
"types": "lib/index.d.ts"
}
}
6 changes: 3 additions & 3 deletions src/commands/add-repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ 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 = {
help: flags.help({ char: 'h' }),
}

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())
Expand All @@ -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')
}
}
4 changes: 2 additions & 2 deletions src/commands/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 13 additions & 14 deletions src/lib/repo.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 {
/**
Expand Down Expand Up @@ -196,8 +195,8 @@ export class Repo {
}
}

const parseYMLRepos = (YMLRepos: Array<any>): Repo[] => {
return YMLRepos.map(r => new Repo(r))
const parseRepos = (repos: Array<any>): Repo[] => {
return repos.map(r => new Repo(r))
}

/**
Expand All @@ -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)
}

/**
Expand Down Expand Up @@ -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,
Expand All @@ -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))
}

0 comments on commit 31d46c8

Please sign in to comment.