-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c3b6905
commit c963ad9
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const fragmentPlugin = require('../../plugins/remark-plugins/fragments'); | ||
const variablePlugin = require('../../plugins/remark-plugins/variables'); | ||
const variables = require('../..//variables'); | ||
const docutils = require('../flaturl/doc'); | ||
|
||
const myArgs = process.argv.slice(2); | ||
let baseurl = './.flatdocs' | ||
if (myArgs.length >= 1) { | ||
baseurl = myArgs[0] | ||
} | ||
|
||
const mdxLoader = require('@docusaurus/mdx-loader').default; | ||
const { | ||
reportMessage, | ||
} = require('@docusaurus/utils') | ||
|
||
const loadContext = (errors) => { | ||
return { | ||
async: () => { | ||
return () => {} | ||
}, | ||
getOptions: () => ({ | ||
remarkPlugins: [ | ||
[variablePlugin, { data: variables, fail: false, onError: (err, line) => {errors.push([err, line])} }], | ||
[fragmentPlugin, { prefix: 'fragments', fail: false, baseUrl: process.cwd() + '/fragments', onError: (err, line) => {errors.push([err, line])} }] | ||
], | ||
}) | ||
} | ||
} | ||
|
||
async function validateFragmentsAndVariables(contentPath) { | ||
const docs = await docutils.getDocMetadata(contentPath); | ||
let haserrors = false | ||
for (const doc of docs) { | ||
const errors = [] | ||
const context = loadContext(errors) | ||
const mdxLoaderWithContext = mdxLoader.bind(context) | ||
await mdxLoaderWithContext(doc.body) | ||
if (errors.length > 0) { | ||
haserrors = true | ||
reportMessage(`- on source page path = ${doc.source}`, 'error') | ||
for (const item of errors) { | ||
reportMessage(` line:${item[1].line} Column:${item[1].column} ${item[0]}`, 'error') | ||
} | ||
} | ||
} | ||
if (haserrors) { | ||
process.exit(1) | ||
} | ||
} | ||
|
||
validateFragmentsAndVariables(baseurl) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const shell = require('shelljs') | ||
const fs = require('fs') | ||
const path = require('path') | ||
const semver = require('semver'); | ||
const _ = require('lodash'); | ||
|
||
const writeFile = (file, data) => { | ||
fs.writeFileSync(file, data) | ||
} | ||
|
||
function keepLastNVersion(n) { | ||
const data = shell.exec('cd $RAGFLOW_MAIN && git tag').stdout.trim() | ||
const tags = _.compact(data.split('\n')) | ||
.filter(semver.valid) | ||
.sort(semver.compare) | ||
.reverse(); | ||
const groups = _.groupBy(tags, function(item){ | ||
return semver.major(item) + '.' + semver.minor(item) | ||
}) | ||
let got = 0; | ||
const res = []; | ||
for (const key in groups) { | ||
res.push(groups[key][0]) | ||
got++ | ||
if (got >= n) break | ||
} | ||
return res | ||
} | ||
|
||
const arr = keepLastNVersion(2) | ||
writeFile('./versions.json', JSON.stringify(arr, null, 2)) |