Skip to content

Commit 4642b34

Browse files
committed
Add examples section to README.md
1 parent b4185cc commit 4642b34

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ console.log(require('cross-dirname')() === __dirname) // true
3838

3939
```ts
4040
// /path/to/the/script.ts
41-
import { dirname } from 'https://deno.land/x/[email protected]/mod.ts';
41+
import dirname from 'https://deno.land/x/[email protected]/mod.ts';
4242
console.log(dirname()); // outputs "/path/to/the"
4343
```
4444

@@ -62,6 +62,29 @@ node esbuild.mjs
6262
gjs -m index.js
6363
```
6464

65+
### Examples
66+
67+
You can run the examples with
68+
69+
```bash
70+
71+
npm install
72+
npm run build
73+
74+
deno run ./examples/deno/index.ts
75+
# -> /.../examples/deno
76+
77+
node ./examples/node/index.cjs
78+
# -> /.../examples/node
79+
80+
node ./examples/node/index.mjs
81+
# -> /.../examples/node
82+
83+
node ./examples/gjs/esbuild.mjs
84+
gjs -m ./examples/gjs/index.js
85+
# -> /.../examples/gjs
86+
```
87+
6588
### Contributions
6689

6790
Contributions for more platforms are welcome :)

examples/deno/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#! /usr/bin/env -S deno run
2-
import { dirname } from 'https://deno.land/x/[email protected]/mod.ts';
2+
import dirname from 'https://deno.land/x/[email protected]/mod.ts';
33
console.log(dirname()); // outputs "/path/to/the"

examples/gjs/esbuild.mjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#! /usr/bin/env node
22
import { build } from "esbuild";
3-
import dirname from "../../dist/esm/index.mjs";
3+
import dirname from "cross-dirname";
4+
const __dirname = dirname();
45

56
await build({
6-
entryPoints: ['./src/index.js'],
7-
outdir: dirname(),
7+
entryPoints: [__dirname + '/src/index.js'],
8+
outdir: __dirname,
89
bundle: true,
910
// target: "firefox60", // Since GJS 1.53.90
1011
// target: "firefox68", // Since GJS 1.63.90

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
},
4343
"devDependencies": {
4444
"chai": "^4.3.6",
45+
"cross-dirname": "^0.0.3",
4546
"esbuild": "^0.14.49",
4647
"esm": "^3.2.25",
4748
"mocha": "^10.0.0",

0 commit comments

Comments
 (0)