Skip to content

Commit

Permalink
Removed pagefind as a dep, now just using the CLI installed by the en…
Browse files Browse the repository at this point in the history
…d user
  • Loading branch information
Hugos68 committed Feb 1, 2024
1 parent eccd97a commit f1427a7
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 135 deletions.
5 changes: 5 additions & 0 deletions .changeset/sour-tips-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vite-plugin-pagefind": patch
---

Cleaned up some internals
58 changes: 29 additions & 29 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,147 +4,147 @@

### Patch Changes

- 19ca67b: Fixed executeMeasured return time (start - stop should be stop - start)
- 19ca67b: Fixed executeMeasured return time (start - stop should be stop - start)

## 0.0.24

### Patch Changes

- 720dbb8: Removed the automatic pagefind run on post build in favor of manually doing so to be framework agnostic (some frameworks have their own CLI wrappers around Vite so it was impossible to run post build since the framework ran after `vite build` had completed.
- 720dbb8: Removed the automatic pagefind run on post build in favor of manually doing so to be framework agnostic (some frameworks have their own CLI wrappers around Vite so it was impossible to run post build since the framework ran after `vite build` had completed.

## 0.0.23

### Patch Changes

- d8de3ba: Graph improvements
- d8de3ba: Graph improvements

## 0.0.22

### Patch Changes

- 7aafe6b: Added flow chart to showcase what pagefind does
- 7aafe6b: Added flow chart to showcase what pagefind does

## 0.0.21

### Patch Changes

- 74aed9c: Added Astro example :tada:
- 74aed9c: Added Astro example :tada:

## 0.0.20

### Patch Changes

- ce7ba7a: Docs cleanup and default empty object fix
- ce7ba7a: Docs cleanup and default empty object fix

## 0.0.19

### Patch Changes

- 396c975: Added @antfu/ni in order to detect package and allow for more flexible build process (rather than harcoding `vite build`
- 396c975: Added @antfu/ni in order to detect package and allow for more flexible build process (rather than harcoding `vite build`

## 0.0.18

### Patch Changes

- 6da3d09: Minor doc changes
- 6da3d09: Minor doc changes

## 0.0.17

### Patch Changes

- dfde5a4: Added examples folder, added SvelteKit
- dfde5a4: Added examples folder, added SvelteKit

## 0.0.16

### Patch Changes

- e1cbe1f: Fixed dynamic imports being due to faulty vite configuration
- e1cbe1f: Fixed dynamic imports being due to faulty vite configuration

## 0.0.15

### Patch Changes

- 6bb27bc: Fixed nested pagefind dir
- 6bb27bc: Fixed nested pagefind dir

## 0.0.14

### Patch Changes

- 3759d12: Removed testing console.log
- 3759d12: Removed testing console.log

## 0.0.13

### Patch Changes

- a9d0e41: Removed prerequisites from docs since the plugin will handle pagefind through the node API
- a9d0e41: Removed prerequisites from docs since the plugin will handle pagefind through the node API

## 0.0.12

### Patch Changes

- e08ff34: Cleaned up docs, renamed appDir to publicDir (makes more sense with vite), added LICENSE
- b974483: Fixed docs
- e08ff34: Cleaned up docs, renamed appDir to publicDir (makes more sense with vite), added LICENSE
- b974483: Fixed docs

## 0.0.11

### Patch Changes

- 692518a: Added assetsInclude config and external config to make usage of pagefind FAR easier
- 692518a: Added assetsInclude config and external config to make usage of pagefind FAR easier

## 0.0.10

### Patch Changes

- cf9d8a7: Forced buildDir to be present
- 9f91f77: Fixed buildDir being optional type
- cf9d8a7: Forced buildDir to be present
- 9f91f77: Fixed buildDir being optional type

## 0.0.9

### Patch Changes

- 1dc1751: Renamed pagefindDir to appDir and removed the need to specify the `pagefind` folder
- 1dc1751: Added documentation (see README.md)
- 1dc1751: Renamed pagefindDir to appDir and removed the need to specify the `pagefind` folder
- 1dc1751: Added documentation (see README.md)

## 0.0.8

### Patch Changes

- bd97d3d: Finally fixed running pagefind after build
- fcf32c0: Fixed broken vite dependency: https://github.com/vitejs/vite/issues/15714
- bd97d3d: Finally fixed running pagefind after build
- fcf32c0: Fixed broken vite dependency: https://github.com/vitejs/vite/issues/15714

## 0.0.7

### Patch Changes

- 9bdcc49: Fixed pagefind post build not running after the build process
- 9bdcc49: Fixed pagefind post build not running after the build process

## 0.0.6

### Patch Changes

- d911925: Fixed hardcoded buildDir
- 324852e: Added quotes around paths for pagefind to prevent invalid paths from occuring
- d911925: Fixed hardcoded buildDir
- 324852e: Added quotes around paths for pagefind to prevent invalid paths from occuring

## 0.0.5

### Patch Changes

- 04163e9: Added cwd option that defaults to process.cwd, added default to buildDir: build
- 04163e9: Added cwd option that defaults to process.cwd, added default to buildDir: build

## 0.0.4

### Patch Changes

- 93731cd: Bugfix: Had colorette as devDep causing issues with the plugin
- 93731cd: Bugfix: Had colorette as devDep causing issues with the plugin

## 0.0.3

### Patch Changes

- 2f8a075: Only packaging dist files now
- 2f8a075: Only packaging dist files now

## 0.0.2

### Patch Changes

- a969687: Released package
- a969687: Released package
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Note: If your framework does not have a `vite.config` checkout the [examples](#e
}
```

Note: replace `<BUILD_DIR>` with your build directory.
Note: Replace `<BUILD_DIR>` with your build directory.

## Config

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
},
"dependencies": {
"@antfu/ni": "^0.21.12",
"colorette": "^2.0.20",
"pagefind": "^1.0.4"
"colorette": "^2.0.20"
},
"type": "module",
"keywords": [
Expand Down
72 changes: 0 additions & 72 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 20 additions & 31 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
import type { PluginOption } from 'vite';
import { build, type PluginOption } from 'vite';
import { join } from 'path';
import { existsSync } from 'fs';
import { execSync } from 'child_process';
import { performance } from 'perf_hooks';
import { blue, bold } from 'colorette';
import { detect, getCommand } from '@antfu/ni';
import * as pagefind from 'pagefind';

type PagefindPluginConfig = {
publicDir?: string;
buildDir?: string;
buildScript?: string;
};

type PagefindDevPluginConfig = {
publicDir: string;
buildDir: string;
buildScript: string;
};

function log(input: string) {
console.log(`${blue('[vite-plugin-pagefind]')} ${bold(input)}`);
}
Expand All @@ -42,7 +35,7 @@ function pagefindDevPlugin({
publicDir,
buildDir,
buildScript
}: PagefindDevPluginConfig): PluginOption {
}: Required<PagefindPluginConfig>): PluginOption {
return {
name: 'pagefind-dev',
apply: 'serve',
Expand All @@ -57,29 +50,25 @@ function pagefindDevPlugin({
};
},
async configureServer() {
if (!existsSync(join(publicDir, 'pagefind'))) {
log('Pagefind not found.');
if (!existsSync(join(buildDir, 'pagefind'))) {
const buildCommand = await getBuildCommand(buildScript);
log(`Build not found, running "${buildCommand}".`);
const time = await executeMeasured(() =>
execSync(buildCommand)
);
log(`Build completed in ${millisToSeconds(time)}.`);
}
log('Running pagefind...');
const time = await executeMeasured(async () => {
const { index } = await pagefind.createIndex({});
await index.addDirectory({
path: buildDir
});
await index.writeFiles({
outputPath: join(publicDir, 'pagefind')
});
await pagefind.close();
});
log(`Pagefind completed in ${millisToSeconds(time)}.`);
if (existsSync(join(publicDir, 'pagefind'))) {
return;
}
log('Pagefind not found.');
if (!existsSync(join(buildDir, 'pagefind'))) {
const buildCommand = await getBuildCommand(buildScript);
log(`Build not found, running "${buildCommand}".`);
const time = await executeMeasured(() =>
execSync(buildCommand)
);
log(`Build completed in ${millisToSeconds(time)}.`);
}
log('Running pagefind...');
const time = await executeMeasured(() =>
execSync(
`pagefind --site ${buildDir} --output-path ${publicDir}`
)
);
log(`Pagefind completed in ${millisToSeconds(time)}.`);
}
};
}
Expand Down

0 comments on commit f1427a7

Please sign in to comment.