/
githubmirror
/
docusaurus
Обзор
Документация
Войти
/
githubmirror
/
docusaurus
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/create-docusaurus/src/utils.ts
83 строки
2 KB
Sébastien Lorber
refactor(create-docusaurus): simplify/refactor/split create-docusaurus internal logic (#12050)
21 май 2026, 18:31
Не верифицирован
21 май 2026, 18:31
b43766d
Код
Авторство
О чём код?
/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ import fs from 'node:fs/promises'; import path from 'node:path'; import {logger} from '@docusaurus/logger'; import {type PackageManager} from './constants.js'; /** * We use a simple kebab-case-like conversion * It's not perfect, but good enough * We don't want to depend on lodash in this package * See https://github.com/facebook/docusaurus/pull/11653 * @param siteName */ export function siteNameToPackageName(siteName: string): string { const match = siteName.match( /[A-Z]{2,}(?=[A-Z][a-z]+\d*|\b|_)|[A-Z]?[a-z]+\d*|[A-Z]|\d+/g, ); if (match) { return match.map((x) => x.toLowerCase()).join('-'); } return siteName; } export async function updatePkg( pkgPath: string, obj: {[key: string]: unknown}, ): Promise<void> { const pkg = JSON.parse(await fs.readFile(pkgPath, 'utf8')) as { [key: string]: unknown; }; const newPkg = Object.assign(pkg, obj); await fs.mkdir(path.dirname(pkgPath), {recursive: true}); await fs.writeFile(pkgPath, `${JSON.stringify(newPkg, null, 2)}\n`); } // No need for fs-extra dependency export async function pathExists(filePath: string): Promise<boolean> { return fs .access(filePath, fs.constants.F_OK) .then(() => true) .catch(() => false); } export function printPackageManagerHelp({ pkgManager, cdpath, }: { pkgManager: PackageManager; cdpath: string; }) { const useNpm = pkgManager === 'npm'; const useBun = pkgManager === 'bun'; const run = useNpm || useBun ? 'run ' : ''; logger.success`Created name=${cdpath}.`; logger.info`Inside that directory, you can run several commands: code=${`${pkgManager} start`} Starts the development server. code=${`${pkgManager} ${run}build`} Bundles your website into static files for production. code=${`${pkgManager} ${run}serve`} Serves the built website locally. code=${`${pkgManager} ${run}deploy`} Publishes the website to GitHub pages. We recommend that you begin by typing: code=${`cd ${cdpath}`} code=${`${pkgManager} start`} Happy building awesome websites! `; }