-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from mbc-net/docs/how-to-usage
Browser auto reloads in local development mode
- Loading branch information
Showing
5 changed files
with
277 additions
and
3 deletions.
There are no files selected for viewing
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,65 @@ | ||
import concurrently from "concurrently"; | ||
import config from "../docusaurus.config"; | ||
import { execSync } from "child_process"; | ||
import * as path from "path"; | ||
import * as fs from "fs"; | ||
|
||
const fallbackLanguage = "en"; | ||
const rootDir = path.resolve(__dirname, ".."); | ||
|
||
const runCommand = function (cmd: string) { | ||
console.log(cmd); | ||
const ret = execSync(cmd, { cwd: rootDir }); | ||
console.log(ret.toString()); | ||
}; | ||
|
||
// Get the language from the command-line arguments | ||
const args = process.argv.slice(2); | ||
let language = args[0]; | ||
|
||
if (!language) { | ||
language = fallbackLanguage; | ||
} | ||
|
||
if (config.i18n.locales.find((lng) => lng === language) === undefined) { | ||
console.error("Please correct the support language"); | ||
process.exit(1); | ||
} | ||
|
||
const outputDir = path.join( | ||
__dirname, | ||
`../i18n/${language}/docusaurus-plugin-content-docs/current` | ||
); | ||
|
||
if (!fs.existsSync(outputDir)) { | ||
// We need to replace placeholder into i18n folder before serve content. | ||
runCommand(`npm run translate:extract-placeholder`); | ||
runCommand("npm run translate:replace-placeholders"); | ||
} | ||
|
||
const { result } = concurrently( | ||
[ | ||
{ command: "nodemon", name: "watch", prefixColor: "green" }, | ||
{ | ||
command: `docusaurus start --locale ${language}`, | ||
name: "serve", | ||
prefixColor: "blue", | ||
}, | ||
], | ||
{ | ||
prefix: "name", | ||
killOthers: ["failure", "success"], | ||
restartTries: 3, | ||
cwd: rootDir, | ||
} | ||
); | ||
|
||
result.then( | ||
function onSuccess() { | ||
process.exit(); | ||
}, | ||
function onFailure(msg) { | ||
console.error("abc", msg); | ||
process.exit(); | ||
} | ||
); |