1- import * as fs from 'fs' ;
2- import * as path from 'path' ;
3- import { AutomationConfig } from './schema' ;
41import { runAutomation } from './automation' ;
52
63const EXIT_CODES = {
74 SUCCESS : 0 ,
85 INVALID_ARGS : 1 ,
9- FILE_NOT_FOUND : 2 ,
10- INVALID_CONFIG : 3 ,
11- AUTOMATION_FAILED : 4 ,
6+ AUTOMATION_FAILED : 2 ,
127} as const ;
138
149const DEFAULT_COMPANY_IDENTIFIER = 'embed' ;
1510
1611const printUsage = ( ) : void => {
1712 console . log ( `
18- Usage: npx tsx src/index.ts <config.json > [options]
13+ Usage: npx tsx src/index.ts <document > [options]
1914
2015Arguments:
21- config.json Path to JSON configuration file
16+ document URL or local file path to a PDF
2217
2318Options:
2419 --company-identifier Your SimplePDF company identifier (default: embed)
2520 --help Show this help message
2621
27- Configuration file format:
28- {
29- "document": "https://example.com/document.pdf"
30- }
31-
3222Examples:
33- npx tsx src/index.ts example.config.json
34- npx tsx src/index.ts example.config.json --company-identifier yourcompany
23+ npx tsx src/index.ts https://example.com/form.pdf
24+ npx tsx src/index.ts ./documents/form.pdf
25+ npx tsx src/index.ts https://example.com/form.pdf --company-identifier yourcompany
3526` ) ;
3627} ;
3728
3829type ParsedArgs = {
39- configPath : string | null ;
30+ document : string | null ;
4031 baseUrl : string ;
4132 showHelp : boolean ;
4233} ;
4334
4435const parseArgs = ( ) : ParsedArgs => {
4536 const args = process . argv . slice ( 2 ) ;
46- let configPath : string | null = null ;
37+ let document : string | null = null ;
4738 let companyIdentifier = DEFAULT_COMPANY_IDENTIFIER ;
4839 let baseUrl : string | null = null ;
4940 let showHelp = false ;
@@ -67,57 +58,35 @@ const parseArgs = (): ParsedArgs => {
6758 }
6859
6960 if ( ! arg ?. startsWith ( '-' ) ) {
70- configPath = arg ?? null ;
61+ document = arg ?? null ;
7162 }
7263 }
7364
7465 const resolvedBaseUrl = baseUrl ?? `https://${ companyIdentifier } .simplepdf.com` ;
7566
76- return { configPath, baseUrl : resolvedBaseUrl , showHelp } ;
77- } ;
78-
79- const loadConfig = ( { configPath } : { configPath : string } ) : AutomationConfig => {
80- const absolutePath = path . isAbsolute ( configPath ) ? configPath : path . resolve ( process . cwd ( ) , configPath ) ;
81-
82- if ( ! fs . existsSync ( absolutePath ) ) {
83- throw new Error ( `Configuration file not found: ${ absolutePath } ` ) ;
84- }
85-
86- const content = fs . readFileSync ( absolutePath , 'utf-8' ) ;
87- const parsed = JSON . parse ( content ) as unknown ;
88-
89- return parsed as AutomationConfig ;
67+ return { document, baseUrl : resolvedBaseUrl , showHelp } ;
9068} ;
9169
9270const main = async ( ) : Promise < void > => {
93- const { configPath , baseUrl, showHelp } = parseArgs ( ) ;
71+ const { document , baseUrl, showHelp } = parseArgs ( ) ;
9472
9573 if ( showHelp ) {
9674 printUsage ( ) ;
9775 process . exit ( EXIT_CODES . SUCCESS ) ;
9876 }
9977
100- if ( ! configPath ) {
101- console . error ( 'Error: Configuration file path is required' ) ;
78+ if ( ! document ) {
79+ console . error ( 'Error: document URL or file path is required' ) ;
10280 printUsage ( ) ;
10381 process . exit ( EXIT_CODES . INVALID_ARGS ) ;
10482 }
10583
106- let config : AutomationConfig ;
107- try {
108- config = loadConfig ( { configPath } ) ;
109- } catch ( e ) {
110- const error = e as Error ;
111- console . error ( `Error loading configuration: ${ error . message } ` ) ;
112- process . exit ( EXIT_CODES . FILE_NOT_FOUND ) ;
113- }
114-
11584 console . log ( 'Starting automation...' ) ;
116- console . log ( `Document: ${ config . document } ` ) ;
85+ console . log ( `Document: ${ document } ` ) ;
11786 console . log ( `Editor: ${ baseUrl } ` ) ;
11887 console . log ( '' ) ;
11988
120- const result = await runAutomation ( { config , baseUrl } ) ;
89+ const result = await runAutomation ( { document , baseUrl } ) ;
12190
12291 if ( ! result . success ) {
12392 console . error ( `Automation failed: [${ result . error . code } ] ${ result . error . message } ` ) ;
0 commit comments