Skip to content

Commit

Permalink
feat(v2): added command notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorallen0913 committed Jul 18, 2020
1 parent 998e4d5 commit 2fba092
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"@types/lodash.pick": "^4.4.6",
"@types/lodash.pickby": "^4.6.6",
"@types/node": "^13.11.0",
"@types/node-notifier": "^6.0.1",
"@types/prismjs": "^1.16.1",
"@types/react": "^16.9.38",
"@types/react-dev-utils": "^9.0.1",
Expand Down
Binary file added packages/docusaurus-utils/docusaurus.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion packages/docusaurus-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"fs-extra": "^8.1.0",
"gray-matter": "^4.0.2",
"lodash.camelcase": "^4.3.0",
"lodash.kebabcase": "^4.1.1"
"lodash.kebabcase": "^4.1.1",
"node-notifier": "^7.0.1"
},
"engines": {
"node": ">=10.15.1"
Expand Down
37 changes: 37 additions & 0 deletions packages/docusaurus-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import matter from 'gray-matter';
import {createHash} from 'crypto';
import camelCase from 'lodash.camelcase';
import kebabCase from 'lodash.kebabcase';
import notifier from 'node-notifier';
import escapeStringRegexp from 'escape-string-regexp';
import fs from 'fs-extra';
import {URL} from 'url';
Expand Down Expand Up @@ -391,3 +392,39 @@ export function getFilePathForRoutePath(routePath: string): string {
const filePath = path.dirname(routePath);
return path.join(filePath, `${fileName}/index.html`);
}

export function swizzleNotification(componentName: string | undefined): void {
notifier.notify({
title: 'Docusaurus',
message: `Successfully swizzled ${componentName}!`,
icon: path.join(__dirname, '../docusaurus.jpg'),
sound: true,
});
}

export function deployNotification(): void {
notifier.notify({
title: 'Docusaurus',
message: 'Site successfully deployed!',
icon: path.join(__dirname, '../docusaurus.jpg'),
sound: true,
});
}

export function startNotification(): void {
notifier.notify({
title: 'Docusaurus',
message: 'Site started successfully!',
icon: path.join(__dirname, '../docusaurus.jpg'),
sound: true,
});
}

export function buildNotification(): void {
notifier.notify({
title: 'Docusaurus',
message: 'Site built successfully!',
icon: path.join(__dirname, '../docusaurus.jpg'),
sound: true,
});
}
2 changes: 2 additions & 0 deletions packages/docusaurus/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ReactLoadableSSRAddon from 'react-loadable-ssr-addon';
import webpack, {Configuration, Plugin, Stats} from 'webpack';
import {BundleAnalyzerPlugin} from 'webpack-bundle-analyzer';
import merge from 'webpack-merge';
import {buildNotification} from '@docusaurus/utils';
import {STATIC_DIR_NAME} from '../constants';
import {load} from '../server';
import {BuildCLIOptions, Props} from '@docusaurus/types';
Expand Down Expand Up @@ -164,6 +165,7 @@ export default async function build(
relativeDir,
)}.\n`,
);
buildNotification();
if (forceTerminate && !cliOptions.bundleAnalyzer) {
process.exit(0);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/docusaurus/src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {loadContext} from '../server';
import loadConfig from '../server/config';
import build from './build';
import {BuildCLIOptions} from '@docusaurus/types';
import {deployNotification} from '@docusaurus/utils';

export default async function deploy(
siteDir: string,
Expand Down Expand Up @@ -189,6 +190,7 @@ export default async function deploy(
// Build static html files, then push to deploymentBranch branch of specified repo.
build(siteDir, cliOptions, false)
.then(runDeploy)
.then(deployNotification)
.catch((buildError) => {
console.error(buildError);
process.exit(1);
Expand Down
11 changes: 7 additions & 4 deletions packages/docusaurus/src/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import {normalizeUrl, posixPath} from '@docusaurus/utils';
import {normalizeUrl, posixPath, startNotification} from '@docusaurus/utils';
import chalk = require('chalk');
import chokidar from 'chokidar';
import express from 'express';
Expand Down Expand Up @@ -188,9 +188,12 @@ export default async function start(
devServer.listen(port, host, (err) => {
if (err) {
console.log(err);
}
if (cliOptions.open) {
openBrowser(openUrl);
} else {
startNotification();

if (cliOptions.open) {
openBrowser(openUrl);
}
}
});
['SIGINT', 'SIGTERM'].forEach((sig) => {
Expand Down
2 changes: 2 additions & 0 deletions packages/docusaurus/src/commands/swizzle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import fs from 'fs-extra';
import importFresh from 'import-fresh';
import path from 'path';
import {Plugin, LoadContext} from '@docusaurus/types';
import {swizzleNotification} from '@docusaurus/utils';

import {THEME_PATH} from '../constants';
import {loadContext} from '../server';
Expand Down Expand Up @@ -57,6 +58,7 @@ export default async function swizzle(
console.log(
`\n${chalk.green('Success!')} Copied ${fromMsg} to ${toMsg}.\n`,
);
swizzleNotification(componentName);
} else if (typescript) {
console.warn(
chalk.yellow(
Expand Down
24 changes: 24 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3056,6 +3056,13 @@
resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.0.tgz#69a23a3ad29caf0097f06eda59b361ee2f0639f6"
integrity sha1-aaI6OtKcrwCX8G7aWbNh7i8GOfY=

"@types/node-notifier@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/@types/node-notifier/-/node-notifier-6.0.1.tgz#282bb8c37d69be3343c359efc8b9c97fad46a0e9"
integrity sha512-PBkKwgjxu2aA24zh5Rng8FlL03R4zopZbTtzeKbWLfF+AMeHBMk3Ls12K/yZchYhe/riuiarPXcRJGUBLGb15w==
dependencies:
"@types/node" "*"

"@types/node@*", "@types/node@>= 8", "@types/node@^13.11.0":
version "13.11.0"
resolved "https://registry.yarnpkg.com/@types/node/-/node-13.11.0.tgz#390ea202539c61c8fa6ba4428b57e05bc36dc47b"
Expand Down Expand Up @@ -12621,6 +12628,18 @@ node-notifier@^6.0.0:
shellwords "^0.1.1"
which "^1.3.1"

node-notifier@^7.0.1:
version "7.0.1"
resolved "https://registry.yarnpkg.com/node-notifier/-/node-notifier-7.0.1.tgz#a355e33e6bebacef9bf8562689aed0f4230ca6f9"
integrity sha512-VkzhierE7DBmQEElhTGJIoiZa1oqRijOtgOlsXg32KrJRXsPy0NXFBqWGW/wTswnJlDCs5viRYaqWguqzsKcmg==
dependencies:
growly "^1.3.0"
is-wsl "^2.1.1"
semver "^7.2.1"
shellwords "^0.1.1"
uuid "^7.0.3"
which "^2.0.2"

node-releases@^1.1.29, node-releases@^1.1.42:
version "1.1.43"
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-1.1.43.tgz#2c6ca237f88ce11d49631f11190bb01f8d0549f2"
Expand Down Expand Up @@ -18390,6 +18409,11 @@ uuid@^3.0.1, uuid@^3.3.2, uuid@^3.4.0:
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee"
integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==

uuid@^7.0.3:
version "7.0.3"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-7.0.3.tgz#c5c9f2c8cf25dc0a372c4df1441c41f5bd0c680b"
integrity sha512-DPSke0pXhTZgoF/d+WSt2QaKMCFSfx7QegxEWT+JOuHF5aWrKEn0G+ztjuJg/gG8/ItK+rbPCD/yNv8yyih6Cg==

v8-compile-cache@^2.0.3, v8-compile-cache@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.1.0.tgz#e14de37b31a6d194f5690d67efc4e7f6fc6ab30e"
Expand Down

0 comments on commit 2fba092

Please sign in to comment.