mirror of
https://github.com/facebook/docusaurus.git
synced 2025-04-29 18:27:56 +02:00
refactor: make JS executables included in the tsconfig for editor hints (#6861)
* refactor: make JS executables included in the tsconfig for editor hints * oops
This commit is contained in:
parent
a6e72192fa
commit
44d73f7230
11 changed files with 94 additions and 64 deletions
|
@ -13,8 +13,8 @@
|
|||
},
|
||||
"scripts": {
|
||||
"create-docusaurus": "create-docusaurus",
|
||||
"build": "tsc",
|
||||
"watch": "tsc --watch"
|
||||
"build": "tsc -p tsconfig.build.json",
|
||||
"watch": "tsc -p tsconfig.build.json --watch"
|
||||
},
|
||||
"bin": "bin/index.js",
|
||||
"publishConfig": {
|
||||
|
|
12
packages/create-docusaurus/tsconfig.build.json
Normal file
12
packages/create-docusaurus/tsconfig.build.json
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"module": "es2020",
|
||||
"incremental": true,
|
||||
"tsBuildInfoFile": "./lib/.tsbuildinfo",
|
||||
"rootDir": "src",
|
||||
"outDir": "lib"
|
||||
},
|
||||
"include": ["src/"],
|
||||
"exclude": ["templates/"]
|
||||
}
|
|
@ -1,12 +1,10 @@
|
|||
// For editor typechecking; includes bin
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"extends": "./tsconfig.build.json",
|
||||
"compilerOptions": {
|
||||
"module": "es2020",
|
||||
"incremental": true,
|
||||
"tsBuildInfoFile": "./lib/.tsbuildinfo",
|
||||
"rootDir": "src",
|
||||
"outDir": "lib"
|
||||
"noEmit": true,
|
||||
"allowJs": true,
|
||||
"rootDir": "."
|
||||
},
|
||||
"include": ["src/"],
|
||||
"exclude": ["templates/"]
|
||||
"include": ["src", "bin"]
|
||||
}
|
||||
|
|
|
@ -13,18 +13,9 @@ import semver from 'semver';
|
|||
import cli from 'commander';
|
||||
import path from 'path';
|
||||
import {createRequire} from 'module';
|
||||
import {migrateDocusaurusProject, migrateMDToMDX} from '../lib/index.js';
|
||||
|
||||
const requiredVersion = createRequire(import.meta.url)('../package.json')
|
||||
.engines.node;
|
||||
|
||||
function wrapCommand(fn) {
|
||||
return (...args) =>
|
||||
fn(...args).catch((err) => {
|
||||
logger.error(err.stack);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
}
|
||||
const moduleRequire = createRequire(import.meta.url);
|
||||
const requiredVersion = moduleRequire('../package.json').engines.node;
|
||||
|
||||
if (!semver.satisfies(process.version, requiredVersion)) {
|
||||
logger.error('Minimum Node.js version not met :(');
|
||||
|
@ -32,6 +23,10 @@ if (!semver.satisfies(process.version, requiredVersion)) {
|
|||
process.exit(1);
|
||||
}
|
||||
|
||||
// See https://github.com/facebook/docusaurus/pull/6860
|
||||
const {migrateDocusaurusProject, migrateMDToMDX} =
|
||||
moduleRequire('../lib/index.js');
|
||||
|
||||
cli
|
||||
.command('migrate [siteDir] [newDir]')
|
||||
.option('--mdx', 'try to migrate MD to MDX too')
|
||||
|
@ -40,7 +35,7 @@ cli
|
|||
.action((siteDir = '.', newDir = '.', {mdx, page} = {}) => {
|
||||
const sitePath = path.resolve(siteDir);
|
||||
const newSitePath = path.resolve(newDir);
|
||||
wrapCommand(migrateDocusaurusProject)(sitePath, newSitePath, mdx, page);
|
||||
migrateDocusaurusProject(sitePath, newSitePath, mdx, page);
|
||||
});
|
||||
|
||||
cli
|
||||
|
@ -49,7 +44,7 @@ cli
|
|||
.action((siteDir = '.', newDir = '.') => {
|
||||
const sitePath = path.resolve(siteDir);
|
||||
const newSitePath = path.resolve(newDir);
|
||||
wrapCommand(migrateMDToMDX)(sitePath, newSitePath);
|
||||
migrateMDToMDX(sitePath, newSitePath);
|
||||
});
|
||||
|
||||
cli.parse(process.argv);
|
||||
|
@ -57,3 +52,8 @@ cli.parse(process.argv);
|
|||
if (!process.argv.slice(2).length) {
|
||||
cli.outputHelp();
|
||||
}
|
||||
|
||||
process.on('unhandledRejection', (err) => {
|
||||
logger.error(err);
|
||||
process.exit(1);
|
||||
});
|
|
@ -2,14 +2,13 @@
|
|||
"name": "@docusaurus/migrate",
|
||||
"version": "2.0.0-beta.17",
|
||||
"description": "A CLI tool to migrate from older versions of Docusaurus.",
|
||||
"main": "lib/index.js",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"watch": "tsc --watch"
|
||||
"build": "tsc -p tsconfig.build.json",
|
||||
"watch": "tsc -p tsconfig.build.json --watch"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
|
10
packages/docusaurus-migrate/tsconfig.build.json
Normal file
10
packages/docusaurus-migrate/tsconfig.build.json
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"incremental": true,
|
||||
"tsBuildInfoFile": "./lib/.tsbuildinfo",
|
||||
"rootDir": "src",
|
||||
"outDir": "lib"
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
|
@ -1,9 +1,11 @@
|
|||
// For editor typechecking; includes bin
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"extends": "./tsconfig.build.json",
|
||||
"compilerOptions": {
|
||||
"incremental": true,
|
||||
"tsBuildInfoFile": "./lib/.tsbuildinfo",
|
||||
"rootDir": "src",
|
||||
"outDir": "lib"
|
||||
}
|
||||
"noEmit": true,
|
||||
"module": "esnext",
|
||||
"allowJs": true,
|
||||
"rootDir": "."
|
||||
},
|
||||
"include": ["src", "bin"]
|
||||
}
|
||||
|
|
|
@ -245,34 +245,33 @@ cli.arguments('<command>').action((cmd) => {
|
|||
});
|
||||
|
||||
/**
|
||||
* @param {string} command
|
||||
* @param {string | undefined} command
|
||||
*/
|
||||
function isInternalCommand(command) {
|
||||
return [
|
||||
'start',
|
||||
'build',
|
||||
'swizzle',
|
||||
'deploy',
|
||||
'serve',
|
||||
'clear',
|
||||
'write-translations',
|
||||
'write-heading-ids',
|
||||
].includes(command);
|
||||
return (
|
||||
command &&
|
||||
[
|
||||
'start',
|
||||
'build',
|
||||
'swizzle',
|
||||
'deploy',
|
||||
'serve',
|
||||
'clear',
|
||||
'write-translations',
|
||||
'write-heading-ids',
|
||||
].includes(command)
|
||||
);
|
||||
}
|
||||
|
||||
async function run() {
|
||||
if (!isInternalCommand(process.argv.slice(2)[0])) {
|
||||
await externalCommand(cli, await resolveDir('.'));
|
||||
}
|
||||
|
||||
cli.parse(process.argv);
|
||||
|
||||
if (!process.argv.slice(2).length) {
|
||||
cli.outputHelp();
|
||||
}
|
||||
if (!isInternalCommand(process.argv.slice(2)[0])) {
|
||||
await externalCommand(cli, await resolveDir('.'));
|
||||
}
|
||||
|
||||
run();
|
||||
if (!process.argv.slice(2).length) {
|
||||
cli.outputHelp();
|
||||
}
|
||||
|
||||
cli.parse(process.argv);
|
||||
|
||||
process.on('unhandledRejection', (err) => {
|
||||
logger.error(err);
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
"docusaurus": "bin/docusaurus.mjs"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc && tsc -p tsconfig.client.json && node copyUntypedFiles.mjs",
|
||||
"watch": "node copyUntypedFiles.mjs && concurrently -n \"server,client\" --kill-others \"tsc --watch\" \"tsc -p tsconfig.client.json --watch\""
|
||||
"build": "tsc -p tsconfig.server.json && tsc -p tsconfig.client.json && node copyUntypedFiles.mjs",
|
||||
"watch": "node copyUntypedFiles.mjs && concurrently -n \"server,client\" --kill-others \"tsc -p tsconfig.server.json --watch\" \"tsc -p tsconfig.client.json --watch\""
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/facebook/docusaurus/issues"
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
// For editor typechecking; includes bin
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"extends": "./tsconfig.server.json",
|
||||
"compilerOptions": {
|
||||
"incremental": true,
|
||||
"tsBuildInfoFile": "./lib/.tsbuildinfo",
|
||||
"rootDir": "src",
|
||||
"outDir": "lib",
|
||||
"allowJs": true
|
||||
"noEmit": true,
|
||||
"rootDir": ".",
|
||||
"module": "esnext"
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["**/__tests__/**/*", "src/client"]
|
||||
"include": ["src", "bin"]
|
||||
}
|
||||
|
|
12
packages/docusaurus/tsconfig.server.json
Normal file
12
packages/docusaurus/tsconfig.server.json
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"incremental": true,
|
||||
"tsBuildInfoFile": "./lib/.tsbuildinfo",
|
||||
"rootDir": "src",
|
||||
"outDir": "lib",
|
||||
"allowJs": true
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["**/__tests__/**/*", "src/client"]
|
||||
}
|
Loading…
Add table
Reference in a new issue