Skip to content

Commit

Permalink
Merge pull request #6 from easyops-cn/steve/publish
Browse files Browse the repository at this point in the history
Steve/publish
  • Loading branch information
weareoutman committed Oct 24, 2020
2 parents 3c9e58c + faf9cf7 commit 2fe7286
Show file tree
Hide file tree
Showing 10 changed files with 183 additions and 25 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
on:
push:
branches:
- master
name: npm-publish
jobs:
npm-publish:
runs-on: ubuntu-latest
steps:
# The logic below handles the npm publication:
- uses: actions/checkout@v2
# these if statements ensure that a publication only occurs when
# a new release is created:
if: ${{ steps.release.outputs.release_created }}
- uses: actions/setup-node@v1
with:
node-version: 12
registry-url: 'https://registry.npmjs.org'
if: ${{ steps.release.outputs.release_created }}
- run: yarn install --frozen-lockfile
if: ${{ steps.release.outputs.release_created }}
- run: yarn build
if: ${{ steps.release.outputs.release_created }}
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
if: ${{ steps.release.outputs.release_created }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# @easyops-cn/docusaurus-search-local

![Npm Version](https://img.shields.io/npm/v/@easyops-cn/docusaurus-search-local)
[![Npm Version](https://img.shields.io/npm/v/@easyops-cn/docusaurus-search-local)](https://www.npmjs.com/package/@easyops-cn/docusaurus-search-local)
[![Build Status](https://travis-ci.com/easyops-cn/docusaurus-search-local.svg?branch=master)](https://travis-ci.com/easyops-cn/docusaurus-search-local)
[![Coverage Status](https://coveralls.io/repos/github/easyops-cn/docusaurus-search-local/badge.svg?branch=master)](https://coveralls.io/github/easyops-cn/docusaurus-search-local?branch=master)

Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
"homepage": "https://github.com/easyops-cn/docusaurus-search-local",
"scripts": {
"test": "jest",
"start": "concurrently -k -n client,server \"npm run start:client\" \"npm run start:server\"",
"start:client": "tsc --watch --project tsconfig.client.json",
"start:server": "tsc --watch --project tsconfig.server.json",
"prebuild": "rimraf dist",
"build": "tsc --project tsconfig.client.json && tsc --project tsconfig.server.json",
"build": "npm run build:client && npm run build:server",
"build:client": "tsc --project tsconfig.client.json",
"build:server": "tsc --project tsconfig.server.json",
"postbuild": "copyfiles -f src/client/theme/SearchBar/SearchBar.css dist/client/client/theme/SearchBar",
"release": "standard-version",
"coveralls": "coveralls < .coverage/lcov.info"
Expand Down Expand Up @@ -48,6 +53,7 @@
"@typescript-eslint/eslint-plugin": "^4.4.1",
"@typescript-eslint/parser": "^4.4.1",
"babel-jest": "^26.5.2",
"concurrently": "^5.3.0",
"copyfiles": "^2.4.0",
"coveralls": "^3.1.0",
"enzyme": "^3.11.0",
Expand Down
2 changes: 0 additions & 2 deletions src/client/theme/SearchBar/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { SearchSourceFactory } from "../../utils/SearchSourceFactory";
import { SuggestionTemplate } from "../../utils/SuggestionTemplate.js";
import { EmptyTemplate } from "../../utils/EmptyTemplate.js";
import { SearchResult } from "../../../shared/interfaces";

// This file is auto generated while building.
import { searchResultLimits } from "../../utils/proxiedGenerated";
import "./SearchBar.css";

Expand Down
2 changes: 0 additions & 2 deletions src/client/theme/SearchBar/fetchIndexes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import {
SearchDocumentType,
WrappedIndex,
} from "../../../shared/interfaces";

// This file is auto generated while building.
import { indexHash } from "../../utils/proxiedGenerated";

interface SerializedIndex {
Expand Down
1 change: 1 addition & 0 deletions src/client/utils/proxiedGenerated.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// This file is auto generated while building.
export * from "@generated/@easyops-cn/docusaurus-search-local/default/generated.js";
34 changes: 29 additions & 5 deletions src/server/utils/getIndexHash.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { getIndexHash } from "./getIndexHash";

jest.mock("klaw-sync");
jest.mock("fs");
const mockConsoleWarn = jest
.spyOn(console, "warn")
.mockImplementation(() => void 0);

(klawSync as jest.MockedFunction<typeof klawSync>).mockImplementation(
(root, options) => {
Expand All @@ -27,12 +30,33 @@ jest.mock("fs");
throw new Error(`Unknown file: ${filePath}`);
});

(fs.existsSync as jest.MockedFunction<typeof fs.existsSync>).mockImplementation(
(filePath: string) => {
return filePath.startsWith("/tmp/");
}
);

(fs.lstatSync as jest.MockedFunction<typeof fs.lstatSync>).mockImplementation(
(filePath: string) => {
return {
isDirectory: () => !filePath.includes("."),
} as fs.Stats;
}
);

describe("getIndexHash", () => {
test.each<[Partial<ProcessedPluginOptions>, string | null]>([
[{ hashed: false }, null],
[{ hashed: true, indexDocs: true, docsDir: "/tmp/docs" }, "a387bd69"],
[{ hashed: true, indexBlog: true, blogDir: "/tmp/blog" }, null],
])("getIndexHash(%j) should return '%s'", (config, hash) => {
test.each<[Partial<ProcessedPluginOptions>, string | null, number]>([
[{ hashed: false }, null, 0],
[{ hashed: true, indexDocs: true, docsDir: "/tmp/docs" }, "a387bd69", 0],
[{ hashed: true, indexBlog: true, blogDir: "/tmp/blog" }, null, 0],
[
{ hashed: true, indexDocs: true, docsDir: "/does-not-exist/docs" },
null,
1,
],
[{ hashed: true, indexDocs: true, docsDir: "/tmp/index.js" }, null, 1],
])("getIndexHash(%j) should return '%s'", (config, hash, warnCount) => {
expect(getIndexHash(config as ProcessedPluginOptions)).toBe(hash);
expect(mockConsoleWarn).toBeCalledTimes(warnCount);
});
});
35 changes: 25 additions & 10 deletions src/server/utils/getIndexHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,31 @@ export function getIndexHash(config: ProcessedPluginOptions): string | null {
return null;
}
const files: klawSync.Item[] = [];
if (config.indexDocs) {
files.push(
...klawSync(config.docsDir, { nodir: true, filter: markdownFilter })
);
}
if (config.indexBlog) {
files.push(
...klawSync(config.blogDir, { nodir: true, filter: markdownFilter })
);
}

const scanFiles = (
flagField: "indexDocs" | "indexBlog",
dirField: "docsDir" | "blogDir"
): void => {
if (config[flagField]) {
if (!fs.existsSync(config[dirField])) {
console.warn(
`Warn: \`${dirField}\` doesn't exist: "${config[dirField]}".`
);
} else if (!fs.lstatSync(config[dirField]).isDirectory()) {
console.warn(
`Warn: \`${dirField}\` is not a directory: "${config[dirField]}".`
);
} else {
files.push(
...klawSync(config[dirField], { nodir: true, filter: markdownFilter })
);
}
}
};

scanFiles("indexDocs", "docsDir");
scanFiles("indexBlog", "blogDir");

if (files.length > 0) {
const md5sum = crypto.createHash("md5");
for (const item of files) {
Expand Down
3 changes: 2 additions & 1 deletion src/server/utils/processDocInfos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ export function processDocInfos(
): DocInfoWithFilePath[] {
return routesPaths
.map<DocInfoWithRoute | undefined>((url: string) => {
// istanbul ignore next
if (!url.startsWith(baseUrl)) {
throw new Error(
`The route must start with the baseUrl ${baseUrl}, but was ${url}. This is a bug, please report it.`
`The route must start with the baseUrl "${baseUrl}", but was "${url}". This is a bug, please report it.`
);
}
const route = url.substr(baseUrl.length);
Expand Down
94 changes: 91 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2130,6 +2130,15 @@ cli-truncate@^2.1.0:
slice-ansi "^3.0.0"
string-width "^4.2.0"

cliui@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/cliui/-/cliui-5.0.0.tgz#deefcfdb2e800784aa34f46fa08e06851c7bbbc5"
integrity sha512-PYeGSEmmHM6zvoef2w8TPzlrnNpXIjTipYK780YswmIP9vjxmd6Y2a3CB2Ks6/AU8NHjZugXvo8w3oWM2qnwXA==
dependencies:
string-width "^3.1.0"
strip-ansi "^5.2.0"
wrap-ansi "^5.1.0"

cliui@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/cliui/-/cliui-6.0.0.tgz#511d702c0c4e41ca156d7d0e96021f23e13225b1"
Expand Down Expand Up @@ -2236,6 +2245,21 @@ concat-stream@^2.0.0:
readable-stream "^3.0.2"
typedarray "^0.0.6"

concurrently@^5.3.0:
version "5.3.0"
resolved "https://registry.yarnpkg.com/concurrently/-/concurrently-5.3.0.tgz#7500de6410d043c912b2da27de3202cb489b1e7b"
integrity sha512-8MhqOB6PWlBfA2vJ8a0bSFKATOdWlHiQlk11IfmQBPaHVP8oP2gsh2MObE6UR3hqDHqvaIvLTyceNW6obVuFHQ==
dependencies:
chalk "^2.4.2"
date-fns "^2.0.1"
lodash "^4.17.15"
read-pkg "^4.0.1"
rxjs "^6.5.2"
spawn-command "^0.0.2-1"
supports-color "^6.1.0"
tree-kill "^1.2.2"
yargs "^13.3.0"

console-control-strings@^1.0.0, console-control-strings@~1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/console-control-strings/-/console-control-strings-1.1.0.tgz#3d7cf4464db6446ea644bf4b39507f9851008e8e"
Expand Down Expand Up @@ -2554,6 +2578,11 @@ data-urls@^2.0.0:
whatwg-mimetype "^2.3.0"
whatwg-url "^8.0.0"

date-fns@^2.0.1:
version "2.16.1"
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.16.1.tgz#05775792c3f3331da812af253e1a935851d3834b"
integrity sha512-sAJVKx/FqrLYHAQeN7VpJrPhagZc9R4ImZIWYRFZaaohR3KzmuK88touwsSwSVT8Qcbd4zoDsnGfX4GFB4imyQ==

dateformat@^3.0.0:
version "3.0.3"
resolved "https://registry.yarnpkg.com/dateformat/-/dateformat-3.0.3.tgz#a6e37499a4d9a9cf85ef5872044d62901c9889ae"
Expand Down Expand Up @@ -5973,6 +6002,15 @@ read-pkg@^3.0.0:
normalize-package-data "^2.3.2"
path-type "^3.0.0"

read-pkg@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/read-pkg/-/read-pkg-4.0.1.tgz#963625378f3e1c4d48c85872b5a6ec7d5d093237"
integrity sha1-ljYlN48+HE1IyFhytabsfV0JMjc=
dependencies:
normalize-package-data "^2.3.2"
parse-json "^4.0.0"
pify "^3.0.0"

read-pkg@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/read-pkg/-/read-pkg-5.2.0.tgz#7bf295438ca5a33e56cd30e053b34ee7250c93cc"
Expand Down Expand Up @@ -6280,7 +6318,7 @@ run-parallel@^1.1.9:
resolved "https://registry.yarnpkg.com/run-parallel/-/run-parallel-1.1.9.tgz#c9dd3a7cf9f4b2c4b6244e173a6ed866e61dd679"
integrity sha512-DEqnSRTDw/Tc3FXf49zedI638Z9onwUotBMiUFKmrO2sdFKIbXamXGQ3Axd4qgphxKB4kw/qP1w5kTxnfU1B9Q==

rxjs@^6.6.2:
rxjs@^6.5.2, rxjs@^6.6.2:
version "6.6.3"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.6.3.tgz#8ca84635c4daa900c0d3967a6ee7ac60271ee552"
integrity sha512-trsQc+xYYXZ3urjOiJOuCOa5N3jAZ3eiSpQB5hIT8zGlL2QfnHLJ2r7GMkBGuIausdJN1OneaI6gQlsqNHHmZQ==
Expand Down Expand Up @@ -6546,6 +6584,11 @@ source-map@^0.7.3:
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.3.tgz#5302f8169031735226544092e64981f751750383"
integrity sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ==

spawn-command@^0.0.2-1:
version "0.0.2-1"
resolved "https://registry.yarnpkg.com/spawn-command/-/spawn-command-0.0.2-1.tgz#62f5e9466981c1b796dc5929937e11c9c6921bd0"
integrity sha1-YvXpRmmBwbeW3Fkpk34RycaSG9A=

spdx-correct@^3.0.0:
version "3.1.1"
resolved "https://registry.yarnpkg.com/spdx-correct/-/spdx-correct-3.1.1.tgz#dece81ac9c1e6713e5f7d1b6f17d468fa53d89a9"
Expand Down Expand Up @@ -6684,7 +6727,7 @@ string-width@^1.0.1:
is-fullwidth-code-point "^2.0.0"
strip-ansi "^4.0.0"

string-width@^3.0.0:
string-width@^3.0.0, string-width@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-3.1.0.tgz#22767be21b62af1081574306f69ac51b62203961"
integrity sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==
Expand Down Expand Up @@ -6785,7 +6828,7 @@ strip-ansi@^4.0.0:
dependencies:
ansi-regex "^3.0.0"

strip-ansi@^5.1.0:
strip-ansi@^5.0.0, strip-ansi@^5.1.0, strip-ansi@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-5.2.0.tgz#8c9a536feb6afc962bdfa5b104a5091c1ad9c0ae"
integrity sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==
Expand Down Expand Up @@ -6862,6 +6905,13 @@ supports-color@^5.3.0:
dependencies:
has-flag "^3.0.0"

supports-color@^6.1.0:
version "6.1.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-6.1.0.tgz#0764abc69c63d5ac842dd4867e8d025e880df8f3"
integrity sha512-qe1jfm1Mg7Nq/NSh6XE24gPXROEVsWHxC1LIx//XNlD9iw7YZQGjZNjYN7xGaEG6iKdA8EtNFW6R0gjnVXp+wQ==
dependencies:
has-flag "^3.0.0"

supports-color@^7.0.0, supports-color@^7.1.0:
version "7.2.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.2.0.tgz#1b7dcdcb32b8138801b3e478ba6a51caa89648da"
Expand Down Expand Up @@ -7024,6 +7074,11 @@ tr46@^2.0.2:
dependencies:
punycode "^2.1.1"

tree-kill@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/tree-kill/-/tree-kill-1.2.2.tgz#4ca09a9092c88b73a7cdc5e8a01b507b0790a0cc"
integrity sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==

trim-newlines@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/trim-newlines/-/trim-newlines-1.0.0.tgz#5887966bb582a4503a41eb524f7d35011815a613"
Expand Down Expand Up @@ -7336,6 +7391,15 @@ wordwrap@^1.0.0:
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb"
integrity sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus=

wrap-ansi@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-5.1.0.tgz#1fd1f67235d5b6d0fee781056001bfb694c03b09"
integrity sha512-QC1/iN/2/RPVJ5jYK8BGttj5z83LmSKmvbvrXPNCLZSEb32KKVDJDl/MOt2N01qU2H/FkzEa9PKto1BqDjtd7Q==
dependencies:
ansi-styles "^3.2.0"
string-width "^3.0.0"
strip-ansi "^5.0.0"

wrap-ansi@^6.2.0:
version "6.2.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-6.2.0.tgz#e9393ba07102e6c91a3b221478f0257cd2856e53"
Expand Down Expand Up @@ -7402,6 +7466,14 @@ yaml@^1.10.0:
resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.10.0.tgz#3b593add944876077d4d683fee01081bd9fff31e"
integrity sha512-yr2icI4glYaNG+KWONODapy2/jDdMSDnrONSjblABjD9B4Z5LgiircSt8m8sRZFNi08kG9Sm0uSHtEmP3zaEGg==

yargs-parser@^13.1.2:
version "13.1.2"
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-13.1.2.tgz#130f09702ebaeef2650d54ce6e3e5706f7a4fb38"
integrity sha512-3lbsNRf/j+A4QuSZfDRA7HRSfWrzO0YjqTJd5kjAq37Zep1CEgaYmrH9Q3GwPiB9cHyd1Y1UwggGhJGoxipbzg==
dependencies:
camelcase "^5.0.0"
decamelize "^1.2.0"

yargs-parser@^18.1.2, yargs-parser@^18.1.3:
version "18.1.3"
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-18.1.3.tgz#be68c4975c6b2abf469236b0c870362fab09a7b0"
Expand All @@ -7410,6 +7482,22 @@ yargs-parser@^18.1.2, yargs-parser@^18.1.3:
camelcase "^5.0.0"
decamelize "^1.2.0"

yargs@^13.3.0:
version "13.3.2"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-13.3.2.tgz#ad7ffefec1aa59565ac915f82dccb38a9c31a2dd"
integrity sha512-AX3Zw5iPruN5ie6xGRIDgqkT+ZhnRlZMLMHAs8tg7nRruy2Nb+i5o9bwghAogtM08q1dpr2LVoS8KSTMYpWXUw==
dependencies:
cliui "^5.0.0"
find-up "^3.0.0"
get-caller-file "^2.0.1"
require-directory "^2.1.1"
require-main-filename "^2.0.0"
set-blocking "^2.0.0"
string-width "^3.0.0"
which-module "^2.0.0"
y18n "^4.0.0"
yargs-parser "^13.1.2"

yargs@^15.3.1, yargs@^15.4.1:
version "15.4.1"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-15.4.1.tgz#0d87a16de01aee9d8bec2bfbf74f67851730f4f8"
Expand Down

0 comments on commit 2fe7286

Please sign in to comment.