Skip to content

Commit

Permalink
bundle website db on build time (nuxt#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored Nov 12, 2021
1 parent d0cd20e commit 093f6ec
Show file tree
Hide file tree
Showing 17 changed files with 10,187 additions and 11,753 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ jobs:
run: |
echo "//registry.npmjs.org/:_authToken=$NPM_AUTH_TOKEN" >> ~/.npmrc
echo "//registry.yarnpkg.com/:_authToken=$NPM_AUTH_TOKEN" >> ~/.npmrc
yarn release || true
yarn release
env:
NPM_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ sw.js
cache
.vercel_build_output
.output
package-lock.json
package-lock.json
npm/modules.json
20 changes: 3 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Metadata of nuxt modules are maintained in [yml](https://en.wikipedia.org/wiki/Y

Compiled JSON data is available from following CDNs:

- **jsdelivr:**: https://cdn.jsdelivr.net/npm/@nuxt/modules@latest/dist/modules.json
- **unpkg:** https://unpkg.com/@nuxt/modules@latest/dist/modules.json
- **jsdelivr:**: https://cdn.jsdelivr.net/npm/@nuxt/modules@latest/modules.json
- **unpkg:** https://unpkg.com/@nuxt/modules@latest/modules.json

### Using npm package

Expand Down Expand Up @@ -81,7 +81,7 @@ To sync with a branch different than `master`, suffix the repo with `#repo-branc
yarn sync
```

### Generate `dist/module.json`
### Generate `npm/modules.json`

```sh
yarn build
Expand All @@ -90,7 +90,6 @@ yarn build
## Website development

- Clone repository
- Change working directory to website using `cd website`
- Install website depenedencies using `npx yarn install`

Start development:
Expand All @@ -103,19 +102,6 @@ Then visit http://localhost:3000

In the development, the npm downloads and GitHub stars will be mocked unless setting `USE_NUXT_API` variable.

### Production build


```sh
yarn build
```

Start the production website:

```sh
yarn start
```

## License

[MIT](./LICENSE) - Made by Nuxt Team
File renamed without changes.
6 changes: 6 additions & 0 deletions npm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@nuxt/modules",
"version": "0.5.0",
"license": "MIT",
"main": "./modules.json"
}
15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
{
"name": "@nuxt/modules",
"version": "0.5.0",
"license": "MIT",
"main": "dist/modules.json",
"files": [
"dist"
"private": true,
"workspaces": [
"npm",
"website"
],
"scripts": {
"build": "yarn sync && yarn cli build",
"build": "yarn cli build",
"cli": "jiti ./scripts/cli",
"dev": "cd website && yarn dev",
"lint": "eslint --ext .vue,.ts .",
"release": "yarn cli version && npm publish",
"release": "yarn cli version && cd npm && npm publish",
"sync": "yarn cli sync",
"test": "yarn lint && yarn sync"
},
Expand Down
2 changes: 1 addition & 1 deletion scripts/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as yml from 'js-yaml'
import { globby } from 'globby'
import defu from 'defu'
import { $fetch } from 'ohmyfetch'
import categories from '../lib/categories.json'
import categories from '../npm/categories.json'
import { fetchGithubPkg, modulesDir, distDir, distFile } from './utils'

export async function sync (name, repo?: string, isNew: boolean = false) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { resolve } from 'path'
import { $fetch } from 'ohmyfetch'
export const rootDir = resolve(__dirname, '..')
export const modulesDir = resolve(rootDir, 'modules')
export const distDir = resolve(rootDir, 'dist')
export const distDir = resolve(rootDir, 'npm')
export const distFile = resolve(distDir, 'modules.json')

export function fetchPKG (name) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { build } from './modules'
export async function version () {
await build()

const pkgFile = path.resolve(rootDir, 'package.json')
const pkgFile = path.resolve(rootDir, 'npm/package.json')
const pkg = JSON.parse(await fsp.readFile(pkgFile, 'utf8'))

const hash = hasha(await fsp.readFile(distFile, 'utf8')).substr(0, 6)
Expand Down
17 changes: 8 additions & 9 deletions website/components/TheSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,22 @@
</div>
<slot />
<button aria-label="Toggle theme" class="!outline-none" @click="toggleDarkMode()">
<IconMoon v-if="$colorMode.value === 'dark'" />
<IconSun v-else-if="$colorMode.value === 'light'" />
<IconMoon v-if="$colorMode.preference === 'dark'" />
<IconSun v-else-if="$colorMode.preference === 'light'" />
<IconSystem v-else aria-label="System theme" />
</button>
</div>
</template>
<script>
const toggleNext = {
system: 'dark', // TODO
dark: 'light',
light: 'dark'
}
export default {
methods: {
toggleDarkMode () {
if (this.$colorMode.preference === 'system') {
this.$colorMode.preference = 'dark'
} else if (this.$colorMode.preference === 'dark') {
this.$colorMode.preference = 'light'
} else {
this.$colorMode.preference = 'system'
}
this.$colorMode.preference = toggleNext[this.$colorMode.preference] || 'system'
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions website/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
"private": true,
"name": "nuxt-modules-website",
"version": "0.0.0",
"scripts": {
"build": "nuxi build",
"dev": "nuxi dev",
"build": "yarn build:npm && nuxi build",
"dev": "yarn build:npm && nuxi dev",
"build:npm": "cd .. && yarn build",
"start": "node .output/server/index.mjs"
},
"resolutions": {
Expand All @@ -11,14 +14,12 @@
},
"devDependencies": {
"@nuxt/bridge": "npm:@nuxt/bridge-edge",
"@nuxt/image": "^0.6.0",
"@nuxt/kit-edge": "npm:@nuxt/kit-edge@latest",
"@nuxtjs/color-mode": "^2.1.1",
"@nuxtjs/google-fonts": "^1.3.0",
"@nuxtjs/html-validator": "^0.6.0",
"@nuxtjs/pwa": "^3.3.5",
"fuse.js": "^6.4.6",
"ipx": "^0.9.1",
"millify": "^4.0.0",
"nuxt-edge": "^2.16.0-27277936.ab1c6cb4",
"nuxt-windicss": "^2.0.12",
Expand Down
2 changes: 1 addition & 1 deletion website/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ export default {
}
},
focusSearchInput () {
this.$refs.searchModule.focus()
this.$refs.searchModule?.focus()
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions website/server/api/categories.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

const modulesCDN = 'https://cdn.jsdelivr.net/gh/nuxt/modules@main/lib/categories.json'

export default async () => {
const categories = await $fetch(modulesCDN) as any[]
const categories = await import('../../../npm/categories.json').then(r => r.default || r)
return {
categories
}
Expand Down
3 changes: 1 addition & 2 deletions website/server/api/modules.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const modulesCDN = 'https://cdn.jsdelivr.net/npm/@nuxt/modules@latest/dist/modules.json'

export default async () => {
const _modules = await $fetch(modulesCDN) as any[]
const _modules = await import('../../../npm/modules.json').then(r => r.default || r)
const modules = await Promise.all(_modules.map(module => fetchModuleStats(module)))
return {
modules
Expand Down
5 changes: 1 addition & 4 deletions website/server/middleware/swr.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
export default (req, res, next) => {
if (req.method.toUpperCase() !== 'GET') {
return next()
}
export default (_req, res, next) => {
res.setHeader('Cache-Control', 's-maxage=600, stale-while-revalidate')
next()
}
Loading

0 comments on commit 093f6ec

Please sign in to comment.