Skip to content

Commit 209dac5

Browse files
committed
feat: cwd option for server-side
1 parent 09f3f0b commit 209dac5

6 files changed

Lines changed: 10 additions & 10 deletions

File tree

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

packages/pdfeasy/scripts/generate/simple-pdf.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import pdfeasy from '../../dist/node.esm.js'
2-
import path from 'path'
3-
import process from 'process'
42

53
pdfeasy.new({
64
exports: {
@@ -13,7 +11,7 @@ pdfeasy.add([{ raw: 'A simple pdf!', text: {} }])
1311
pdfeasy
1412
.run({
1513
type: 'server',
16-
serverPath: path.resolve(process.cwd() + '/examples'),
14+
serverPath: '/examples',
1715
})
1816
.then(() => {
1917
console.log('simple-pdf.js ready!')

packages/pdfeasy/scripts/generate/using-external-font-pdf.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import pdfeasy from '../../dist/node.esm.js'
2-
import path from 'path'
3-
import process from 'process'
42

53
pdfeasy.new({
64
exports: {
@@ -26,7 +24,7 @@ pdfeasy.addFonts([
2624
pdfeasy
2725
.run({
2826
type: 'server',
29-
serverPath: path.resolve(process.cwd() + '/examples'),
27+
serverPath: '/examples',
3028
})
3129
.then(() => {
3230
console.log('using-external-font-pdf.js ready!')

packages/pdfeasy/src/runner/pdfeasy.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,8 @@ export default class {
310310
if (runType && options?.serverPath) {
311311
this.pdfkit?.pipe(
312312
createWriteStream(
313-
path.resolve(
314-
options.serverPath +
315-
`/${this.options?.exports?.name || 'New PDF'}.pdf`
316-
)
313+
path.resolve((options?.cwd || process.cwd()) + options.serverPath) +
314+
`/${this.options?.exports?.name || 'New PDF'}.pdf`
317315
)
318316
)
319317

packages/pdfeasy/src/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,4 +311,10 @@ export interface RunOptions {
311311
* @default 'rgb'
312312
*/
313313
colorSchema?: ColorSchema
314+
/**
315+
* CWD for Server-Side Setup
316+
*
317+
* @default 'process.cwd()'
318+
*/
319+
cwd?: ColorSchema
314320
}

0 commit comments

Comments
 (0)