Skip to content

Commit 089677d

Browse files
committed
Move docusaurus to TypeScript
1 parent 920008a commit 089677d

6 files changed

Lines changed: 82 additions & 27 deletions

File tree

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
module.exports = {
1+
import { themes as prismThemes } from 'prism-react-renderer';
2+
import type { Config } from '@docusaurus/types';
3+
import type { Options as ClassicPresetOptions } from '@docusaurus/preset-classic';
4+
5+
const config: Config = {
26
title: 'CashScript',
37
tagline: 'Smart contracts for Bitcoin Cash',
48
url: 'https://cashscript.org',
@@ -8,8 +12,8 @@ module.exports = {
812
projectName: 'cashscript',
913
themeConfig: {
1014
prism: {
11-
theme: require('prism-react-renderer').themes.nightOwlLight,
12-
darkTheme: require('prism-react-renderer').themes.nightOwl,
15+
theme: prismThemes.nightOwlLight,
16+
darkTheme: prismThemes.nightOwl,
1317
additionalLanguages: ['solidity', 'antlr4'],
1418
},
1519
image: 'img/logo.svg',
@@ -19,7 +23,7 @@ module.exports = {
1923
src: 'img/logo.svg',
2024
},
2125
items: [
22-
{to: '/docs/basics/about', label: 'Docs', position: 'right'},
26+
{ to: '/docs/basics/about', label: 'Docs', position: 'right' },
2327
{
2428
href: 'https://playground.cashscript.org',
2529
label: 'Playground',
@@ -99,15 +103,15 @@ module.exports = {
99103
},
100104
presets: [
101105
[
102-
'@docusaurus/preset-classic',
106+
'classic',
103107
{
104108
theme: {
105-
customCss: require.resolve('./src/css/custom.css'),
109+
customCss: './src/css/custom.css',
106110
},
107111
docs: {
108-
sidebarPath: './sidebars.js',
112+
sidebarPath: './sidebars.ts',
109113
},
110-
},
114+
} as ClassicPresetOptions,
111115
],
112116
],
113117
plugins: [
@@ -116,7 +120,7 @@ module.exports = {
116120
{
117121
fromExtensions: ['html'],
118122
redirects: [
119-
{ from: ['/docs', '/docs/about', '/docs/basics'], to: '/docs/basics/about'},
123+
{ from: ['/docs', '/docs/about', '/docs/basics'], to: '/docs/basics/about' },
120124
{ from: '/docs/language', to: '/docs/language/contracts' },
121125
{ from: '/docs/sdk', to: '/docs/sdk/instantiation' },
122126
{ from: '/docs/sdk/transactions-advanced', to: '/docs/sdk/transaction-builder' },
@@ -130,3 +134,5 @@ module.exports = {
130134
['@branchup/docusaurus-plugin-simple-analytics', {}],
131135
],
132136
};
137+
138+
export default config;

website/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"deploy": "docusaurus deploy"
1010
},
1111
"dependencies": {
12-
"@babel/helper-get-function-arity": "^7.16.7",
1312
"@branchup/docusaurus-plugin-simple-analytics": "^1.1.0",
1413
"@docusaurus/core": "^3.9.2",
1514
"@docusaurus/plugin-client-redirects": "^3.9.2",
@@ -19,6 +18,10 @@
1918
"react": "^19.2.3",
2019
"react-dom": "^19.2.3"
2120
},
21+
"devDependencies": {
22+
"@docusaurus/tsconfig": "^3.9.2",
23+
"typescript": "^5.9.2"
24+
},
2225
"browserslist": {
2326
"production": [
2427
">0.2%",
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
module.exports = {
1+
import type { SidebarsConfig } from '@docusaurus/plugin-content-docs';
2+
3+
const sidebars: SidebarsConfig = {
24
docs: [
35
{
46
type: 'category',
@@ -76,3 +78,5 @@ module.exports = {
7678
'showcase',
7779
],
7880
};
81+
82+
export default sidebars;
Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
66
import useBaseUrl from '@docusaurus/useBaseUrl';
77
import styles from './index.module.css';
88

9-
const features = [
9+
type FeatureItem = {
10+
title: string;
11+
description: React.ReactNode;
12+
imageUrl?: string;
13+
};
14+
15+
const features: FeatureItem[] = [
1016
{
1117
title: 'TypeScript SDK',
1218
description: (
@@ -47,8 +53,8 @@ const features = [
4753
},
4854
];
4955

50-
function Feature({imageUrl, title, description}) {
51-
const imgUrl = useBaseUrl(imageUrl);
56+
function Feature({ imageUrl, title, description }: FeatureItem) {
57+
const imgUrl = imageUrl ? useBaseUrl(imageUrl) : undefined;
5258
return (
5359
<div className={classnames('col col--6', styles.feature)}>
5460
{imgUrl && (
@@ -62,14 +68,13 @@ function Feature({imageUrl, title, description}) {
6268
);
6369
}
6470

65-
function Home() {
71+
function Home(): React.ReactNode {
6672
const context = useDocusaurusContext();
67-
const {siteConfig = {}} = context;
73+
const { siteConfig } = context;
6874
return (
6975
<Layout
7076
title={`${siteConfig.title}: ${siteConfig.tagline}`}
71-
description='A high-level smart contract language for Bitcoin Cash. Write complex smart contracts with a straightforward syntax and integrate them into your JavaScript applications.'
72-
keywords={['cashscript','smart contracts','bitcoin cash', 'compiler', 'sdk', 'programming language']}>
77+
description='A high-level smart contract language for Bitcoin Cash. Write complex smart contracts with a straightforward syntax and integrate them into your JavaScript applications.'>
7378
<header className={classnames('hero', styles.banner)}>
7479
<div className='container'>
7580
<div className='row'>
@@ -99,7 +104,7 @@ function Home() {
99104
</div>
100105
</header>
101106
<main>
102-
{features && features.length && (
107+
{features && features.length > 0 && (
103108
<section className={styles.features}>
104109
<div className='container margin-vert--md'>
105110
<div className='row'>

website/tsconfig.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"extends": "@docusaurus/tsconfig",
3+
"compilerOptions": {
4+
"target": "es2020",
5+
"lib": [
6+
"dom",
7+
"dom.iterable",
8+
"esnext",
9+
"es2021"
10+
],
11+
"allowJs": true,
12+
"skipLibCheck": true,
13+
"strict": true,
14+
"esModuleInterop": true,
15+
"forceConsistentCasingInFileNames": true,
16+
"allowSyntheticDefaultImports": true,
17+
"module": "esnext",
18+
"moduleResolution": "node",
19+
"resolveJsonModule": true,
20+
"isolatedModules": true,
21+
"noEmit": true,
22+
"jsx": "react-jsx",
23+
"baseUrl": ".",
24+
},
25+
"include": [
26+
"**/*.ts",
27+
"**/*.tsx",
28+
"**/*.js",
29+
"**/*.jsx",
30+
],
31+
"exclude": [
32+
"**/node_modules"
33+
]
34+
}

website/yarn.lock

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -307,13 +307,6 @@
307307
lodash.debounce "^4.0.8"
308308
resolve "^1.22.10"
309309

310-
"@babel/helper-get-function-arity@^7.16.7":
311-
version "7.16.7"
312-
resolved "https://registry.yarnpkg.com/@babel/helper-get-function-arity/-/helper-get-function-arity-7.16.7.tgz#ea08ac753117a669f1508ba06ebcc49156387419"
313-
integrity sha512-flc+RLSOBXzNzVhcLu6ujeHUrD6tANAOU5ojrRx/as+tbzf8+stUCj7+IfRRoAbEZqj/ahXEMsjhOhgeZsrnTw==
314-
dependencies:
315-
"@babel/types" "^7.16.7"
316-
317310
"@babel/helper-globals@^7.28.0":
318311
version "7.28.0"
319312
resolved "https://registry.yarnpkg.com/@babel/helper-globals/-/helper-globals-7.28.0.tgz#b9430df2aa4e17bc28665eadeae8aa1d985e6674"
@@ -1138,7 +1131,7 @@
11381131
"@babel/types" "^7.28.5"
11391132
debug "^4.3.1"
11401133

1141-
"@babel/types@^7.12.7", "@babel/types@^7.16.7", "@babel/types@^7.20.0", "@babel/types@^7.21.3", "@babel/types@^7.27.1", "@babel/types@^7.27.3", "@babel/types@^7.28.2", "@babel/types@^7.28.4", "@babel/types@^7.28.5", "@babel/types@^7.4.4":
1134+
"@babel/types@^7.12.7", "@babel/types@^7.20.0", "@babel/types@^7.21.3", "@babel/types@^7.27.1", "@babel/types@^7.27.3", "@babel/types@^7.28.2", "@babel/types@^7.28.4", "@babel/types@^7.28.5", "@babel/types@^7.4.4":
11421135
version "7.28.5"
11431136
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.28.5.tgz#10fc405f60897c35f07e85493c932c7b5ca0592b"
11441137
integrity sha512-qQ5m48eI/MFLQ5PxQj4PFaprjyCTLI37ElWMmNs0K8Lk3dVeOdNpB3ks8jc7yM5CDmVC73eMVk/trk3fgmrUpA==
@@ -2116,6 +2109,11 @@
21162109
fs-extra "^11.1.1"
21172110
tslib "^2.6.0"
21182111

2112+
"@docusaurus/tsconfig@^3.9.2":
2113+
version "3.9.2"
2114+
resolved "https://registry.yarnpkg.com/@docusaurus/tsconfig/-/tsconfig-3.9.2.tgz#7f440e0ae665b841e1d487749037f26a0275f9c1"
2115+
integrity sha512-j6/Fp4Rlpxsc632cnRnl5HpOWeb6ZKssDj6/XzzAzVGXXfm9Eptx3rxCC+fDzySn9fHTS+CWJjPineCR1bB5WQ==
2116+
21192117
"@docusaurus/types@2.1.0":
21202118
version "2.1.0"
21212119
resolved "https://registry.yarnpkg.com/@docusaurus/types/-/types-2.1.0.tgz#01e13cd9adb268fffe87b49eb90302d5dc3edd6b"
@@ -10432,6 +10430,11 @@ typescript@^4.8.4:
1043210430
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a"
1043310431
integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==
1043410432

10433+
typescript@^5.9.2:
10434+
version "5.9.3"
10435+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.9.3.tgz#5b4f59e15310ab17a216f5d6cf53ee476ede670f"
10436+
integrity sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==
10437+
1043510438
undici-types@~7.16.0:
1043610439
version "7.16.0"
1043710440
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-7.16.0.tgz#ffccdff36aea4884cbfce9a750a0580224f58a46"

0 commit comments

Comments
 (0)