create-pdf-forge 1.0.0-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/LICENSE.md +8 -0
- package/package.json +39 -0
- package/src/index.js +104 -0
- package/template/README.md +63 -0
- package/template/package.json +21 -0
- package/template/templates/welcome.tsx +107 -0
- package/tsconfig.json +12 -0
package/CHANGELOG.md
ADDED
package/LICENSE.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Copyright 2024 Plus Five Five, Inc
|
|
2
|
+
Copyright 2025 ahmedrowaihi (fork modifications)
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
5
|
+
|
|
6
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-pdf-forge",
|
|
3
|
+
"version": "1.0.0-canary.0",
|
|
4
|
+
"description": "The easiest way to get started with React PDF",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"commander": "^13.0.0",
|
|
10
|
+
"fs-extra": "^11.1.1",
|
|
11
|
+
"log-symbols": "^7.0.0",
|
|
12
|
+
"ora": "^8.0.0"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/ahmedrowaihi/react-pdf-forge.git",
|
|
17
|
+
"directory": "packages/create-pdf"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"react",
|
|
21
|
+
"pdf"
|
|
22
|
+
],
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=20.0.0"
|
|
25
|
+
},
|
|
26
|
+
"bin": {
|
|
27
|
+
"create-pdf-forge": "src/index.js"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"nypm": "0.6.0",
|
|
31
|
+
"react": "^19",
|
|
32
|
+
"typescript": "5.8.3",
|
|
33
|
+
"@ahmedrowaihi/pdf-forge-components": "1.0.0-canary.0",
|
|
34
|
+
"tsconfig": "1.0.0-canary.0"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"test": "vitest run"
|
|
38
|
+
}
|
|
39
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { Command } from 'commander';
|
|
6
|
+
import fse from 'fs-extra';
|
|
7
|
+
import logSymbols from 'log-symbols';
|
|
8
|
+
import ora from 'ora';
|
|
9
|
+
import { tree } from './tree.js';
|
|
10
|
+
|
|
11
|
+
const filename = fileURLToPath(import.meta.url);
|
|
12
|
+
const dirname = path.dirname(filename);
|
|
13
|
+
|
|
14
|
+
const packageJson = JSON.parse(
|
|
15
|
+
fse.readFileSync(path.resolve(dirname, '../package.json'), 'utf8'),
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
const getLatestVersionOfTag = async (packageName, tag) => {
|
|
19
|
+
const response = await fetch(
|
|
20
|
+
`https://registry.npmjs.org/${packageName}/${tag}`,
|
|
21
|
+
);
|
|
22
|
+
const data = await response.json();
|
|
23
|
+
|
|
24
|
+
if (typeof data === 'string' && data.startsWith('version not found')) {
|
|
25
|
+
console.error(`Tag ${tag} does not exist for ${packageName}.`);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const { version } = data;
|
|
30
|
+
|
|
31
|
+
if (!/^\d+\.\d+\.\d+.*$/.test(version)) {
|
|
32
|
+
console.error('Invalid version received, something has gone very wrong.');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return version;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const init = async (name, { tag }) => {
|
|
39
|
+
let projectPath = name;
|
|
40
|
+
|
|
41
|
+
if (!projectPath) {
|
|
42
|
+
projectPath = path.join(process.cwd(), 'react-pdf-starter');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (typeof projectPath === 'string') {
|
|
46
|
+
projectPath = projectPath.trim();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const templatePath = path.resolve(dirname, '../template');
|
|
50
|
+
const resolvedProjectPath = path.resolve(projectPath);
|
|
51
|
+
|
|
52
|
+
if (fse.existsSync(resolvedProjectPath)) {
|
|
53
|
+
console.error(`Project called ${projectPath} already exists!`);
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const spinner = ora({
|
|
58
|
+
text: 'Preparing files...\n',
|
|
59
|
+
}).start();
|
|
60
|
+
|
|
61
|
+
fse.copySync(templatePath, resolvedProjectPath, {
|
|
62
|
+
recursive: true,
|
|
63
|
+
});
|
|
64
|
+
const templatePackageJsonPath = path.resolve(
|
|
65
|
+
resolvedProjectPath,
|
|
66
|
+
'./package.json',
|
|
67
|
+
);
|
|
68
|
+
const templatePackageJson = fse.readFileSync(templatePackageJsonPath, 'utf8');
|
|
69
|
+
fse.writeFileSync(
|
|
70
|
+
templatePackageJsonPath,
|
|
71
|
+
templatePackageJson
|
|
72
|
+
.replace(
|
|
73
|
+
'INSERT_COMPONENTS_VERSION',
|
|
74
|
+
await getLatestVersionOfTag('@ahmedrowaihi/pdf-forge-components', tag),
|
|
75
|
+
)
|
|
76
|
+
.replaceAll(
|
|
77
|
+
'INSERT_REACT_PDF_VERSION',
|
|
78
|
+
await getLatestVersionOfTag('@ahmedrowaihi/pdf-forge-cli', tag),
|
|
79
|
+
),
|
|
80
|
+
'utf8',
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
spinner.stopAndPersist({
|
|
84
|
+
symbol: logSymbols.success,
|
|
85
|
+
text: 'React PDF Starter files ready',
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
console.info(
|
|
89
|
+
await tree(resolvedProjectPath, 4, (dirent) => {
|
|
90
|
+
return !path
|
|
91
|
+
.join(dirent.parentPath, dirent.name)
|
|
92
|
+
.includes('node_modules');
|
|
93
|
+
}),
|
|
94
|
+
);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
new Command()
|
|
98
|
+
.name(packageJson.name)
|
|
99
|
+
.version(packageJson.version)
|
|
100
|
+
.description('The easiest way to get started with React PDF')
|
|
101
|
+
.arguments('[dir]', 'Path to initialize the project')
|
|
102
|
+
.option('-t, --tag <tag>', 'Tag of React PDF versions to use', 'latest')
|
|
103
|
+
.action(init)
|
|
104
|
+
.parse(process.argv);
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# React PDF Starter
|
|
2
|
+
|
|
3
|
+
This is a starter template for React PDF Render.
|
|
4
|
+
|
|
5
|
+
## Getting Started
|
|
6
|
+
|
|
7
|
+
1. Install dependencies:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pnpm install
|
|
11
|
+
# or
|
|
12
|
+
npm install
|
|
13
|
+
# or
|
|
14
|
+
yarn install
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
2. Start the development server:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
pnpm dev
|
|
21
|
+
# or
|
|
22
|
+
npm run dev
|
|
23
|
+
# or
|
|
24
|
+
yarn dev
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
3. Open http://localhost:3000 in your browser
|
|
28
|
+
|
|
29
|
+
## Creating Templates
|
|
30
|
+
|
|
31
|
+
Add your PDF templates in the `templates/` directory. Each template should be a React component that exports a default function.
|
|
32
|
+
|
|
33
|
+
Example:
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
import { Document, Body } from '@ahmedrowaihi/pdf-forge-components';
|
|
37
|
+
|
|
38
|
+
export default function MyTemplate() {
|
|
39
|
+
return (
|
|
40
|
+
<Document>
|
|
41
|
+
<Body>
|
|
42
|
+
<h1>Hello World</h1>
|
|
43
|
+
</Body>
|
|
44
|
+
</Document>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Building Templates
|
|
50
|
+
|
|
51
|
+
To export all templates as HTML:
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
pnpm export
|
|
55
|
+
# or
|
|
56
|
+
npm run export
|
|
57
|
+
# or
|
|
58
|
+
yarn export
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Learn More
|
|
62
|
+
|
|
63
|
+
Visit [react-pdf-forge.com](https://react-pdf-forge.com) for documentation.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-pdf-forge-starter",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "pdf-dev build",
|
|
7
|
+
"dev": "pdf-dev dev",
|
|
8
|
+
"export": "pdf-dev export"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@ahmedrowaihi/pdf-forge-components": "INSERT_COMPONENTS_VERSION",
|
|
12
|
+
"react-dom": "^19",
|
|
13
|
+
"react": "^19"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@ahmedrowaihi/pdf-forge-preview": "INSERT_REACT_PDF_VERSION",
|
|
17
|
+
"@ahmedrowaihi/pdf-forge-cli": "INSERT_REACT_PDF_VERSION",
|
|
18
|
+
"@types/react": "^19",
|
|
19
|
+
"@types/react-dom": "^19"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { Body, Document } from '@ahmedrowaihi/pdf-forge-components';
|
|
2
|
+
|
|
3
|
+
export interface WelcomeProps {
|
|
4
|
+
name?: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function Welcome({ name = 'World' }: WelcomeProps) {
|
|
8
|
+
const cssStyles = `
|
|
9
|
+
:root {
|
|
10
|
+
--color-bg: #ffffff;
|
|
11
|
+
--color-text: #000000;
|
|
12
|
+
--color-text-muted: #666666;
|
|
13
|
+
--color-border: #e0e0e0;
|
|
14
|
+
--color-accent: #007141;
|
|
15
|
+
--color-accent-light: rgba(0, 188, 109, 0.1);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/* Dark mode variable overrides */
|
|
19
|
+
:root.dark-mode,
|
|
20
|
+
.dark-mode {
|
|
21
|
+
--color-bg: #1a1a1a;
|
|
22
|
+
--color-text: #ffffff;
|
|
23
|
+
--color-text-muted: #b0b0b0;
|
|
24
|
+
--color-border: #404040;
|
|
25
|
+
--color-accent: #00c76d;
|
|
26
|
+
--color-accent-light: rgba(0, 199, 109, 0.2);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
* {
|
|
30
|
+
box-sizing: border-box;
|
|
31
|
+
margin: 0;
|
|
32
|
+
padding: 0;
|
|
33
|
+
-webkit-print-color-adjust: exact;
|
|
34
|
+
print-color-adjust: exact;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
body {
|
|
38
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
|
39
|
+
background-color: var(--color-bg);
|
|
40
|
+
color: var(--color-text);
|
|
41
|
+
padding: 20mm;
|
|
42
|
+
line-height: 1.6;
|
|
43
|
+
transition: background-color 0.3s ease, color 0.3s ease;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
h1 {
|
|
47
|
+
font-size: 32px;
|
|
48
|
+
font-weight: 700;
|
|
49
|
+
color: var(--color-text);
|
|
50
|
+
margin-bottom: 10mm;
|
|
51
|
+
border-bottom: 2px solid var(--color-accent);
|
|
52
|
+
padding-bottom: 5mm;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.content {
|
|
56
|
+
font-size: 14px;
|
|
57
|
+
color: var(--color-text);
|
|
58
|
+
margin-bottom: 8mm;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.content p {
|
|
62
|
+
margin-bottom: 5mm;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.footer {
|
|
66
|
+
margin-top: 15mm;
|
|
67
|
+
padding-top: 8mm;
|
|
68
|
+
border-top: 1px solid var(--color-border);
|
|
69
|
+
text-align: center;
|
|
70
|
+
font-size: 12px;
|
|
71
|
+
color: var(--color-text-muted);
|
|
72
|
+
}
|
|
73
|
+
`;
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<Document lang="en" dir="ltr">
|
|
77
|
+
<style dangerouslySetInnerHTML={{ __html: cssStyles }} />
|
|
78
|
+
<Body>
|
|
79
|
+
<div className="container">
|
|
80
|
+
<h1>Welcome, {name}!</h1>
|
|
81
|
+
|
|
82
|
+
<div className="content">
|
|
83
|
+
<p>
|
|
84
|
+
This is your first PDF template created with React PDF Render.
|
|
85
|
+
</p>
|
|
86
|
+
<p>
|
|
87
|
+
You can start editing this template in{' '}
|
|
88
|
+
<code>templates/welcome.tsx</code> to create your own PDF
|
|
89
|
+
documents.
|
|
90
|
+
</p>
|
|
91
|
+
</div>
|
|
92
|
+
|
|
93
|
+
<div className="footer">
|
|
94
|
+
React PDF Render • Get started at{' '}
|
|
95
|
+
<a href="https://react-pdf-forge.com">react-pdf-forge.com</a>
|
|
96
|
+
</div>
|
|
97
|
+
</div>
|
|
98
|
+
</Body>
|
|
99
|
+
</Document>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
Welcome.PreviewProps = {
|
|
104
|
+
name: 'World',
|
|
105
|
+
} as WelcomeProps;
|
|
106
|
+
|
|
107
|
+
export default Welcome;
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "tsconfig/base.json",
|
|
3
|
+
"include": ["**/*.ts", "**/*.tsx"],
|
|
4
|
+
"exclude": ["dist", "build", "node_modules", ".test"],
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"moduleResolution": "nodenext",
|
|
7
|
+
"module": "nodenext",
|
|
8
|
+
"jsx": "react-jsx",
|
|
9
|
+
"noEmit": true,
|
|
10
|
+
"types": ["vitest/globals"]
|
|
11
|
+
}
|
|
12
|
+
}
|