mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
Support MERMAID_RELEASE_VERSION in docs
This commit is contained in:
parent
194ef202ac
commit
88856a721f
@ -223,6 +223,9 @@ If the users have no way to know that things have changed, then you haven't real
|
|||||||
Likewise, if users don't know that there is a new feature that you've implemented, it will forever remain unknown and unused.
|
Likewise, if users don't know that there is a new feature that you've implemented, it will forever remain unknown and unused.
|
||||||
|
|
||||||
The documentation has to be updated to users know that things have changed and added!
|
The documentation has to be updated to users know that things have changed and added!
|
||||||
|
If you are adding a new feature, add `(v<MERMAID_RELEASE_VERSION>+)` in the title or description. It will be replaced automatically with the current version number when the release happens.
|
||||||
|
|
||||||
|
eg: `# Feature Name (v<MERMAID_RELEASE_VERSION>+)`
|
||||||
|
|
||||||
We know it can sometimes be hard to code _and_ write user documentation.
|
We know it can sometimes be hard to code _and_ write user documentation.
|
||||||
|
|
||||||
|
@ -25,14 +25,15 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"docs:code": "typedoc src/defaultConfig.ts src/config.ts src/mermaidAPI.ts && prettier --write ./src/docs/config/setup",
|
"docs:code": "typedoc src/defaultConfig.ts src/config.ts src/mermaidAPI.ts && prettier --write ./src/docs/config/setup",
|
||||||
"docs:build": "rimraf ../../docs && pnpm docs:spellcheck && pnpm docs:code && ts-node-esm src/docs.mts",
|
"docs:build": "rimraf ../../docs && pnpm docs:spellcheck && pnpm docs:code && ts-node-esm src/docs.cli.mts",
|
||||||
"docs:verify": "pnpm docs:spellcheck && pnpm docs:code && ts-node-esm src/docs.mts --verify",
|
"docs:verify": "pnpm docs:spellcheck && pnpm docs:code && ts-node-esm src/docs.cli.mts --verify",
|
||||||
"docs:pre:vitepress": "pnpm --filter ./src/docs prefetch && rimraf src/vitepress && pnpm docs:code && ts-node-esm src/docs.mts --vitepress && pnpm --filter ./src/vitepress install --no-frozen-lockfile --ignore-scripts",
|
"docs:pre:vitepress": "pnpm --filter ./src/docs prefetch && rimraf src/vitepress && pnpm docs:code && ts-node-esm src/docs.cli.mts --vitepress && pnpm --filter ./src/vitepress install --no-frozen-lockfile --ignore-scripts",
|
||||||
"docs:build:vitepress": "pnpm docs:pre:vitepress && (cd src/vitepress && pnpm run build) && cpy --flat src/docs/landing/ ./src/vitepress/.vitepress/dist/landing",
|
"docs:build:vitepress": "pnpm docs:pre:vitepress && (cd src/vitepress && pnpm run build) && cpy --flat src/docs/landing/ ./src/vitepress/.vitepress/dist/landing",
|
||||||
"docs:dev": "pnpm docs:pre:vitepress && concurrently \"pnpm --filter ./src/vitepress dev\" \"ts-node-esm src/docs.mts --watch --vitepress\"",
|
"docs:dev": "pnpm docs:pre:vitepress && concurrently \"pnpm --filter ./src/vitepress dev\" \"ts-node-esm src/docs.cli.mts --watch --vitepress\"",
|
||||||
"docs:dev:docker": "pnpm docs:pre:vitepress && concurrently \"pnpm --filter ./src/vitepress dev:docker\" \"ts-node-esm src/docs.mts --watch --vitepress\"",
|
"docs:dev:docker": "pnpm docs:pre:vitepress && concurrently \"pnpm --filter ./src/vitepress dev:docker\" \"ts-node-esm src/docs.cli.mts --watch --vitepress\"",
|
||||||
"docs:serve": "pnpm docs:build:vitepress && vitepress serve src/vitepress",
|
"docs:serve": "pnpm docs:build:vitepress && vitepress serve src/vitepress",
|
||||||
"docs:spellcheck": "cspell --config ../../cSpell.json \"src/docs/**/*.md\"",
|
"docs:spellcheck": "cspell --config ../../cSpell.json \"src/docs/**/*.md\"",
|
||||||
|
"docs:release-version": "ts-node-esm scripts/update-release-version.mts",
|
||||||
"types:build-config": "ts-node-esm --transpileOnly scripts/create-types-from-json-schema.mts",
|
"types:build-config": "ts-node-esm --transpileOnly scripts/create-types-from-json-schema.mts",
|
||||||
"types:verify-config": "ts-node-esm scripts/create-types-from-json-schema.mts --verify",
|
"types:verify-config": "ts-node-esm scripts/create-types-from-json-schema.mts --verify",
|
||||||
"release": "pnpm build",
|
"release": "pnpm build",
|
||||||
|
34
packages/mermaid/scripts/update-release-version.mts
Normal file
34
packages/mermaid/scripts/update-release-version.mts
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/* eslint-disable no-console */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file Update the MERMAID_RELEASE_VERSION placeholder in the documentation source files with the current version of mermaid.
|
||||||
|
* So contributors adding new features will only have to add the placeholder and not worry about updating the version number.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
import { posix } from 'path';
|
||||||
|
import {
|
||||||
|
getGlobs,
|
||||||
|
getFilesFromGlobs,
|
||||||
|
SOURCE_DOCS_DIR,
|
||||||
|
readSyncedUTF8file,
|
||||||
|
MERMAID_RELEASE_VERSION,
|
||||||
|
} from '../src/docs.mjs';
|
||||||
|
import { writeFile } from 'fs/promises';
|
||||||
|
|
||||||
|
const main = async () => {
|
||||||
|
const sourceDirGlob = posix.join('.', SOURCE_DOCS_DIR, '**');
|
||||||
|
const mdFileGlobs = getGlobs([posix.join(sourceDirGlob, '*.md')]);
|
||||||
|
mdFileGlobs.push('!**/community/development.md');
|
||||||
|
const mdFiles = await getFilesFromGlobs(mdFileGlobs);
|
||||||
|
mdFiles.sort();
|
||||||
|
for (const mdFile of mdFiles) {
|
||||||
|
const content = readSyncedUTF8file(mdFile);
|
||||||
|
const updatedContent = content.replace(/<MERMAID_RELEASE_VERSION>/g, MERMAID_RELEASE_VERSION);
|
||||||
|
if (content !== updatedContent) {
|
||||||
|
await writeFile(mdFile, updatedContent);
|
||||||
|
console.log(`Updated MERMAID_RELEASE_VERSION in ${mdFile}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void main();
|
3
packages/mermaid/src/docs.cli.mts
Normal file
3
packages/mermaid/src/docs.cli.mts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import { processDocs } from './docs.mjs';
|
||||||
|
|
||||||
|
void processDocs();
|
@ -27,8 +27,6 @@
|
|||||||
* get their absolute paths. Ensures that the location of those 2 directories is not dependent on
|
* get their absolute paths. Ensures that the location of those 2 directories is not dependent on
|
||||||
* where this file resides.
|
* where this file resides.
|
||||||
*
|
*
|
||||||
* @todo Write a test file for this. (Will need to be able to deal .mts file. Jest has trouble with
|
|
||||||
* it.)
|
|
||||||
*/
|
*/
|
||||||
import { readFileSync, writeFileSync, mkdirSync, existsSync, rmSync, rmdirSync } from 'fs';
|
import { readFileSync, writeFileSync, mkdirSync, existsSync, rmSync, rmdirSync } from 'fs';
|
||||||
import { exec } from 'child_process';
|
import { exec } from 'child_process';
|
||||||
@ -46,9 +44,9 @@ import mm from 'micromatch';
|
|||||||
import flatmap from 'unist-util-flatmap';
|
import flatmap from 'unist-util-flatmap';
|
||||||
import { visit } from 'unist-util-visit';
|
import { visit } from 'unist-util-visit';
|
||||||
|
|
||||||
const MERMAID_MAJOR_VERSION = (
|
export const MERMAID_RELEASE_VERSION = JSON.parse(readFileSync('../mermaid/package.json', 'utf8'))
|
||||||
JSON.parse(readFileSync('../mermaid/package.json', 'utf8')).version as string
|
.version as string;
|
||||||
).split('.')[0];
|
const MERMAID_MAJOR_VERSION = MERMAID_RELEASE_VERSION.split('.')[0];
|
||||||
const CDN_URL = 'https://cdn.jsdelivr.net/npm'; // 'https://unpkg.com';
|
const CDN_URL = 'https://cdn.jsdelivr.net/npm'; // 'https://unpkg.com';
|
||||||
|
|
||||||
const MERMAID_KEYWORD = 'mermaid';
|
const MERMAID_KEYWORD = 'mermaid';
|
||||||
@ -71,7 +69,7 @@ const vitepress: boolean = process.argv.includes('--vitepress');
|
|||||||
const noHeader: boolean = process.argv.includes('--noHeader') || vitepress;
|
const noHeader: boolean = process.argv.includes('--noHeader') || vitepress;
|
||||||
|
|
||||||
// These paths are from the root of the mono-repo, not from the mermaid subdirectory
|
// These paths are from the root of the mono-repo, not from the mermaid subdirectory
|
||||||
const SOURCE_DOCS_DIR = 'src/docs';
|
export const SOURCE_DOCS_DIR = 'src/docs';
|
||||||
const FINAL_DOCS_DIR = vitepress ? 'src/vitepress' : '../../docs';
|
const FINAL_DOCS_DIR = vitepress ? 'src/vitepress' : '../../docs';
|
||||||
|
|
||||||
const LOGMSG_TRANSFORMED = 'transformed';
|
const LOGMSG_TRANSFORMED = 'transformed';
|
||||||
@ -158,7 +156,7 @@ const copyTransformedContents = (filename: string, doCopy = false, transformedCo
|
|||||||
logWasOrShouldBeTransformed(fileInFinalDocDir, doCopy);
|
logWasOrShouldBeTransformed(fileInFinalDocDir, doCopy);
|
||||||
};
|
};
|
||||||
|
|
||||||
const readSyncedUTF8file = (filename: string): string => {
|
export const readSyncedUTF8file = (filename: string): string => {
|
||||||
return readFileSync(filename, 'utf8');
|
return readFileSync(filename, 'utf8');
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -336,7 +334,7 @@ import { default as jsonSchemaReadmeBuilder } from '@adobe/jsonschema2md/lib/rea
|
|||||||
/**
|
/**
|
||||||
* Transforms the given JSON Schema into Markdown documentation
|
* Transforms the given JSON Schema into Markdown documentation
|
||||||
*/
|
*/
|
||||||
async function transormJsonSchema(file: string) {
|
async function transformJsonSchema(file: string) {
|
||||||
const yamlContents = readSyncedUTF8file(file);
|
const yamlContents = readSyncedUTF8file(file);
|
||||||
const jsonSchema = load(yamlContents, {
|
const jsonSchema = load(yamlContents, {
|
||||||
filename: file,
|
filename: file,
|
||||||
@ -480,7 +478,7 @@ const transformHtml = (filename: string) => {
|
|||||||
copyTransformedContents(filename, !verifyOnly, formattedHTML);
|
copyTransformedContents(filename, !verifyOnly, formattedHTML);
|
||||||
};
|
};
|
||||||
|
|
||||||
const getGlobs = (globs: string[]): string[] => {
|
export const getGlobs = (globs: string[]): string[] => {
|
||||||
globs.push('!**/dist/**', '!**/redirect.spec.ts', '!**/landing/**', '!**/node_modules/**');
|
globs.push('!**/dist/**', '!**/redirect.spec.ts', '!**/landing/**', '!**/node_modules/**');
|
||||||
if (!vitepress) {
|
if (!vitepress) {
|
||||||
globs.push(
|
globs.push(
|
||||||
@ -494,12 +492,12 @@ const getGlobs = (globs: string[]): string[] => {
|
|||||||
return globs;
|
return globs;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getFilesFromGlobs = async (globs: string[]): Promise<string[]> => {
|
export const getFilesFromGlobs = async (globs: string[]): Promise<string[]> => {
|
||||||
return await globby(globs, { dot: true });
|
return await globby(globs, { dot: true });
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Main method (entry point) */
|
/** Main method (entry point) */
|
||||||
const main = async () => {
|
export const processDocs = async () => {
|
||||||
if (verifyOnly) {
|
if (verifyOnly) {
|
||||||
console.log('Verifying that all files are in sync with the source files');
|
console.log('Verifying that all files are in sync with the source files');
|
||||||
}
|
}
|
||||||
@ -509,7 +507,7 @@ const main = async () => {
|
|||||||
|
|
||||||
if (vitepress) {
|
if (vitepress) {
|
||||||
console.log(`${action} 1 .schema.yaml file`);
|
console.log(`${action} 1 .schema.yaml file`);
|
||||||
await transormJsonSchema('src/schemas/config.schema.yaml');
|
await transformJsonSchema('src/schemas/config.schema.yaml');
|
||||||
} else {
|
} else {
|
||||||
// skip because this creates so many Markdown files that it lags git
|
// skip because this creates so many Markdown files that it lags git
|
||||||
console.log('Skipping 1 .schema.yaml file');
|
console.log('Skipping 1 .schema.yaml file');
|
||||||
@ -577,5 +575,3 @@ const main = async () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void main();
|
|
||||||
|
@ -212,6 +212,9 @@ If the users have no way to know that things have changed, then you haven't real
|
|||||||
Likewise, if users don't know that there is a new feature that you've implemented, it will forever remain unknown and unused.
|
Likewise, if users don't know that there is a new feature that you've implemented, it will forever remain unknown and unused.
|
||||||
|
|
||||||
The documentation has to be updated to users know that things have changed and added!
|
The documentation has to be updated to users know that things have changed and added!
|
||||||
|
If you are adding a new feature, add `(v<MERMAID_RELEASE_VERSION>+)` in the title or description. It will be replaced automatically with the current version number when the release happens.
|
||||||
|
|
||||||
|
eg: `# Feature Name (v<MERMAID_RELEASE_VERSION>+)`
|
||||||
|
|
||||||
We know it can sometimes be hard to code _and_ write user documentation.
|
We know it can sometimes be hard to code _and_ write user documentation.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user