Skip to content

Commit

Permalink
Merge pull request #7 from citkane/dev
Browse files Browse the repository at this point in the history
New version 0.1.0
  • Loading branch information
citkane committed Aug 24, 2022
2 parents e04bffe + 66abff2 commit ac128d4
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 108 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text eol=lf
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ on:
workflow_dispatch:
workflow_call:
pull_request:
types: [opened, reopened, edited]
branches:
- 'dev'
push:
Expand Down
40 changes: 19 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@

# ↹ typedoc-plugin-versions

| | |
| ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <img src="./media/Screenshot.jpg" width="500px" height="auto" border="1px solid light-grey" /> | **It keeps track of your document builds and provides a select menu for versions.**<br /><br />Built for: <a href = "https://semver.org/" target="_blank">semantic versioning</a>. |

<img src="./media/Screenshot.jpg" width="300px" height="auto" border="1px solid light-grey" /><br><br>
**It keeps track of your document builds and provides a select menu for versions.**
<br /><br />
Built for: <a href = "https://semver.org/" target="_blank">semantic versioning</a>.

### Usage
<br /><br />

---
## Usage

Install:

Expand All @@ -32,22 +31,17 @@ and then set up your environment in typedoc.json

<br /><br />

### Options

---
## Options

| Key | Value Information | Type | Required | Default |
| :---------------- | ------------------------------------------------------------------------------------------------------------------------- | -------- | :------: | --------------------------------------------------------------------------------------------- |
| **_stable_** | The minor version that you would like to be marked as `stable` | `string` | **no** | The latest minor version of the version being built |
| **_dev_** | The version that you would like to be marked as `dev` | `string` | **no** | The latest patch version of the version being built |
| **_homeUrl_** | The url to the base folder where you will host your documentation set | `string` | **no** | will try to determine the GitHUB package url from package.json and convert it to gh-page url. |
| **_domLocation_** | A custom DOM location to render the HTML `select` dropdown corresponding to typedoc rendererHooks, eg. "navigation.begin" | `string` | **no** | Injects to left of header using vanilla js - not a typedoc render hook. |
| Key | Value Information | Type | Required | Default |
| :---------------- | ------------------------------------------------------------------------------------------------------------------------- | -------- | :------: | ----------------------------------------------------------------------- |
| **_stable_** | The minor version that you would like to be marked as `stable` | `string` | **no** | The latest minor version of the version being built |
| **_dev_** | The version that you would like to be marked as `dev` | `string` | **no** | The latest patch version of the version being built |
| **_domLocation_** | A custom DOM location to render the HTML `select` dropdown corresponding to typedoc rendererHooks, eg. "navigation.begin" | `string` | **no** | Injects to left of header using vanilla js - not a typedoc render hook. |

<br /><br />

### "What sorcery is this?", you may ask...

---
## "What sorcery is this?", you may ask...

Typedoc-plugin-versions takes the architectural approach of [JuliaLang Documenter](https://juliadocs.github.io/Documenter.jl/stable/).

Expand All @@ -60,9 +54,7 @@ If you want to remove a historic version, delete the old folder and rebuild your

<br /><br />

### CID

---
## CID

Below is an opinionated Github CI setup. You can hack and change it to suite your needs.

Expand All @@ -79,3 +71,9 @@ Below is an opinionated Github CI setup. You can hack and change it to suite you
- Create a [custom workflow](https://docs.github.com/en/actions/quickstart) as per [this template](https://github.com/citkane/typedoc-plugin-versions/blob/main/.github/workflows/docs.yml) for PUBLISH DOCS.

The "PUBLISH DOCS" action will create a rolling update to your document set.

<br /><br />

## Development Guidelines and howto's

Please refer to the [Wiki Page](https://github.com/citkane/typedoc-plugin-versions/wiki/Development-Guidelines).
12 changes: 12 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// eslint-disable-next-line no-undef
const fs = require('fs-extra');

fs.copyFileSync('./README.md', './dist/README.md');
fs.copyFileSync('./LICENSE.txt', './dist/LICENSE.txt');
fs.copyFileSync('./.npmignore', './dist/.npmignore');
fs.copyFileSync('./package.json', './dist/package.json');
fs.ensureDirSync('./dist/src/assets/');
fs.copyFileSync(
'./src/assets/versionsMenu.js',
'./dist/src/assets/versionsMenu.js'
);
9 changes: 0 additions & 9 deletions build.sh

This file was deleted.

4 changes: 2 additions & 2 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "typedoc-plugin-versions",
"version": "0.0.5",
"version": "0.1.0",
"description": "It keeps track of your document builds and provides a select menu for versions",
"main": "src/index",
"scripts": {
"test": "prettier -c . && nyc mocha",
"build": "./build.sh",
"build": "npx tsc && node ./build.js",
"docs": "typedoc",
"docs:build": "tsc && typedoc"
},
Expand Down
29 changes: 0 additions & 29 deletions src/etc/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,6 @@ import { Application, Logger, TypeDocReader } from 'typedoc';
const packagePath = path.join(process.cwd(), 'package.json');
const pack = fs.readJSONSync(packagePath);

/**
* Attempts to find the github repository location url and parse it into a github pages url.
* @param repository
* @returns The github pages url or a dummy url
*/
export function getGhPageUrl(repository: { url } = pack.repository) {
if (!repository || !repository.url) {
return 'http://localhost:5500/docs';
}
const splitUrl = repository.url.split('/');
const gitName = splitUrl[3];
const repoName = splitUrl[4].split('.')[0];
return `https://${gitName}.github.io/${repoName}`;
}

/**
* Gets the package version defined in package.json
* @param version
Expand Down Expand Up @@ -147,20 +132,6 @@ export const DOC_VERSIONS = [
return js;
}

/**
* Creates a string (of HTML) that re-directs to the 'stable' documentation url.
* @param docRoot The root url of the documentation site
* @returns a string of valid HTML
*/
export function makeIndex(docRoot: string) {
const baseUrl = new URL(docRoot);
const newUrl = new URL(
path.join(baseUrl.pathname, 'stable'),
baseUrl.origin
);
return `<meta http-equiv="refresh" content="0; url=${newUrl.href}"/>`;
}

/**
* Creates a symlink for the stable release
* @param docRoot
Expand Down
7 changes: 4 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export function load(app: Application) {
defaultValue: {
stable: vUtils.getMinorVersion(),
dev: vUtils.getSemanticVersion(),
homeUrl: vUtils.getGhPageUrl(),
domLocation: 'false',
} as versionsOptions,
});
Expand Down Expand Up @@ -65,8 +64,10 @@ export function load(app: Application) {
const jsVersionKeys = vUtils.makeJsKeys(semGroups);
fs.writeFileSync(path.join(rootPath, 'versions.js'), jsVersionKeys);

const htmlIndex = vUtils.makeIndex(vOptions.homeUrl);
fs.writeFileSync(path.join(rootPath, 'index.html'), htmlIndex);
fs.writeFileSync(
path.join(rootPath, 'index.html'),
'<meta http-equiv="refresh" content="0; url=stable"/>'
);
});

return vOptions;
Expand Down
5 changes: 0 additions & 5 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ export interface versionsOptions {
* Defaults to the latest patch version of the version being built
*/
dev?: patchVersion;
/**
* The url to the base folder where you will host your documentation set
* Default: will try to determine the GitHUB package url from package.json and convert it to gh-page url.
*/
homeUrl?: string;
/**
* A custom DOM location to render the HTML `select` dropdown corresponding to [typedoc render hooks](https://typedoc.org/api/interfaces/RendererHooks.html)
* Default: Injects to left of header using vanilla js - not a typedoc render hook.
Expand Down
35 changes: 6 additions & 29 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import * as vUtils from '../src/etc/utils';
import { minorVerRegex, verRegex } from '../src/etc/utils';
import {
docsPath,
htmlRedirect,
jsKeys,
stubOptionKeys,
stubPathKeys,
Expand All @@ -26,24 +25,6 @@ describe('Unit testing for typedoc-plugin-versions', function () {
);
});

describe('parsing for documentation root url', function () {
it('parses git url to gh-page url', function () {
assert.equal(
vUtils.getGhPageUrl({
url: 'git+https://github.com/username/repository.git',
}),
'https://username.github.io/repository',
'did not parse gh-pages url correctly'
);
});
it('provides a default document url if none given', function () {
assert.equal(
vUtils.getGhPageUrl({ url: null }),
'http://localhost:5500/docs',
'did not provide a default document url'
);
});
});
describe('retrieving package version', function () {
it('retrieves patch value from package.json', function () {
assert.match(
Expand Down Expand Up @@ -104,14 +85,6 @@ describe('Unit testing for typedoc-plugin-versions', function () {
'did not create a valid js string'
);
});
it('creates a redirect string for index.html', function () {
const url = vUtils.getGhPageUrl({ url: null });
assert.equal(
vUtils.makeIndex(url),
htmlRedirect,
'did not create a valid htm redirect string'
);
});
});
describe('creates symlinks', function () {
it('creates a stable version symlink', function () {
Expand All @@ -124,7 +97,9 @@ describe('Unit testing for typedoc-plugin-versions', function () {
'did not create a stable symlink'
);
assert.isTrue(
fs.readlinkSync(link).endsWith('test/stubs/docs/v0.1.1'),
/test[/|\\]stubs[/|\\]docs[/|\\]v0.1.1$/.test(
fs.readlinkSync(link)
),
'did not link the stable symlink correctly'
);
assert.throws(() => {
Expand All @@ -138,7 +113,9 @@ describe('Unit testing for typedoc-plugin-versions', function () {
const link = path.join(docsPath, 'dev');
assert.isTrue(fs.existsSync(link), 'did not create a dev symlink');
assert.isTrue(
fs.readlinkSync(link).endsWith('test/stubs/docs/v0.1.0'),
/test[/|\\]stubs[/|\\]docs[/|\\]v0.1.0/.test(
fs.readlinkSync(link)
),
'did not link the dev symlink correctly'
);
assert.throws(() => {
Expand Down
10 changes: 4 additions & 6 deletions test/stubs/stubs.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import path from 'path';
import { getSemanticVersion as getSemanticVersion } from '../../src/etc/utils';
import { getSemanticVersion } from '../../src/etc/utils';

export const stubsPath = __dirname;
export const docsPath = path.join(stubsPath, 'docs');
export const stubVersions = ['v0.0.0', 'v0.1.0', 'v0.1.1'];
export const stubSemanticLinks = ['v0.0', 'v0.1'];
export const stubOptionKeys = ['stable', 'dev', 'homeUrl', 'domLocation'];
export const stubOptionKeys = ['stable', 'dev', 'domLocation'];
export const stubPathKeys = ['rootPath', 'targetPath'];
export const stubRootPath = '/test/stubs/docs';
export const stubRootPath =
process.platform === 'win32' ? '\\test\\stubs\\docs' : '/test/stubs/docs';
export const stubTargetPath = (version) =>
path.join(stubRootPath, getSemanticVersion(version));

Expand All @@ -21,6 +22,3 @@ export const DOC_VERSIONS = [
'dev'
];
`;

export const htmlRedirect =
'<meta http-equiv="refresh" content="0; url=http://localhost:5500/docs/stable"/>';
2 changes: 1 addition & 1 deletion typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"plugin": ["./dist"],
"includeVersion": true,
"versions": {
"stable": "0.0"
"stable": "0.1"
}
}

0 comments on commit ac128d4

Please sign in to comment.