feat(v2): v1-v2 migration cli automate migration from v1 to v2 (#3015)

* add poc for migration tool

* fix version

* fix path

* fix some type error

* fix type errors

* fix commad

* delete package.lock.json

* ignore lib folder in eslint

* ignore lib in prettier

* fix missing version

* fix sidebar in next

* use primaey color

* fix navbar link

* fix footer

* sanatize front-matter for gray-matter

* add e2e test

* fixworkflow

* add unit test

* chore(v2): fix eslint error

* refactor(v2): use descriptive variable names

* refactor(v2): refactor createProjectStructure

* refactor(v2): refactor migrateDocusaurusProject

* refactor(v2): fix eslint errors

* fix(v2): fix mistake

* use path.join

* remove console.log

* try automate migrating md file to mdx

* fix types not found

* fix types

* remove unused fixture

* use package.json for version

* add support for pages

* add support

* sanitize fortmatter only in case of special character

* chore(v2): add color to dependencies

* feat(v2): initialize config with range of color and add logs

* chore(v2): add glob dependency

* fix(v2): fix color generation

* fix(v2): fix type issue

* feat(v2): add all unknown fields to customFields

* fix(v2): fix css mistake

* fix lerna

* fix(v2): fix github actions

* feat(v2): add option flag for migrating pages

* fix special character

* remove depulicate build

* fix test

* remove unwanted file

* fix frontmatter

* remove unused file

* rerun the test

* fix links

* feat(v2): filter out more fields from customFields

* feat(v2): filter out deprecated fields from customFields

* fix items

* fix types

* merge master

* revert docs

* fix doc

* fix broken link

* fix test

* test

* fix ci

* fix ci

* fix ci

* fix ci

* fix frontmatter

* log custom fields

Co-authored-by: teikjun <teikjunhci@gmail.com>
This commit is contained in:
Anshul Goyal 2020-07-24 16:22:16 +05:30 committed by GitHub
parent 0ecd71ec06
commit a78f703366
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
52 changed files with 3740 additions and 1368 deletions

View file

@ -23,6 +23,7 @@ packages/docusaurus-plugin-sitemap/lib/
packages/docusaurus-plugin-ideal-image/lib/
packages/docusaurus-plugin-ideal-image/copyUntypedFiles.js
packages/docusaurus-theme-classic/lib/
packages/docusaurus-migrate/lib/
packages/docusaurus-1.x/.eslintrc.js
packages/docusaurus-init/templates/facebook/.eslintrc.js

View file

@ -0,0 +1,35 @@
name: MIGRATION CLI E2E TEST
on:
# Trigger the workflow on push or pull request,
# but only for the master branch
push:
branches:
- master
pull_request:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x]
steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Installation
run: yarn
- name: Migrate D1 website
run: yarn docusaurus-migrate migrate ./website-1.x ./test-migrated
- name: link
run: yarn lerna exec -- yarn link
- name: Build Test website
run: yarn build
working-directory: test-migrated
env:
CI: true

1
.gitignore vendored
View file

@ -27,6 +27,7 @@ packages/docusaurus-plugin-debug/lib/
packages/docusaurus-plugin-sitemap/lib/
packages/docusaurus-plugin-ideal-image/lib/
packages/docusaurus-theme-classic/lib/
packages/docusaurus-migrate/lib/
website/netlifyDeploy
_redirects

View file

@ -14,5 +14,6 @@ packages/docusaurus-plugin-content-pages/lib/
packages/docusaurus-plugin-debug/lib/
packages/docusaurus-plugin-sitemap/lib/
packages/docusaurus-plugin-ideal-image/lib/
packages/docusaurus-migrate/lib/
packages/docusaurus-theme-classic/lib/
__fixtures__

View file

@ -260,33 +260,33 @@ Now, whenever a new commit lands in `master`, Travis CI will run your suite of t
```yaml
# azure-pipelines.yml
trigger:
- master
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- checkout: self
persistCredentials: true
- checkout: self
persistCredentials: true
- task: NodeTool@0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
- task: NodeTool@0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
- script: |
git config --global user.name "${GH_NAME}"
git config --global user.email "${GH_EMAIL}"
git checkout -b master
echo "machine github.com login ${GH_NAME} password ${GH_TOKEN}" > ~/.netrc
cd website
yarn install
GIT_USER="${GH_NAME}" CURRENT_BRANCH=master yarn run publish-gh-pages
env:
GH_NAME: $(GH_NAME)
GH_EMAIL: $(GH_EMAIL)
GH_TOKEN: $(GH_TOKEN)
displayName: 'yarn install and build'
- script: |
git config --global user.name "${GH_NAME}"
git config --global user.email "${GH_EMAIL}"
git checkout -b master
echo "machine github.com login ${GH_NAME} password ${GH_TOKEN}" > ~/.netrc
cd website
yarn install
GIT_USER="${GH_NAME}" CURRENT_BRANCH=master yarn run publish-gh-pages
env:
GH_NAME: $(GH_NAME)
GH_EMAIL: $(GH_EMAIL)
GH_TOKEN: $(GH_TOKEN)
displayName: 'yarn install and build'
```
### Hosting on ZEIT Now

View file

@ -15,6 +15,7 @@ const ignorePatterns = [
'/packages/docusaurus-plugin-content-blog/lib',
'/packages/docusaurus-plugin-content-docs/lib',
'/packages/docusaurus-plugin-content-pages/lib',
'/packages/docusaurus-migrate/lib',
];
module.exports = {

View file

@ -0,0 +1,60 @@
#!/usr/bin/env node
/**
* 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.
*/
const chalk = require('chalk');
const semver = require('semver');
const cli = require('commander');
const path = require('path');
const requiredVersion = require('../package.json').engines.node;
const {migrateDocusaurusProject, migrateMDToMDX} = require('../lib');
function wrapCommand(fn) {
return (...args) =>
fn(...args).catch((err) => {
console.error(chalk.red(err.stack));
process.exitCode = 1;
});
}
if (!semver.satisfies(process.version, requiredVersion)) {
console.log(
chalk.red(`\nMinimum Node version not met :(`) +
chalk.yellow(
`\n\nYou are using Node ${process.version}. We require Node ${requiredVersion} or up!\n`,
),
);
process.exit(1);
}
cli
.command('migrate [siteDir] [newDir]')
.option('--mdx', 'Try to migrate MD to MDX too')
.option('--page', 'Try to migrate pages too')
.description('Migrate between versions of docusaurus website')
.action((siteDir = '.', newDir = '.', {mdx, page}) => {
const sitePath = path.resolve(siteDir);
const newSitePath = path.resolve(newDir);
wrapCommand(migrateDocusaurusProject)(sitePath, newSitePath, mdx, page);
});
cli
.command('mdx [siteDir] [newDir]')
.description('Migrate markdown files to MDX')
.action((siteDir = '.', newDir = '.') => {
const sitePath = path.resolve(siteDir);
const newSitePath = path.resolve(newDir);
wrapCommand(migrateMDToMDX)(sitePath, newSitePath);
});
cli.parse(process.argv);
if (!process.argv.slice(2).length) {
cli.outputHelp();
}

View file

@ -0,0 +1,12 @@
/**
* 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.
*/
declare module '@mapbox/hast-util-to-jsx';
declare module 'hast-util-to-string';
declare module 'color';

View file

@ -0,0 +1,404 @@
{
"name": "@docusaurus/migrate",
"version": "2.0.0-alpha.58",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@types/color-name": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz",
"integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ=="
},
"@types/fs-extra": {
"version": "9.0.1",
"dev": true,
"requires": {
"@types/node": "*"
}
},
"@types/jscodeshift": {
"version": "0.7.1",
"resolved": "https://registry.npmjs.org/@types/jscodeshift/-/jscodeshift-0.7.1.tgz",
"integrity": "sha512-4jkASx74qGl2OUK8NNFEq10QP0MXriOIqeBeNb1IdevHP8k8VDqS5Uv6nIixAA6ZUjjF6/SwOvecrjXkbcaFzw==",
"dev": true,
"requires": {
"ast-types": "0.12.1",
"recast": "0.17.2"
}
},
"@types/node": {
"version": "14.0.23",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.23.tgz",
"integrity": "sha512-Z4U8yDAl5TFkmYsZdFPdjeMa57NOvnaf1tljHzhouaPEp7LCj2JKkejpI1ODviIAQuW4CcQmxkQ77rnLsOOoKw==",
"dev": true
},
"@types/unist": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/@types/unist/-/unist-2.0.3.tgz",
"integrity": "sha512-FvUupuM3rlRsRtCN+fDudtmytGO6iHJuuRKS1Ss0pG5z8oX0diNEw94UEL7hgDbpN94rgaK5R7sWm6RrSkZuAQ=="
},
"ansi-styles": {
"version": "4.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz",
"integrity": "sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==",
"requires": {
"@types/color-name": "^1.1.1",
"color-convert": "^2.0.1"
}
},
"ast-types": {
"version": "0.12.1",
"resolved": "https://registry.npmjs.org/ast-types/-/ast-types-0.12.1.tgz",
"integrity": "sha512-H2izJAyT2xwew4TxShpmxe6f9R5hHgJQy1QloLiUC2yrJMtyraBWNJL7903rpeCY9keNUipORR/zIUC2XcYKng==",
"dev": true
},
"at-least-node": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/at-least-node/-/at-least-node-1.0.0.tgz",
"integrity": "sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg=="
},
"bail": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/bail/-/bail-1.0.5.tgz",
"integrity": "sha512-xFbRxM1tahm08yHBP16MMjVUAvDaBMD38zsM9EMAUN61omwLmKlOpB/Zku5QkjZ8TZ4vn53pj+t518cH0S03RQ=="
},
"ccount": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/ccount/-/ccount-1.0.5.tgz",
"integrity": "sha512-MOli1W+nfbPLlKEhInaxhRdp7KVLFxLN5ykwzHgLsLI3H3gs5jjFAK4Eoj3OzzcxCtumDaI8onoVDeQyWaNTkw=="
},
"chalk": {
"version": "4.1.0",
"requires": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
}
},
"character-entities": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/character-entities/-/character-entities-1.2.4.tgz",
"integrity": "sha512-iBMyeEHxfVnIakwOuDXpVkc54HijNgCyQB2w0VfGQThle6NXn50zU6V/u+LDhxHcDUPojn6Kpga3PTAD8W1bQw=="
},
"character-entities-legacy": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/character-entities-legacy/-/character-entities-legacy-1.1.4.tgz",
"integrity": "sha512-3Xnr+7ZFS1uxeiUDvV02wQ+QDbc55o97tIV5zHScSPJpcLm/r0DFPcoY3tYRp+VZukxuMeKgXYmsXQHO05zQeA=="
},
"character-reference-invalid": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/character-reference-invalid/-/character-reference-invalid-1.1.4.tgz",
"integrity": "sha512-mKKUkUbhPpQlCOfIuZkvSEgktjPFIsZKRRbC6KWVEMvlzblj3i3asQv5ODsrwt0N3pHAEvjP8KTQPHkp0+6jOg=="
},
"collapse-white-space": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/collapse-white-space/-/collapse-white-space-1.0.6.tgz",
"integrity": "sha512-jEovNnrhMuqyCcjfEJA56v0Xq8SkIoPKDyaHahwo3POf4qcSXqMYuwNcOTzp74vTsR9Tn08z4MxWqAhcekogkQ=="
},
"color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"requires": {
"color-name": "~1.1.4"
}
},
"color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
},
"commander": {
"version": "5.1.0"
},
"esprima": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz",
"integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==",
"dev": true
},
"extend": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz",
"integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g=="
},
"fs-extra": {
"version": "9.0.1",
"requires": {
"at-least-node": "^1.0.0",
"graceful-fs": "^4.2.0",
"jsonfile": "^6.0.1",
"universalify": "^1.0.0"
}
},
"graceful-fs": {
"version": "4.2.4",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.4.tgz",
"integrity": "sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw=="
},
"has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ=="
},
"inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
},
"is-alphabetical": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/is-alphabetical/-/is-alphabetical-1.0.4.tgz",
"integrity": "sha512-DwzsA04LQ10FHTZuL0/grVDk4rFoVH1pjAToYwBrHSxcrBIGQuXrQMtD5U1b0U2XVgKZCTLLP8u2Qxqhy3l2Vg=="
},
"is-alphanumerical": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/is-alphanumerical/-/is-alphanumerical-1.0.4.tgz",
"integrity": "sha512-UzoZUr+XfVz3t3v4KyGEniVL9BDRoQtY7tOyrRybkVNjDFWyo1yhXNGrrBTQxp3ib9BLAWs7k2YKBQsFRkZG9A==",
"requires": {
"is-alphabetical": "^1.0.0",
"is-decimal": "^1.0.0"
}
},
"is-buffer": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.4.tgz",
"integrity": "sha512-Kq1rokWXOPXWuaMAqZiJW4XxsmD9zGx9q4aePabbn3qCRGedtH7Cm+zV8WETitMfu1wdh+Rvd6w5egwSngUX2A=="
},
"is-decimal": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/is-decimal/-/is-decimal-1.0.4.tgz",
"integrity": "sha512-RGdriMmQQvZ2aqaQq3awNA6dCGtKpiDFcOzrTWrDAT2MiWrKQVPmxLGHl7Y2nNu6led0kEyoX0enY0qXYsv9zw=="
},
"is-hexadecimal": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/is-hexadecimal/-/is-hexadecimal-1.0.4.tgz",
"integrity": "sha512-gyPJuv83bHMpocVYoqof5VDiZveEoGoFL8m3BXNb2VW8Xs+rz9kqO8LOQ5DH6EsuvilT1ApazU0pyl+ytbPtlw=="
},
"is-plain-obj": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-2.0.0.tgz",
"integrity": "sha512-EYisGhpgSCwspmIuRHGjROWTon2Xp8Z7U03Wubk/bTL5TTRC5R1rGVgyjzBrk9+ULdH6cRD06KRcw/xfqhVYKQ=="
},
"is-whitespace-character": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/is-whitespace-character/-/is-whitespace-character-1.0.4.tgz",
"integrity": "sha512-SDweEzfIZM0SJV0EUga669UTKlmL0Pq8Lno0QDQsPnvECB3IM2aP0gdx5TrU0A01MAPfViaZiI2V1QMZLaKK5w=="
},
"is-word-character": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/is-word-character/-/is-word-character-1.0.4.tgz",
"integrity": "sha512-5SMO8RVennx3nZrqtKwCGyyetPE9VDba5ugvKLaD4KopPG5kR4mQ7tNt/r7feL5yt5h3lpuBbIUmCOG2eSzXHA=="
},
"jsonfile": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.0.1.tgz",
"integrity": "sha512-jR2b5v7d2vIOust+w3wtFKZIfpC2pnRmFAhAC/BuweZFQR8qZzxH1OyrQ10HmdVYiXWkYUqPVsz91cG7EL2FBg==",
"requires": {
"graceful-fs": "^4.1.6",
"universalify": "^1.0.0"
}
},
"markdown-escapes": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/markdown-escapes/-/markdown-escapes-1.0.4.tgz",
"integrity": "sha512-8z4efJYk43E0upd0NbVXwgSTQs6cT3T06etieCMEg7dRbzCbxUCK/GHlX8mhHRDcp+OLlHkPKsvqQTCvsRl2cg=="
},
"parse-entities": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/parse-entities/-/parse-entities-2.0.0.tgz",
"integrity": "sha512-kkywGpCcRYhqQIchaWqZ875wzpS/bMKhz5HnN3p7wveJTkTtyAB/AlnS0f8DFSqYW1T82t6yEAkEcB+A1I3MbQ==",
"requires": {
"character-entities": "^1.0.0",
"character-entities-legacy": "^1.0.0",
"character-reference-invalid": "^1.0.0",
"is-alphanumerical": "^1.0.0",
"is-decimal": "^1.0.0",
"is-hexadecimal": "^1.0.0"
}
},
"private": {
"version": "0.1.8",
"resolved": "https://registry.npmjs.org/private/-/private-0.1.8.tgz",
"integrity": "sha512-VvivMrbvd2nKkiG38qjULzlc+4Vx4wm/whI9pQD35YrARNnhxeiRktSOhSukRLFNlzg6Br/cJPet5J/u19r/mg==",
"dev": true
},
"recast": {
"version": "0.17.2",
"resolved": "https://registry.npmjs.org/recast/-/recast-0.17.2.tgz",
"integrity": "sha512-YHFvn4rBXl8eIjALjUiOV/AP3xFpyGNGNHDw9mAncAWuIdgnBKjbZQ9+P3VlsKcNaNapRVFlTEX1dvDRlYwyxg==",
"dev": true,
"requires": {
"ast-types": "0.12.1",
"esprima": "~4.0.0",
"private": "~0.1.5",
"source-map": "~0.6.1"
}
},
"remark-parse": {
"version": "8.0.2",
"requires": {
"ccount": "^1.0.0",
"collapse-white-space": "^1.0.2",
"is-alphabetical": "^1.0.0",
"is-decimal": "^1.0.0",
"is-whitespace-character": "^1.0.0",
"is-word-character": "^1.0.0",
"markdown-escapes": "^1.0.0",
"parse-entities": "^2.0.0",
"repeat-string": "^1.5.4",
"state-toggle": "^1.0.0",
"trim": "0.0.1",
"trim-trailing-lines": "^1.0.0",
"unherit": "^1.0.4",
"unist-util-remove-position": "^2.0.0",
"vfile-location": "^3.0.0",
"xtend": "^4.0.1"
}
},
"repeat-string": {
"version": "1.6.1",
"resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz",
"integrity": "sha1-jcrkcOHIirwtYA//Sndihtp15jc="
},
"replace-ext": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/replace-ext/-/replace-ext-1.0.0.tgz",
"integrity": "sha1-3mMSg3P8v3w8z6TeWkgMRaZ5WOs="
},
"semver": {
"version": "7.3.2"
},
"source-map": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
"dev": true
},
"state-toggle": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/state-toggle/-/state-toggle-1.0.3.tgz",
"integrity": "sha512-d/5Z4/2iiCnHw6Xzghyhb+GcmF89bxwgXG60wjIiZaxnymbyOmI8Hk4VqHXiVVp6u2ysaskFfXg3ekCj4WNftQ=="
},
"supports-color": {
"version": "7.1.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.1.0.tgz",
"integrity": "sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g==",
"requires": {
"has-flag": "^4.0.0"
}
},
"trim": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/trim/-/trim-0.0.1.tgz",
"integrity": "sha1-WFhUf2spB1fulczMZm+1AITEYN0="
},
"trim-trailing-lines": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/trim-trailing-lines/-/trim-trailing-lines-1.1.3.tgz",
"integrity": "sha512-4ku0mmjXifQcTVfYDfR5lpgV7zVqPg6zV9rdZmwOPqq0+Zq19xDqEgagqVbc4pOOShbncuAOIs59R3+3gcF3ZA=="
},
"trough": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/trough/-/trough-1.0.5.tgz",
"integrity": "sha512-rvuRbTarPXmMb79SmzEp8aqXNKcK+y0XaB298IXueQ8I2PsrATcPBCSPyK/dDNa2iWOhKlfNnOjdAOTBU/nkFA=="
},
"unherit": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/unherit/-/unherit-1.1.3.tgz",
"integrity": "sha512-Ft16BJcnapDKp0+J/rqFC3Rrk6Y/Ng4nzsC028k2jdDII/rdZ7Wd3pPT/6+vIIxRagwRc9K0IUX0Ra4fKvw+WQ==",
"requires": {
"inherits": "^2.0.0",
"xtend": "^4.0.0"
}
},
"unified": {
"version": "9.0.0",
"requires": {
"bail": "^1.0.0",
"extend": "^3.0.0",
"is-buffer": "^2.0.0",
"is-plain-obj": "^2.0.0",
"trough": "^1.0.0",
"vfile": "^4.0.0"
}
},
"unist-util-is": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-4.0.2.tgz",
"integrity": "sha512-Ofx8uf6haexJwI1gxWMGg6I/dLnF2yE+KibhD3/diOqY2TinLcqHXCV6OI5gFVn3xQqDH+u0M625pfKwIwgBKQ=="
},
"unist-util-remove-position": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/unist-util-remove-position/-/unist-util-remove-position-2.0.1.tgz",
"integrity": "sha512-fDZsLYIe2uT+oGFnuZmy73K6ZxOPG/Qcm+w7jbEjaFcJgbQ6cqjs/eSPzXhsmGpAsWPkqZM9pYjww5QTn3LHMA==",
"requires": {
"unist-util-visit": "^2.0.0"
},
"dependencies": {
"unist-util-visit": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/unist-util-visit/-/unist-util-visit-2.0.3.tgz",
"integrity": "sha512-iJ4/RczbJMkD0712mGktuGpm/U4By4FfDonL7N/9tATGIF4imikjOuagyMY53tnZq3NP6BcmlrHhEKAfGWjh7Q==",
"requires": {
"@types/unist": "^2.0.0",
"unist-util-is": "^4.0.0",
"unist-util-visit-parents": "^3.0.0"
}
}
}
},
"unist-util-stringify-position": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/unist-util-stringify-position/-/unist-util-stringify-position-2.0.3.tgz",
"integrity": "sha512-3faScn5I+hy9VleOq/qNbAd6pAx7iH5jYBMS9I1HgQVijz/4mv5Bvw5iw1sC/90CODiKo81G/ps8AJrISn687g==",
"requires": {
"@types/unist": "^2.0.2"
}
},
"unist-util-visit-parents": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/unist-util-visit-parents/-/unist-util-visit-parents-3.1.0.tgz",
"integrity": "sha512-0g4wbluTF93npyPrp/ymd3tCDTMnP0yo2akFD2FIBAYXq/Sga3lwaU1D8OYKbtpioaI6CkDcQ6fsMnmtzt7htw==",
"requires": {
"@types/unist": "^2.0.0",
"unist-util-is": "^4.0.0"
}
},
"universalify": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-1.0.0.tgz",
"integrity": "sha512-rb6X1W158d7pRQBg5gkR8uPaSfiids68LTJQYOtEUhoJUWBdaQHsuT/EUduxXYxcrt4r5PJ4fuHW1MHT6p0qug=="
},
"vfile": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/vfile/-/vfile-4.1.1.tgz",
"integrity": "sha512-lRjkpyDGjVlBA7cDQhQ+gNcvB1BGaTHYuSOcY3S7OhDmBtnzX95FhtZZDecSTDm6aajFymyve6S5DN4ZHGezdQ==",
"requires": {
"@types/unist": "^2.0.0",
"is-buffer": "^2.0.0",
"replace-ext": "1.0.0",
"unist-util-stringify-position": "^2.0.0",
"vfile-message": "^2.0.0"
}
},
"vfile-location": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/vfile-location/-/vfile-location-3.0.1.tgz",
"integrity": "sha512-yYBO06eeN/Ki6Kh1QAkgzYpWT1d3Qln+ZCtSbJqFExPl1S3y2qqotJQXoh6qEvl/jDlgpUJolBn3PItVnnZRqQ=="
},
"vfile-message": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/vfile-message/-/vfile-message-2.0.4.tgz",
"integrity": "sha512-DjssxRGkMvifUOJre00juHoP9DPWuzjxKuMDrhNbk2TdaYYBNMStsNhEOt3idrtI12VQYM/1+iM0KOzXi4pxwQ==",
"requires": {
"@types/unist": "^2.0.0",
"unist-util-stringify-position": "^2.0.0"
}
},
"xtend": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
"integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ=="
}
}
}

View file

@ -0,0 +1,43 @@
{
"name": "@docusaurus/migrate",
"version": "2.0.0-alpha.58",
"description": "A cli tool to migrate between different version of docusuarus",
"main": "lib/index.js",
"license": "MIT",
"engines": {
"node": ">=10.9.0"
},
"scripts": {
"build": "tsc",
"watch": "tsc --watch"
},
"publishConfig": {
"access": "public"
},
"bin": {
"docusaurus-migrate": "bin/index.js"
},
"dependencies": {
"@mapbox/hast-util-to-jsx": "^1.0.0",
"chalk": "^4.1.0",
"color": "^3.1.2",
"commander": "^5.1.0",
"fs-extra": "^9.0.1",
"glob": "^7.1.6",
"hast-util-to-string": "^1.0.4",
"hast-util-to-text": "^2.0.0",
"html-tags": "^3.1.0",
"import-fresh": "^3.2.1",
"jscodeshift": "^0.10.0",
"rehype-parse": "^7.0.1",
"remark-parse": "^8.0.2",
"remark-stringify": "^8.1.0",
"semver": "^7.3.2",
"unified": "^9.0.0",
"unist-util-visit": "^2.0.2"
},
"devDependencies": {
"@types/fs-extra": "^9.0.1",
"@types/jscodeshift": "^0.7.1"
}
}

View file

@ -0,0 +1,10 @@
---
title: Introducing Docusaurus
author: Joel Marcey
authorURL: http://twitter.com/JoelMarcey
authorImageURL: https://graph.facebook.com/611217057/picture/?height=200&width=200
authorFBID: 611217057
authorTwitter: JoelMarcey
---
# blog

View file

@ -0,0 +1,19 @@
{
"name": "docusaurus-1-website",
"version": "2.0.0-alpha.58",
"private": true,
"scripts": {
"start": "docusaurus-start",
"build": "docusaurus-build",
"publish-gh-pages": "docusaurus-publish",
"examples": "docusaurus-examples",
"write-translations": "docusaurus-write-translations",
"docusaurus-version": "docusaurus-version",
"rename-version": "docusaurus-rename-version",
"crowdin-upload": "crowdin --config ../crowdin.yaml upload sources --auto-update -b master",
"crowdin-download": "crowdin --config ../crowdin.yaml download -b master"
},
"dependencies": {
"docusaurus": "*"
}
}

View file

@ -0,0 +1,17 @@
/**
* 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.
*/
const React = require('react');
function Index(props) {
return <></>
}
module.exports = Index;

View file

@ -0,0 +1,6 @@
{
"API": [
"commands",
"doc-markdown",
]
}

View file

@ -0,0 +1,82 @@
/**
* 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.
*/
/* List of projects/orgs using your project for the users page */
const users = {
caption: 'DevSpace',
image: '/img/users/devspace.svg',
infoLink: 'https://devspace.cloud/docs/',
fbOpenSource: false,
pinned: false,
};
const siteConfig = {
title: 'Docusaurus',
tagline: 'Easy to Maintain Open Source Documentation Websites',
url: 'https://docusaurus.io',
baseUrl: '/',
organizationName: 'facebook',
projectName: 'docusaurus',
cname: 'docusaurus.io',
noIndex: false,
users,
editUrl: 'https://github.com/facebook/docusaurus/edit/master/docs/',
headerLinks: [
{doc: 'installation', label: 'Docs'},
{doc: 'tutorial-setup', label: 'Tutorial'},
{page: 'users', label: 'Users'},
{blog: true, label: 'Blog'},
{
href: 'https://github.com/facebook/docusaurus',
label: 'GitHub',
external: true,
},
],
headerIcon: 'img/docusaurus.svg',
footerIcon: 'img/docusaurus_monochrome.svg',
favicon: 'img/docusaurus.ico',
algolia: {
apiKey: '3eb9507824b8be89e7a199ecaa1a9d2c',
indexName: 'docusaurus',
algoliaOptions: {
facetFilters: ['language:LANGUAGE', 'version:VERSION'],
},
},
colors: {
primaryColor: '#2E8555',
secondaryColor: '#205C3B',
},
translationRecruitingLink: 'https://crowdin.com/project/docusaurus',
copyright: `Copyright © ${new Date().getFullYear()} Facebook Inc.`,
usePrism: ['jsx'],
highlight: {
theme: 'atom-one-dark',
},
scripts: [
'https://buttons.github.io/buttons.js',
'https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.0/clipboard.min.js',
'/js/code-blocks-buttons.js',
],
gaTrackingId: 'UA-44373548-31',
facebookAppId: '199138890728411',
facebookComments: true,
twitter: 'true',
twitterUsername: 'docusaurus',
ogImage: 'img/docusaurus.png',
twitterImage: 'img/docusaurus.png',
onPageNav: 'separate',
cleanUrl: true,
scrollToTop: true,
scrollToTopOptions: {
zIndex: 100,
},
enableUpdateTime: true,
enableUpdateBy: true,
docsSideNavCollapsible: true,
};
module.exports = siteConfig;

View file

@ -0,0 +1,7 @@
---
id: version-1.10.x-commands
title: CLI Commands
original_id: commands
---
# Doc

View file

@ -0,0 +1,7 @@
---
id: version-1.9.x-commands
title: CLI Commands
original_id: commands
---
# Doc

View file

@ -0,0 +1,7 @@
---
id: version-1.9.x-doc-markdown
title: Markdown Features
original_id: doc-markdown
---
# Doc

View file

@ -0,0 +1,8 @@
{
"version-1.9.x-docs": {
"API": [
"version-1.9.x-commands",
"version-1.9.x-doc-markdown"
]
}
}

View file

@ -0,0 +1,10 @@
---
title: Introducing Docusaurus
author: Joel Marcey
authorURL: http://twitter.com/JoelMarcey
authorImageURL: https://graph.facebook.com/611217057/picture/?height=200&width=200
authorFBID: 611217057
authorTwitter: JoelMarcey
---
# Blog

View file

@ -0,0 +1,19 @@
{
"name": "docusaurus-1-website",
"version": "2.0.0-alpha.58",
"private": true,
"scripts": {
"start": "docusaurus-start",
"build": "docusaurus-build",
"publish-gh-pages": "docusaurus-publish",
"examples": "docusaurus-examples",
"write-translations": "docusaurus-write-translations",
"docusaurus-version": "docusaurus-version",
"rename-version": "docusaurus-rename-version",
"crowdin-upload": "crowdin --config ../crowdin.yaml upload sources --auto-update -b master",
"crowdin-download": "crowdin --config ../crowdin.yaml download -b master"
},
"dependencies": {
"docusaurus": "*"
}
}

View file

@ -0,0 +1,17 @@
/**
* 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.
*/
const React = require('react');
function Index(props) {
return <></>
}
module.exports = Index;

View file

@ -0,0 +1,6 @@
{
"API": [
"commands",
"doc-markdown",
]
}

View file

@ -0,0 +1,82 @@
/**
* 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.
*/
/* List of projects/orgs using your project for the users page */
const users = {
caption: 'DevSpace',
image: '/img/users/devspace.svg',
infoLink: 'https://devspace.cloud/docs/',
fbOpenSource: false,
pinned: false,
};
const siteConfig = {
title: 'Docusaurus',
tagline: 'Easy to Maintain Open Source Documentation Websites',
url: 'https://docusaurus.io',
baseUrl: '/',
organizationName: 'facebook',
projectName: 'docusaurus',
cname: 'docusaurus.io',
noIndex: false,
users,
editUrl: 'https://github.com/facebook/docusaurus/edit/master/docs/',
headerLinks: [
{doc: 'installation', label: 'Docs'},
{doc: 'tutorial-setup', label: 'Tutorial'},
{page: 'users', label: 'Users'},
{blog: true, label: 'Blog'},
{
href: 'https://github.com/facebook/docusaurus',
label: 'GitHub',
external: true,
},
],
headerIcon: 'img/docusaurus.svg',
footerIcon: 'img/docusaurus_monochrome.svg',
favicon: 'img/docusaurus.ico',
algolia: {
apiKey: '3eb9507824b8be89e7a199ecaa1a9d2c',
indexName: 'docusaurus',
algoliaOptions: {
facetFilters: ['language:LANGUAGE', 'version:VERSION'],
},
},
colors: {
primaryColor: '#2E8555',
secondaryColor: '#205C3B',
},
translationRecruitingLink: 'https://crowdin.com/project/docusaurus',
copyright: `Copyright © ${new Date().getFullYear()} Facebook Inc.`,
usePrism: ['jsx'],
highlight: {
theme: 'atom-one-dark',
},
scripts: [
'https://buttons.github.io/buttons.js',
'https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.0/clipboard.min.js',
'/js/code-blocks-buttons.js',
],
gaTrackingId: 'UA-44373548-31',
facebookAppId: '199138890728411',
facebookComments: true,
twitter: 'true',
twitterUsername: 'docusaurus',
ogImage: 'img/docusaurus.png',
twitterImage: 'img/docusaurus.png',
onPageNav: 'separate',
cleanUrl: true,
scrollToTop: true,
scrollToTopOptions: {
zIndex: 100,
},
enableUpdateTime: true,
enableUpdateBy: true,
docsSideNavCollapsible: true,
};
module.exports = siteConfig;

View file

@ -0,0 +1,7 @@
---
id: version-1.10.x-commands
title: CLI Commands
original_id: commands
---
# Doc

View file

@ -0,0 +1,7 @@
---
id: version-1.9.x-commands
title: CLI Commands
original_id: commands
---
# Doc

View file

@ -0,0 +1,7 @@
---
id: version-1.9.x-doc-markdown
title: Markdown Features
original_id: doc-markdown
---
# Doc

View file

@ -0,0 +1,8 @@
{
"version-1.9.x-docs": {
"API": [
"version-1.9.x-commands",
"version-1.9.x-doc-markdown"
]
}
}

View file

@ -0,0 +1 @@
[ "1.10.x","1.9.10", "1.9.x"]

View file

@ -0,0 +1,6 @@
---
id: commands
title: CLI Commands
---
## Doc

View file

@ -0,0 +1,6 @@
---
id: doc-markdown
title: Markdown Features
---
## Doc

View file

@ -0,0 +1,19 @@
{
"name": "docusaurus-1-website",
"version": "2.0.0-alpha.58",
"private": true,
"scripts": {
"start": "docusaurus-start",
"build": "docusaurus-build",
"publish-gh-pages": "docusaurus-publish",
"examples": "docusaurus-examples",
"write-translations": "docusaurus-write-translations",
"docusaurus-version": "docusaurus-version",
"rename-version": "docusaurus-rename-version",
"crowdin-upload": "crowdin --config ../crowdin.yaml upload sources --auto-update -b master",
"crowdin-download": "crowdin --config ../crowdin.yaml download -b master"
},
"dependencies": {
"docusaurus": "*"
}
}

View file

@ -0,0 +1,17 @@
/**
* 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.
*/
const React = require('react');
function Index(props) {
return <></>
}
module.exports = Index;

View file

@ -0,0 +1,6 @@
{
"API": [
"commands",
"doc-markdown",
]
}

View file

@ -0,0 +1,82 @@
/**
* 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.
*/
/* List of projects/orgs using your project for the users page */
const users = {
caption: 'DevSpace',
image: '/img/users/devspace.svg',
infoLink: 'https://devspace.cloud/docs/',
fbOpenSource: false,
pinned: false,
};
const siteConfig = {
title: 'Docusaurus',
tagline: 'Easy to Maintain Open Source Documentation Websites',
url: 'https://docusaurus.io',
baseUrl: '/',
organizationName: 'facebook',
projectName: 'docusaurus',
cname: 'docusaurus.io',
noIndex: false,
users,
editUrl: 'https://github.com/facebook/docusaurus/edit/master/docs/',
headerLinks: [
{doc: 'installation', label: 'Docs'},
{doc: 'tutorial-setup', label: 'Tutorial'},
{page: 'users', label: 'Users'},
{blog: true, label: 'Blog'},
{
href: 'https://github.com/facebook/docusaurus',
label: 'GitHub',
external: true,
},
],
headerIcon: 'img/docusaurus.svg',
footerIcon: 'img/docusaurus_monochrome.svg',
favicon: 'img/docusaurus.ico',
algolia: {
apiKey: '3eb9507824b8be89e7a199ecaa1a9d2c',
indexName: 'docusaurus',
algoliaOptions: {
facetFilters: ['language:LANGUAGE', 'version:VERSION'],
},
},
colors: {
primaryColor: '#2E8555',
secondaryColor: '#205C3B',
},
translationRecruitingLink: 'https://crowdin.com/project/docusaurus',
copyright: `Copyright © ${new Date().getFullYear()} Facebook Inc.`,
usePrism: ['jsx'],
highlight: {
theme: 'atom-one-dark',
},
scripts: [
'https://buttons.github.io/buttons.js',
'https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.0/clipboard.min.js',
'/js/code-blocks-buttons.js',
],
gaTrackingId: 'UA-44373548-31',
facebookAppId: '199138890728411',
facebookComments: true,
twitter: 'true',
twitterUsername: 'docusaurus',
ogImage: 'img/docusaurus.png',
twitterImage: 'img/docusaurus.png',
onPageNav: 'separate',
cleanUrl: true,
scrollToTop: true,
scrollToTopOptions: {
zIndex: 100,
},
enableUpdateTime: true,
enableUpdateBy: true,
docsSideNavCollapsible: true,
};
module.exports = siteConfig;

View file

@ -0,0 +1,55 @@
/**
* 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 {migrateDocusaurusProject} from '../index';
import path from 'path';
import fs from 'fs-extra';
describe('migration test', () => {
test('simple website', () => {
const siteDir = path.join(
__dirname,
'__fixtures__',
'simple_website',
'website',
);
const newDir = path.join(__dirname, '__fixtures__', 'migrated_simple_site');
migrateDocusaurusProject(siteDir, newDir);
fs.removeSync(newDir);
});
test('complex website', () => {
const siteDir = path.join(
__dirname,
'__fixtures__',
'complex_website',
'website',
);
const newDir = path.join(
__dirname,
'__fixtures__',
'migrated_complex_site',
);
migrateDocusaurusProject(siteDir, newDir);
fs.removeSync(newDir);
});
test('missing versions', () => {
const siteDir = path.join(
__dirname,
'__fixtures__',
'missing_version_website',
'website',
);
const newDir = path.join(
__dirname,
'__fixtures__',
'migrated_missing_version_site',
);
migrateDocusaurusProject(siteDir, newDir);
fs.removeSync(newDir);
});
});

View file

@ -0,0 +1,52 @@
/**
* 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 {RawData, Data} from './types';
function splitHeader(content: string): RawData {
// New line characters need to handle all operating systems.
const lines = content.split(/\r?\n/);
if (lines[0] !== '---') {
return {};
}
let i = 1;
for (; i < lines.length - 1; i = 1 + i) {
if (lines[i] === '---') {
break;
}
}
return {
header: lines.slice(1, i + 1).join('\n'),
content: lines.slice(i + 1).join('\n'),
};
}
export default function extractMetadata(content: string): Data {
const metadata: {[key: string]: string} = {};
const both = splitHeader(content);
if (!both.content) {
if (!both.header) {
return {metadata, rawContent: content};
}
return {metadata, rawContent: both.header};
}
// New line characters => to handle all operating systems.
const lines = (both.header ?? '').split(/\r?\n/);
for (let i = 0; i < lines.length - 1; i += 1) {
const keyvalue = lines[i].split(':');
const key = keyvalue[0].trim();
let value = keyvalue.slice(1).join(':').trim();
try {
value = JSON.parse(value);
} catch (err) {
// Ignore the error as it means it's not a JSON value.
}
metadata[key] = value;
}
return {metadata, rawContent: both.content};
}

View file

@ -0,0 +1,748 @@
/**
* 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 * as fs from 'fs-extra';
import importFresh from 'import-fresh';
import chalk from 'chalk';
import glob from 'glob';
import Color from 'color';
import {
VersionOneConfig,
VersionTwoConfig,
ClassicPresetEntries,
SidebarEntries,
} from './types';
import extractMetadata from './frontMatter';
import migratePage from './transform';
import sanitizeMD from './sanitizeMD';
import path from 'path';
const DOCUSAURUS_VERSION = (importFresh('../package.json') as {version: string})
.version;
export function walk(dir: string): Array<string> {
let results: Array<string> = [];
const list = fs.readdirSync(dir);
list.forEach((file: string) => {
const fullPath = `${dir}/${file}`;
const stat = fs.statSync(fullPath);
if (stat && stat.isDirectory()) {
results = results.concat(walk(fullPath));
} else {
results.push(fullPath);
}
});
return results;
}
function sanitizedFileContent(
content: string,
migrateMDFiles: boolean,
): string {
const extractedData = extractMetadata(content);
const extractedMetaData = Object.entries(extractedData.metadata).reduce(
(metaData, value) => {
return `${metaData}\n${value[0]}: ${
value[0] === 'tags' ||
!!String(value[1]).match(/^(\w| |\.|-)+$/m) ||
String(value[1]).match(/^("|').+("|')$/)
? value[1]
: `"${value[1]}"`
}`;
},
'',
);
const sanitizedData = `---${extractedMetaData}\n---\n${
migrateMDFiles
? sanitizeMD(extractedData.rawContent)
: extractedData.rawContent
}`;
return sanitizedData;
}
export async function migrateDocusaurusProject(
siteDir: string,
newDir: string,
shouldMigrateMdFiles: boolean = false,
shouldMigratePages: boolean = false,
): Promise<void> {
const siteConfig = importFresh(`${siteDir}/siteConfig`) as VersionOneConfig;
console.log('Starting migration from v1 to v2...');
const config = createConfigFile(siteConfig);
const classicPreset = config.presets[0][1];
const deps: Record<string, string> = {
'@docusaurus/core': DOCUSAURUS_VERSION,
'@docusaurus/preset-classic': DOCUSAURUS_VERSION,
clsx: '^1.1.1',
react: '^16.10.2',
'react-dom': '^16.10.2',
};
try {
createClientRedirects(siteConfig, deps, config);
console.log(
chalk.green('Successfully created client redirect for non clean URL'),
);
} catch (errorInClientRedirect) {
console.log(
chalk.red(`Error while creating redirects: ${errorInClientRedirect}`),
);
}
if (shouldMigratePages) {
try {
createPages(newDir, siteDir);
console.log(
chalk.green(
'Successfully created pages (check migration page for more details)',
),
);
} catch (errorInMigratingPages) {
console.log(
chalk.red(
`Error occurred while creating pages: ${errorInMigratingPages}`,
),
);
}
} else {
try {
createDefaultLandingPage(newDir);
console.log(
chalk.green(
'Successfully created landing page (check migration page for more details)',
),
);
} catch (errorInLandingPage) {
console.log(
chalk.red(
`Error occurred while creating landing page: ${errorInLandingPage}`,
),
);
}
}
try {
migrateStaticFiles(siteDir, newDir);
console.log(chalk.green('Successfully migrated static folder'));
} catch (errorInStatic) {
console.log(
chalk.red(`Error occurred while copying static folder: ${errorInStatic}`),
);
}
try {
migrateBlogFiles(siteDir, newDir, classicPreset, shouldMigrateMdFiles);
} catch (errorInMigratingBlogs) {
console.log(
chalk.red(
`Error occurred while migrating blogs: ${errorInMigratingBlogs}`,
),
);
}
try {
handleVersioning(siteDir, newDir, config, shouldMigrateMdFiles);
} catch (errorInVersion) {
console.log(
chalk.red(
`Error occurred while migrating versioned docs: ${errorInVersion}`,
),
);
}
try {
migrateLatestDocs(siteDir, newDir, shouldMigrateMdFiles, classicPreset);
} catch (errorInDoc) {
chalk.red(`Error occurred while migrating docs: ${errorInDoc}`);
}
try {
migrateLatestSidebar(siteDir, newDir, classicPreset, siteConfig);
} catch (error) {
console.log(chalk.red(`Error occurred while migrating sidebar: ${error}`));
}
try {
fs.writeFileSync(
path.join(newDir, 'docusaurus.config.js'),
`module.exports=${JSON.stringify(config, null, 2)}`,
);
console.log(
chalk.green(
`Successfully created a new config file with new navbar and footer config`,
),
);
} catch (error) {
console.log(
chalk.red(`Error occurred while creating config file: ${error}`),
);
}
try {
migratePackageFile(siteDir, deps, newDir);
} catch (error) {
console.log(
chalk.red(
`Error occurred while creating package.json file for project: ${error}`,
),
);
}
console.log('Completed migration from v1 to v2');
}
export function createConfigFile(
siteConfig: VersionOneConfig,
): VersionTwoConfig {
const homePageId = siteConfig.headerLinks?.filter((value) => value.doc)[0]
.doc;
const customConfigFields: Record<string, any> = {};
// add fields that are unknown to v2 to customConfigFields
Object.keys(siteConfig).forEach((key: any) => {
const knownFields = [
'title',
'tagline',
'url',
'baseUrl',
'organizationName',
'projectName',
'scripts',
'stylesheets',
'favicon',
'cname',
'noIndex',
'headerLinks',
'headerIcon',
'footerIcon',
'algolia',
'colors',
'copyright',
'editUrl',
'facebookComments',
'usePrism',
'highlight',
'twitterUsername',
'scrollToTopOptions',
'twitter',
'twitterImage',
'onPageNav',
'cleanUrl',
'ogImage',
'scrollToTop',
'enableUpdateTime',
'enableUpdateBy',
'docsSideNavCollapsible',
'gaTrackingId',
];
const value = siteConfig[key as keyof typeof siteConfig];
if (value !== undefined && !knownFields.includes(key)) {
customConfigFields[key] = value;
}
});
console.log(
`${chalk.yellow(
'Following Fields from siteConfig.js will be added to docusaurus.config.js in `customFields`',
)}\n${chalk.yellow(Object.keys(customConfigFields).join('\n'))}`,
);
const result: VersionTwoConfig = {
title: siteConfig.title ?? '',
tagline: siteConfig.tagline,
url: siteConfig.url ?? '',
baseUrl: siteConfig.baseUrl ?? '',
organizationName: siteConfig.organizationName,
projectName: siteConfig.projectName,
scripts: siteConfig.scripts,
stylesheets: siteConfig.stylesheets,
favicon: siteConfig.favicon ?? '',
customFields: customConfigFields,
onBrokenLinks: 'log',
presets: [
[
'@docusaurus/preset-classic',
{
docs: {
homePageId,
showLastUpdateAuthor: true,
showLastUpdateTime: true,
editUrl: siteConfig.editUrl,
},
blog: {},
theme: {},
},
],
],
plugins: [],
themeConfig: {
navbar: {
title: siteConfig.title,
logo: siteConfig.headerIcon
? {
src: siteConfig.headerIcon,
}
: undefined,
items: (siteConfig.headerLinks ?? [])
.map((link) => {
if (link.doc) {
return {
to: `docs/${link.doc === homePageId ? '' : link.doc}`,
label: link.label,
position: 'left',
};
}
if (link.page) {
return {
to: `/${link.page}`,
label: link.label,
position: 'left',
};
}
if (link.href) {
return {href: link.href, label: link.label, position: 'left'};
}
return null;
})
.filter(Boolean),
},
image: siteConfig.ogImage ? siteConfig.ogImage : undefined,
footer: {
links: siteConfig.twitterUsername
? [
{
title: 'Community',
items: [
{
label: 'Twitter',
to: `https://twitter.com/${siteConfig.twitterUsername}`,
},
],
},
]
: [],
copyright: siteConfig.copyright,
logo: {
src: siteConfig.footerIcon,
},
},
algolia: siteConfig.algolia ? siteConfig.algolia : undefined,
gtag: siteConfig.gaTrackingId
? {
trackingID: siteConfig.gaTrackingId,
}
: undefined,
},
};
return result;
}
function createClientRedirects(
siteConfig: VersionOneConfig,
deps: {[key: string]: string},
config: VersionTwoConfig,
): void {
if (!siteConfig.cleanUrl) {
deps['@docusaurus/plugin-client-redirects'] = DOCUSAURUS_VERSION;
config.plugins.push([
'@docusaurus/plugin-client-redirects',
{fromExtensions: ['html']},
]);
}
}
function createPages(newDir: string, siteDir: string): void {
fs.mkdirpSync(path.join(newDir, 'src', 'pages'));
if (fs.existsSync(path.join(siteDir, 'pages', 'en'))) {
try {
fs.copySync(
path.join(siteDir, 'pages', 'en'),
path.join(newDir, 'src', 'pages'),
);
const files = glob.sync('**/*.js', {
cwd: path.join(newDir, 'src', 'pages'),
});
files.forEach((file) => {
const filePath = path.join(newDir, 'src', 'pages', file);
const content = String(fs.readFileSync(filePath));
fs.writeFileSync(filePath, migratePage(content));
});
} catch (error) {
console.log(chalk.red(`Unable to migrate Pages : ${error}`));
createDefaultLandingPage(newDir);
}
} else {
console.log('Ignoring Pages');
}
}
function createDefaultLandingPage(newDir: string) {
const indexPage = `import Layout from "@theme/Layout";
import React from "react";
export default () => {
return <Layout />;
};
`;
fs.mkdirpSync(`${newDir}/src/pages/`);
fs.writeFileSync(`${newDir}/src/pages/index.js`, indexPage);
}
function migrateStaticFiles(siteDir: string, newDir: string): void {
if (fs.existsSync(path.join(siteDir, 'static'))) {
fs.copySync(path.join(siteDir, 'static'), path.join(newDir, 'static'));
} else {
fs.mkdirSync(path.join(newDir, 'static'));
}
}
function migrateBlogFiles(
siteDir: string,
newDir: string,
classicPreset: ClassicPresetEntries,
migrateMDFiles: boolean,
): void {
if (fs.existsSync(path.join(siteDir, 'blog'))) {
fs.copySync(path.join(siteDir, 'blog'), path.join(newDir, 'blog'));
const files = walk(path.join(newDir, 'blog'));
files.forEach((file) => {
const content = String(fs.readFileSync(file));
fs.writeFileSync(file, sanitizedFileContent(content, migrateMDFiles));
});
classicPreset.blog.path = 'blog';
console.log(
chalk.green(
`Successfully migrated blogs to version 2 with change in frontmatter`,
),
);
} else {
console.log(chalk.yellow(`Blog not found. Skipping migration for blog`));
}
}
function handleVersioning(
siteDir: string,
newDir: string,
config: VersionTwoConfig,
migrateMDFiles: boolean,
): void {
if (fs.existsSync(path.join(siteDir, 'versions.json'))) {
const loadedVersions: Array<string> = JSON.parse(
String(fs.readFileSync(path.join(siteDir, 'versions.json'))),
);
fs.copyFile(
path.join(siteDir, 'versions.json'),
path.join(newDir, 'versions.json'),
);
const versions = loadedVersions.reverse();
const versionRegex = new RegExp(`version-(${versions.join('|')})-`, 'mgi');
migrateVersionedSidebar(siteDir, newDir, versions, versionRegex, config);
fs.mkdirpSync(path.join(newDir, 'versioned_docs'));
migrateVersionedDocs(
versions,
siteDir,
newDir,
versionRegex,
migrateMDFiles,
);
console.log(
chalk.green(
`Successfully migrated version docs and sidebar. The following doc versions have been created: \n${loadedVersions.join(
'\n',
)}`,
),
);
} else {
console.log(
chalk.yellow(
'Versioned docs not found. Skipping migration for versioned docs',
),
);
}
}
function migrateVersionedDocs(
versions: string[],
siteDir: string,
newDir: string,
versionRegex: RegExp,
migrateMDFiles: boolean,
): void {
versions.reverse().forEach((version, index) => {
if (index === 0) {
fs.copySync(
path.join(siteDir, '..', 'docs'),
path.join(newDir, 'versioned_docs', `version-${version}`),
);
fs.copySync(
path.join(siteDir, 'versioned_docs', `version-${version}`),
path.join(newDir, 'versioned_docs', `version-${version}`),
);
return;
}
try {
fs.mkdirsSync(path.join(newDir, 'versioned_docs', `version-${version}`));
fs.copySync(
path.join(newDir, 'versioned_docs', `version-${versions[index - 1]}`),
path.join(newDir, 'versioned_docs', `version-${version}`),
);
fs.copySync(
path.join(siteDir, 'versioned_docs', `version-${version}`),
path.join(newDir, 'versioned_docs', `version-${version}`),
);
} catch {
fs.copySync(
path.join(newDir, 'versioned_docs', `version-${versions[index - 1]}`),
path.join(newDir, 'versioned_docs', `version-${version}`),
);
}
});
const files = walk(path.join(newDir, 'versioned_docs'));
files.forEach((pathToFile) => {
const content = fs.readFileSync(pathToFile).toString();
fs.writeFileSync(
pathToFile,
sanitizedFileContent(content.replace(versionRegex, ''), migrateMDFiles),
);
});
}
function migrateVersionedSidebar(
siteDir: string,
newDir: string,
versions: string[],
versionRegex: RegExp,
config: VersionTwoConfig,
): void {
if (fs.existsSync(path.join(siteDir, 'versioned_sidebars'))) {
fs.mkdirpSync(path.join(newDir, 'versioned_sidebars'));
const sidebars: {
entries: SidebarEntries;
version: string;
}[] = [];
versions.forEach((version, index) => {
let sidebarEntries: SidebarEntries;
const sidebarPath = path.join(
siteDir,
'versioned_sidebars',
`version-${version}-sidebars.json`,
);
try {
fs.statSync(sidebarPath);
sidebarEntries = JSON.parse(String(fs.readFileSync(sidebarPath)));
} catch {
sidebars.push({version, entries: sidebars[index - 1].entries});
return;
}
const newSidebar = Object.entries(sidebarEntries).reduce(
(topLevel: {[key: string]: any}, value) => {
const key = value[0].replace(versionRegex, '');
// eslint-disable-next-line no-param-reassign
topLevel[key] = Object.entries(value[1]).reduce(
(
acc: {[key: string]: Array<Record<string, unknown> | string>},
val,
) => {
acc[val[0].replace(versionRegex, '')] = (val[1] as Array<
any
>).map((item) => {
if (typeof item === 'string') {
return item.replace(versionRegex, '');
}
return {
type: 'category',
label: item.label,
ids: item.ids.map((id: string) =>
id.replace(versionRegex, ''),
),
};
});
return acc;
},
{},
);
return topLevel;
},
{},
);
sidebars.push({version, entries: newSidebar});
});
sidebars.forEach((sidebar) => {
const newSidebar = Object.entries(sidebar.entries).reduce(
(acc: {[key: string]: any}, val) => {
const key = `version-${sidebar.version}/${val[0]}`;
// eslint-disable-next-line prefer-destructuring
acc[key] = Object.entries(val[1]).map((value) => {
return {
type: 'category',
label: value[0],
items: (value[1] as Array<any>).map((sidebarItem) => {
if (typeof sidebarItem === 'string') {
return {
type: 'doc',
id: `version-${sidebar.version}/${sidebarItem}`,
};
}
return {
type: 'category',
label: sidebarItem.label,
items: sidebarItem.ids.map((id: string) => ({
type: 'doc',
id: `version-${sidebar.version}/${id}`,
})),
};
}),
};
});
return acc;
},
{},
);
fs.writeFileSync(
path.join(
newDir,
'versioned_sidebars',
`version-${sidebar.version}-sidebars.json`,
),
JSON.stringify(newSidebar, null, 2),
);
});
config.themeConfig.navbar.items.push({
label: 'Version',
to: 'docs',
position: 'right',
items: [
{
label: versions[versions.length - 1],
to: 'docs/',
activeBaseRegex: `docs/(?!${versions.join('|')}|next)`,
},
...versions
.reverse()
.slice(1)
.map((version) => ({
label: version,
to: `docs/${version}/`,
})),
{
label: 'Master/Unreleased',
to: `docs/next/`,
activeBaseRegex: `docs/next/(?!support|team|resources)`,
},
],
});
}
}
function migrateLatestSidebar(
siteDir: string,
newDir: string,
classicPreset: ClassicPresetEntries,
siteConfig: VersionOneConfig,
): void {
try {
fs.copyFileSync(
path.join(siteDir, 'sidebars.json'),
path.join(newDir, 'sidebars.json'),
);
classicPreset.docs.sidebarPath = path.join(newDir, 'sidebars.json');
} catch {
console.log(
chalk.yellow(`Sidebar not found. Skipping migration for sidebar`),
);
}
if (siteConfig.colors) {
const primaryColor = Color(siteConfig.colors.primaryColor);
const css = `:root{
--ifm-color-primary-lightest: ${primaryColor.darken(-0.3).hex()};
--ifm-color-primary-lighter: ${primaryColor.darken(-0.15).hex()};
--ifm-color-primary-light: ${primaryColor.darken(-0.1).hex()};
--ifm-color-primary: ${siteConfig.colors.primaryColor};
--ifm-color-primary-dark: ${primaryColor.darken(0.1).hex()};
--ifm-color-primary-darker: ${primaryColor.darken(0.15).hex()};
--ifm-color-primary-darkest: ${primaryColor.darken(0.3).hex()};
}
`;
fs.mkdirpSync(path.join(newDir, 'src', 'css'));
fs.writeFileSync(path.join(newDir, 'src', 'css', 'customTheme.css'), css);
classicPreset.theme.customCss = path.join(
newDir,
'src',
'css',
'customTheme.css',
);
}
}
function migrateLatestDocs(
siteDir: string,
newDir: string,
migrateMDFiles: boolean,
classicPreset: ClassicPresetEntries,
): void {
if (fs.existsSync(path.join(siteDir, '..', 'docs'))) {
const docsPath = path.join(
path.relative(newDir, path.join(siteDir, '..')),
'docs',
);
classicPreset.docs.path = docsPath;
const files = walk(path.join(siteDir, '..', 'docs'));
files.forEach((file) => {
const content = String(fs.readFileSync(file));
fs.writeFileSync(file, sanitizedFileContent(content, migrateMDFiles));
});
console.log(chalk.green(`Successfully migrated docs to version 2`));
} else {
console.log(
chalk.yellow(`Docs folder not found. Skipping migration for docs`),
);
}
}
function migratePackageFile(
siteDir: string,
deps: {[key: string]: string},
newDir: string,
): void {
const packageFile = importFresh(`${siteDir}/package.json`) as {
[key: string]: any;
};
packageFile.scripts = {
...packageFile.scripts,
start: 'docusaurus start',
build: 'docusaurus build',
swizzle: 'docusaurus swizzle',
deploy: 'docusaurus deploy',
docusaurus: 'docusaurus',
};
if (packageFile.dependencies) {
delete packageFile.dependencies.docusaurus;
}
if (packageFile.devDependencies) {
delete packageFile.devDependencies.docusaurus;
}
packageFile.dependencies = {
...packageFile.dependencies,
...deps,
};
fs.writeFileSync(
path.join(newDir, 'package.json'),
JSON.stringify(packageFile, null, 2),
);
console.log(chalk.green(`Successfully migrated package.json file`));
}
export async function migrateMDToMDX(
siteDir: string,
newDir: string,
): Promise<void> {
fs.mkdirpSync(newDir);
fs.copySync(siteDir, newDir);
const files = walk(newDir);
files.forEach((file) => {
fs.writeFileSync(
file,
sanitizedFileContent(String(fs.readFileSync(file)), true),
);
});
console.log(`Succesfully migrated ${siteDir} to ${newDir}`);
}

View file

@ -0,0 +1,52 @@
/**
* 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 markdown from 'remark-parse';
import toJsx from '@mapbox/hast-util-to-jsx';
import unified from 'unified';
import parse from 'rehype-parse';
import visit from 'unist-util-visit';
import remarkStringify from 'remark-stringify';
import htmlTags from 'html-tags';
import toText from 'hast-util-to-string';
const tags = htmlTags.reduce((acc: {[key: string]: boolean}, tag) => {
acc[tag] = true;
return acc;
}, {});
export default function sanitizeMD(code: string): string {
const markdownTree = unified()
.use(markdown as any)
.parse(code);
visit(markdownTree, 'code', (node) => {
node.value = `\n<!--${node.value}-->\n`;
});
visit(markdownTree, 'inlineCode', (node) => {
node.value = `<!--${node.value}-->`;
});
const markdownString = unified()
.use(remarkStringify as any, {fence: '`', fences: true})
.stringify(markdownTree);
const htmlTree = unified()
.use(parse as any)
.parse(markdownString);
visit(htmlTree, 'element', (node) => {
if (!tags[node.tagName as string]) {
node.type = 'text';
node.value = node.tagName + toText(node);
delete node.children;
delete node.tagName;
}
});
return toJsx(htmlTree)
.replace(/\{\/\*|\*\/\}/g, '')
.replace(/\{\/\*|\*\/\}/g, '')
.replace(/<html><head \/><body>|<\/body><\/html>/g, '');
}

View file

@ -0,0 +1,201 @@
/**
* 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 jscodeshift from 'jscodeshift';
const empty = () =>
jscodeshift.arrowFunctionExpression(
[jscodeshift.identifier('props')],
jscodeshift.jsxElement(
jscodeshift.jsxOpeningElement(jscodeshift.jsxIdentifier('div'), [
jscodeshift.jsxSpreadAttribute(jscodeshift.identifier('props')),
]),
jscodeshift.jsxClosingElement(jscodeshift.jsxIdentifier('div')),
),
);
const property = (key: string, value: jscodeshift.ArrowFunctionExpression) =>
jscodeshift.objectProperty(jscodeshift.identifier(key), value);
const processCallExpression = (
node: jscodeshift.ASTPath<jscodeshift.VariableDeclarator>,
) => {
const args = (node?.value?.init as any)?.arguments[0];
if (args.type === 'Literal') {
if (args.value.includes('../../core/CompLibrary')) {
const newDeclartor = jscodeshift.variableDeclarator(
node.value.id,
jscodeshift.objectExpression([
property('Container', empty()),
property('GridBlock', empty()),
property('MarkdownBlock', empty()),
]),
);
jscodeshift(node).replaceWith(newDeclartor);
}
}
if (args.type === 'TemplateLiteral') {
if (
args.quasis
.map((element: jscodeshift.TemplateElement) => element.value.raw)
.join('')
.match(/\/core\//)
) {
const newDeclartor = jscodeshift.variableDeclarator(
node.value.id,
empty(),
);
jscodeshift(node).replaceWith(newDeclartor);
}
}
};
const processMemberExpression = (
node: jscodeshift.ASTPath<jscodeshift.VariableDeclarator>,
) => {
const args = (node?.value?.init as any)?.object?.arguments[0];
if (args.type === 'Literal') {
if (args.value === '../../core/CompLibrary.js') {
const newDeclartor = jscodeshift.variableDeclarator(
node.value.id,
jscodeshift.objectExpression([
property('Container', empty()),
property('GridBlock', empty()),
property('MarkdownBlock', empty()),
]),
);
jscodeshift(node).replaceWith(newDeclartor);
} else if (args.value.match(/server/)) {
const newDeclartor = jscodeshift.variableDeclarator(
node.value.id,
empty(),
);
jscodeshift(node).replaceWith(newDeclartor);
}
}
if (args.type === 'TemplateLiteral') {
if (
args.quasis
.map((ele: jscodeshift.TemplateElement) => ele.value.raw)
.join('')
.match(/\/core\//)
) {
const newDeclartor = jscodeshift.variableDeclarator(
node.value.id,
empty(),
);
jscodeshift(node).replaceWith(newDeclartor);
}
}
};
export default function transformer(file: string): string {
const root = jscodeshift(file);
const r = getImportDeclaratorPaths(root);
r.forEach((node) => {
if (node?.value?.init?.type === 'CallExpression') {
processCallExpression(node);
} else if (node?.value?.init?.type === 'MemberExpression') {
processMemberExpression(node);
}
});
if (r[r.length - 1]) {
jscodeshift(r[r.length - 1].parent).insertAfter(
jscodeshift.importDeclaration(
[jscodeshift.importDefaultSpecifier(jscodeshift.identifier('Layout'))],
jscodeshift.literal('@theme/Layout'),
),
);
}
root
.find(jscodeshift.AssignmentExpression, {
operator: '=',
left: {
type: 'MemberExpression',
object: {
name: 'module',
},
property: {
name: 'exports',
},
},
right: {
type: 'Identifier',
},
})
.filter(function (p) {
return p.parentPath.parentPath.name === 'body';
})
.forEach(function (p) {
const exportDecl = jscodeshift.exportDeclaration(
true,
jscodeshift.arrowFunctionExpression(
[jscodeshift.identifier('props')],
jscodeshift.jsxElement(
jscodeshift.jsxOpeningElement(
jscodeshift.jsxIdentifier('Layout'),
[],
),
jscodeshift.jsxClosingElement(jscodeshift.jsxIdentifier('Layout')),
[
jscodeshift.jsxElement(
jscodeshift.jsxOpeningElement(
jscodeshift.jsxIdentifier((p.value.right as any).name),
[
jscodeshift.jsxSpreadAttribute(
jscodeshift.identifier('props'),
),
],
true,
),
),
],
),
),
);
exportDecl.comments = p.parentPath.value.comments;
jscodeshift(p.parentPath).replaceWith(exportDecl);
});
return root.toSource();
}
function getDefaultImportDeclarators(rootAst: jscodeshift.Collection) {
// var ... = require('y')
return rootAst
.find(jscodeshift.VariableDeclarator, {
init: {
callee: {
name: 'require',
},
},
})
.filter((variableDeclarator) => {
return !!variableDeclarator.value;
});
}
function getNamedImportDeclarators(rootAst: jscodeshift.Collection) {
// var ... = require('y').x
return rootAst.find(jscodeshift.VariableDeclarator, {
init: {
object: {
callee: {
name: 'require',
},
},
},
});
}
function getImportDeclaratorPaths(variableDeclaration: jscodeshift.Collection) {
const defaultImports = getDefaultImportDeclarators(variableDeclaration);
const namedImports = getNamedImportDeclarators(variableDeclaration);
return [...defaultImports.paths(), ...namedImports.paths()];
}

View file

@ -0,0 +1,126 @@
/**
* 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.
*/
export type RawData = {
header?: string;
content?: string;
};
export type Data = {
metadata: {[key: string]: string};
rawContent: string;
};
export type ClassicPresetEntries = {
docs: {[key: string]: any};
blog: {[key: string]: any};
theme: {[key: string]: any};
};
export type SidebarEntries = {
[key: string]:
| Record<string, unknown>
| Array<Record<string, unknown> | string>;
};
export interface VersionTwoConfig {
baseUrl: string;
favicon: string;
tagline?: string;
title: string;
url: string;
organizationName?: string;
projectName?: string;
githubHost?: string;
onBrokenLinks: string;
plugins: Array<[string, {[key: string]: any}]>;
themes?: [];
presets: [[string, ClassicPresetEntries]];
themeConfig: {
gtag?: {
trackingID?: string;
};
navbar: {
title?: string;
logo?: {
src?: string;
};
items: Array<Record<string, unknown> | null>;
};
image?: string;
footer: {
links: Array<{
title: string;
items: Array<{
label: string;
to: string;
}>;
}>;
copyright?: string;
logo: {
src?: string;
};
};
algolia?: Record<string, unknown>;
};
customFields: {
[key: string]: unknown;
};
scripts?: (
| string
| {
src: string;
[key: string]: unknown;
}
)[];
stylesheets?: (
| string
| {
href: string;
[key: string]: unknown;
}
)[];
}
export type VersionOneConfig = {
title?: string;
tagline?: string;
url?: string;
baseUrl?: string;
defaultVersionShown?: string;
organizationName?: string;
projectName?: string;
noIndex?: string;
headerLinks?: Array<any>;
headerIcon?: string;
favicon?: string;
colors?: any;
copyright?: string;
editUrl?: string;
users?: Array<Record<string, unknown>>;
disableHeaderTitle?: string;
disableTitleTagline?: string;
separateCss?: Array<Record<string, unknown>>;
footerIcon?: string;
translationRecruitingLink?: string;
algolia?: Record<string, unknown>;
gaTrackingId?: string;
highlight?: Record<string, unknown>;
markdownPlugins?: Array<() => void>;
scripts?: Array<{src: string; [key: string]: any} | string>;
stylesheets?: Array<{href: string; [key: string]: any} | string>;
facebookAppId?: string;
facebookComments?: true;
facebookPixelId?: string;
twitter?: string;
twitterUsername?: string;
twitterImage?: string;
ogImage?: string;
cleanUrl?: boolean;
scrollToTop?: boolean;
scrollToTopOptions?: Record<string, unknown>;
};

View file

@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"rootDir": "src",
"outDir": "lib",
"typeRoots": [ "./external_types", "./node_modules/@types"]
}
}

View file

@ -4,6 +4,7 @@
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"rootDir": "src",
"outDir": "lib"
"outDir": "lib",
"typeRoots": [ "./types", "./node_modules/@types"]
}
}

View file

@ -5,10 +5,7 @@ authorURL: http://twitter.com/JoelMarcey
authorImageURL: https://graph.facebook.com/611217057/picture/?height=200&width=200
authorFBID: 611217057
authorTwitter: JoelMarcey
keywords:
- documentation
- blog
- docusaurus
tags: [documentation, blog, docusaurus]
---
![Introducing Slash](/img/slash-introducing.svg)

View file

@ -1,5 +1,5 @@
---
id: version-1.14.3-site-config
id: version-1.14.4-site-config
title: siteConfig.js
original_id: site-config
---

View file

@ -1,5 +1,5 @@
---
id: version-1.14.3-translation
id: version-1.14.4-translation
title: Translations & Localization
original_id: translation
---

View file

@ -226,31 +226,31 @@ Now, whenever a new commit lands in `master`, Travis CI will run your suite of t
```yaml title="azure-pipelines.yml"
trigger:
- master
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- checkout: self
persistCredentials: true
- checkout: self
persistCredentials: true
- task: NodeTool@0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
- task: NodeTool@0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
- script: |
git config --global user.name "${GH_NAME}"
git config --global user.email "${GH_EMAIL}"
git checkout -b master
echo "machine github.com login ${GH_NAME} password ${GH_TOKEN}" > ~/.netrc
yarn && GIT_USER="${GH_NAME}" yarn deploy
env:
GH_NAME: $(GH_NAME)
GH_EMAIL: $(GH_EMAIL)
GH_TOKEN: $(GH_TOKEN)
displayName: 'yarn install and build'
- script: |
git config --global user.name "${GH_NAME}"
git config --global user.email "${GH_EMAIL}"
git checkout -b master
echo "machine github.com login ${GH_NAME} password ${GH_TOKEN}" > ~/.netrc
yarn && GIT_USER="${GH_NAME}" yarn deploy
env:
GH_NAME: $(GH_NAME)
GH_EMAIL: $(GH_EMAIL)
GH_TOKEN: $(GH_TOKEN)
displayName: 'yarn install and build'
```
## Deploying to Netlify

2754
yarn.lock

File diff suppressed because it is too large Load diff