Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena committed Feb 19, 2022
1 parent e498b6b commit 5ffef38
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 43 deletions.
11 changes: 5 additions & 6 deletions packages/docusaurus-utils-build/bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const chalk = require('chalk');
const cli = require('commander');
const build = require('../lib/build').default;
const watch = require('../lib/watch').default;

import logger from '@docusaurus/logger';
import cli from 'commander';
import {build, watch} from '../lib/index.js';

cli
.command('build')
Expand All @@ -28,8 +28,7 @@ cli

cli.arguments('<command>').action((cmd) => {
cli.outputHelp();
console.log(` ${chalk.red(`\n Unknown command ${chalk.yellow(cmd)}.`)}`);
console.log();
logger.error` Unknown command name=${cmd}.`;
});

cli.parse(process.argv);
Expand Down
21 changes: 10 additions & 11 deletions packages/docusaurus-utils-build/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "@docusaurus/utils-build",
"version": "2.0.0-beta.14",
"version": "2.0.0-beta.15",
"description": "Build and pack docusaurus plugins in one command",
"license": "MIT",
"type": "module",
"publishConfig": {
"access": "public"
},
Expand All @@ -18,21 +19,19 @@
"build": "tsc"
},
"dependencies": {
"@babel/core": "^7.16.0",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
"@babel/plugin-proposal-optional-chaining": "^7.16.0",
"@babel/plugin-transform-modules-commonjs": "^7.16.0",
"@babel/preset-typescript": "^7.16.0",
"@docusaurus/utils": "2.0.0-beta.14",
"chalk": "^4.1.2",
"@babel/core": "^7.17.5",
"@babel/plugin-transform-modules-commonjs": "^7.16.8",
"@babel/preset-typescript": "^7.16.7",
"@docusaurus/logger": "2.0.0-beta.15",
"@docusaurus/utils": "2.0.0-beta.15",
"chokidar": "^3.5.2",
"commander": "^5.1.0",
"lodash": "^4.17.21",
"prettier": "^2.5.1",
"shelljs": "^0.8.4",
"typescript": "^4.5.2"
"shelljs": "^0.8.5",
"typescript": "^4.5.5"
},
"devDependencies": {
"@docusaurus/types": "2.0.0-beta.14"
"@docusaurus/types": "2.0.0-beta.15"
}
}
13 changes: 6 additions & 7 deletions packages/docusaurus-utils-build/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/

import fs from 'fs';
import chalk from 'chalk';
import {Globby} from '@docusaurus/utils';
import logger from '@docusaurus/logger';
import Prettier from 'prettier';
import shelljs from 'shelljs';
import {compileOrCopy, compileServerCode, compileClientCode} from './compiler';
Expand Down Expand Up @@ -43,29 +43,28 @@ export default async function build(
ignore = ['**/__tests__/**'],
} = options;
// Compile: src/*.ts -> lib/*.js
console.log(chalk.cyan('Compiling source with Babel...'));
logger.info('Compiling source with Babel...');
transformDir(sourceDir, targetDir, compileServerCode, [
...ignore,
'**/*.d.ts',
]);
// Generate declaration: src/*.ts -> lib/*.d.ts
// await tsc(sourceDir, targetDir, ignore);
console.log(
chalk.cyan('Typechecking and generating declaration with TSC...'),
);
logger.info('Typechecking and generating declaration with TSC...');
const res = shelljs.exec('tsc --emitDeclarationOnly'); // 😅
if (res.code !== 0) {
throw new Error('Typechecking failed.');
}
// Strip types & prettier: src/theme/*.tsx -> lib/theme/*.js (client code will be swizzlable)
// Strip types & format: src/theme/*.tsx -> lib/theme/*.js
// (client code will be swizzlable)
if (fs.existsSync(themeDir)) {
const prettierConfig = await Prettier.resolveConfig(themeDir);
if (!prettierConfig) {
throw new Error(
'Prettier config file not found. Building the theme code requires using Prettier to format the JS code, which will be used for swizzling.',
);
}
console.log(chalk.cyan('Compiling theme with Babel + Prettier...'));
logger.info('Compiling theme with Babel + Prettier...');
transformDir(
themeDir,
themeTargetDir,
Expand Down
11 changes: 11 additions & 0 deletions packages/docusaurus-utils-build/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* 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 build from './build';
import watch from './watch';

export {build, watch};
24 changes: 9 additions & 15 deletions packages/docusaurus-utils-build/src/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import fs from 'fs';
import chokidar from 'chokidar';
import {debounce} from 'lodash';
import chalk from 'chalk';
import logger from '@docusaurus/logger';
import {compileOrCopy, compileClientCode, compileServerCode} from './compiler';

export default async function watch(
Expand Down Expand Up @@ -45,26 +45,20 @@ export default async function watch(
compileOrCopy(filePath, sourceDir, targetDir, compileServerCode);
}
} catch (e) {
console.log(chalk.red(`Error while processing ${chalk.cyan(filePath)}:`));
console.error(e);
logger.error`Error while processing path=${filePath}:`;
logger.error(e);
}
}, 200);

['add', 'change'].forEach((event) =>
watcher.on(event, async (filePath: string) => {
compile(filePath);
console.log(
chalk.green(`Compilation of ${chalk.cyan(filePath)} finished`),
);
logger.success`Compilation of path=${filePath} finished`;
}),
);
console.log(
chalk.green(
`Watching file changes in ${chalk.cyan(sourceDir)}${
fs.existsSync(themeDir)
? ` (server) and ${chalk.cyan(themeDir)} (client)`
: ''
}...`,
),
);
logger.info`Watching file changes in path=${sourceDir}${
fs.existsSync(themeDir)
? logger.interpolate` (server) and path=${themeDir} (client)`
: ''
}...`;
}
1 change: 1 addition & 0 deletions packages/docusaurus-utils-build/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"incremental": true,
"module": "es2020",
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"rootDir": "src",
"outDir": "lib"
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11106,11 +11106,11 @@ is-url@^1.2.4:
integrity sha512-ITvGim8FhRiYe4IQ5uHSkj7pVaPDrCTkNd3yq3cV7iZAcJdHTUMPMEHcqSOy9xZ9qFenQCvi+2wjH9a1nXqHww==

is-weakref@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/is-weakref/-/is-weakref-1.0.1.tgz#842dba4ec17fa9ac9850df2d6efbc1737274f2a2"
integrity sha512-b2jKc2pQZjaeFYWEf7ScFj+Be1I+PXmlu572Q8coTXZ+LD/QQZ7ShPMst8h16riVgyXTQwUsFEl74mDvc/3MHQ==
version "1.0.2"
resolved "https://registry.yarnpkg.com/is-weakref/-/is-weakref-1.0.2.tgz#9529f383a9338205e89765e0392efc2f100f06f2"
integrity sha512-qctsuLZmIQ0+vSSMfoVvyFe2+GSEvnmZ2ezTup1SBse9+twCCeial6EEi3Nc2KFcf6+qz2FBPnjXsk8xhKSaPQ==
dependencies:
call-bind "^1.0.0"
call-bind "^1.0.2"

is-whitespace-character@^1.0.0:
version "1.0.4"
Expand Down

0 comments on commit 5ffef38

Please sign in to comment.