mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-26 06:27:59 +02:00
chore(v2): rm flowtype (#1444)
This commit is contained in:
parent
c2ebde997a
commit
56cd3a22ce
18 changed files with 66 additions and 7213 deletions
|
@ -5,8 +5,6 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/* @flow */
|
||||
|
||||
const path = require('path');
|
||||
const fm = require('front-matter');
|
||||
const {createHash} = require('crypto');
|
||||
|
@ -16,11 +14,13 @@ const escapeStringRegexp = require('escape-string-regexp');
|
|||
const fs = require('fs-extra');
|
||||
|
||||
const fileHash = new Map();
|
||||
async function generate(
|
||||
generatedFilesDir: string,
|
||||
file: string,
|
||||
content: any,
|
||||
): Promise<void> {
|
||||
/**
|
||||
* @param {string} generatedFilesDir
|
||||
* @param {string} file
|
||||
* @param {*} content
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async function generate(generatedFilesDir, file, content) {
|
||||
const filepath = path.join(generatedFilesDir, file);
|
||||
const lastHash = fileHash.get(filepath);
|
||||
const currentHash = createHash('md5')
|
||||
|
@ -37,14 +37,22 @@ async function generate(
|
|||
const indexRE = /(^|.*\/)index\.(md|js)$/i;
|
||||
const extRE = /\.(md|js)$/;
|
||||
|
||||
function fileToPath(file: string): string {
|
||||
/**
|
||||
* @param {string} file
|
||||
* @returns {string}
|
||||
*/
|
||||
function fileToPath(file) {
|
||||
if (indexRE.test(file)) {
|
||||
return file.replace(indexRE, '/$1');
|
||||
}
|
||||
return `/${file.replace(extRE, '').replace(/\\/g, '/')}`;
|
||||
}
|
||||
|
||||
function encodePath(userpath: string): string {
|
||||
/**
|
||||
* @param {string} userpath
|
||||
* @returns {string}
|
||||
*/
|
||||
function encodePath(userpath) {
|
||||
return userpath
|
||||
.split('/')
|
||||
.map(item => encodeURIComponent(item))
|
||||
|
@ -56,7 +64,7 @@ function encodePath(userpath: string): string {
|
|||
* @param {string} str input string
|
||||
* @returns {string}
|
||||
*/
|
||||
function docuHash(str: string): string {
|
||||
function docuHash(str) {
|
||||
if (str === '/') {
|
||||
return 'index';
|
||||
}
|
||||
|
@ -72,7 +80,7 @@ function docuHash(str: string): string {
|
|||
* @param {string} pagePath
|
||||
* @returns {string} unique react component name
|
||||
*/
|
||||
function genComponentName(pagePath: string): string {
|
||||
function genComponentName(pagePath) {
|
||||
if (pagePath === '/') {
|
||||
return 'index';
|
||||
}
|
||||
|
@ -89,7 +97,7 @@ function genComponentName(pagePath: string): string {
|
|||
* @param {string} str windows backslash paths
|
||||
* @returns {string} posix-style path
|
||||
*/
|
||||
function posixPath(str: string): string {
|
||||
function posixPath(str) {
|
||||
const isExtendedLengthPath = /^\\\\\?\\/.test(str);
|
||||
const hasNonAscii = /[^\u0000-\u0080]+/.test(str); // eslint-disable-line
|
||||
|
||||
|
@ -100,11 +108,14 @@ function posixPath(str: string): string {
|
|||
}
|
||||
|
||||
const chunkNameCache = new Map();
|
||||
function genChunkName(
|
||||
modulePath: string,
|
||||
prefix?: string,
|
||||
preferredName?: string,
|
||||
): string {
|
||||
/**
|
||||
* Generate unique chunk name given a module path
|
||||
* @param {string} modulePath
|
||||
* @param {string=} prefix
|
||||
* @param {string=} preferredName
|
||||
* @returns {string}
|
||||
*/
|
||||
function genChunkName(modulePath, prefix, preferredName) {
|
||||
let chunkName = chunkNameCache.get(modulePath);
|
||||
if (!chunkName) {
|
||||
let str = modulePath;
|
||||
|
@ -121,8 +132,12 @@ function genChunkName(
|
|||
}
|
||||
return chunkName;
|
||||
}
|
||||
|
||||
function idx(target?: {}, keyPaths: string | string[]): any {
|
||||
/**
|
||||
* @param {*} target
|
||||
* @param {string|string[]} keyPaths
|
||||
* @returns {*}
|
||||
*/
|
||||
function idx(target, keyPaths) {
|
||||
return (
|
||||
target &&
|
||||
(Array.isArray(keyPaths)
|
||||
|
@ -131,7 +146,12 @@ function idx(target?: {}, keyPaths: string | string[]): any {
|
|||
);
|
||||
}
|
||||
|
||||
function getSubFolder(file: string, refDir: string): ?string {
|
||||
/**
|
||||
* @param {string} file
|
||||
* @param {string} refDir
|
||||
* @returns {string}
|
||||
*/
|
||||
function getSubFolder(file, refDir) {
|
||||
const separator = escapeStringRegexp(path.sep);
|
||||
const baseDir = escapeStringRegexp(path.basename(refDir));
|
||||
const regexSubFolder = new RegExp(
|
||||
|
@ -141,7 +161,11 @@ function getSubFolder(file: string, refDir: string): ?string {
|
|||
return match && match[1];
|
||||
}
|
||||
|
||||
function parse(fileString: string): {} {
|
||||
/**
|
||||
* @param {string} fileString
|
||||
* @returns {*}
|
||||
*/
|
||||
function parse(fileString) {
|
||||
if (!fm.test(fileString)) {
|
||||
return {metadata: null, content: fileString};
|
||||
}
|
||||
|
@ -150,7 +174,11 @@ function parse(fileString: string): {} {
|
|||
return {metadata, content};
|
||||
}
|
||||
|
||||
function normalizeUrl(rawUrls: string[]): string {
|
||||
/**
|
||||
* @param {string[]} rawUrls
|
||||
* @returns {string}
|
||||
*/
|
||||
function normalizeUrl(rawUrls) {
|
||||
const urls = rawUrls;
|
||||
const resultArray = [];
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue