Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

facilitate watching changes from another project #56

Merged
merged 3 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.local.default
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LINKED_PROJECT_PATH = "/path/to/project/linking/chessground"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules/
dist/

.env.local
48 changes: 37 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,40 +88,66 @@ More? Please make a pull request to include it here.

## Development

Install build dependencies:
Commands are listed in package.json.
In case you want to see the possibilities from the console, run `pnpm run`

### Install build dependencies:s

```sh
pnpm install
```

Update deps:
### Update deps:

```sh
rm -rf node_modules pnpm-lock.yaml && pnpm store prune && pnpm install
```

Build the node module:
### Build the node module:

```sh
pnpm prepare --watch
```

Build the minified bundled dist files:

```sh
pnpm dist
```

run tests:
### Run tests:

```sh
pnpm run test --watch
pnpm run test fen --watch
```

Before committing:
### Before committing:

```sh
pnpm run lint
pnpm run format
```

### Watch chessground changes from another project:

In other project:

- declare the link towards chessground (from project's `package.json`)

```json
"dependencies": {
...
"chessground": "link:/path/to/chessground",
...
}
```

In chessground:

- create `.env.local` file based on .env.local.default
- link back:

```sh
pnpm run link
```

- trigger compilation and generate minified file:

```sh
pnpm run local-dist
```
30 changes: 30 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as cps from 'node:child_process';

const red = '\x1b[31m%s\x1b[0m';
const green = '\x1b[32m%s\x1b[0m';
const cyan = '\x1b[36m%s\x1b[0m';

const linkedProject = process.env.LINKED_PROJECT_PATH;
if (!linkedProject) {
console.error(red, 'LINKED_PROJECT not set');
process.exit(1);
}
const args = process.argv.slice(2);

if (args.length === 0) {
console.error(red, 'No arguments provided');
process.exit(1);
}

if (args.includes('--link')) {
cps.execSync(`pnpm link --dir ${linkedProject}`, { stdio: 'inherit' });
console.log(cyan, `ready to be linked from ${linkedProject}.`);
}

if (args.includes('--bundle')) {
cps.execSync(
`esbuild src/chessground.ts --bundle --format=esm --outfile=${linkedProject}/node_modules/chessground/dist/chessground.min.js`,
{ stdio: 'inherit' },
);
console.log(green, `compiled and built ${linkedProject}/node_modules/chessground/dist/chessground.min.js`);
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
"check-format": "prettier --check .",
"bundle": "esbuild src/chessground.ts --bundle --format=esm --outfile=dist/chessground.min.js --minify",
"dist": "$npm_execpath run compile && $npm_execpath run bundle",
"link": "node --env-file=.env.local ./build.js --link",
"local-bundle": "node --env-file=.env.local ./build.js --bundle",
"local-dist": "$npm_execpath run compile && $npm_execpath run local-bundle",
"postinstall": "$npm_execpath run bundle"
},
"files": [
Expand Down
Loading