@powerhousedao/ph-cli 5.1.0-staging.0 → 5.2.0-staging.1
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/dist/src/commands/access-token.d.ts +9 -0
- package/dist/src/commands/access-token.d.ts.map +1 -0
- package/dist/src/commands/access-token.js +110 -0
- package/dist/src/commands/access-token.js.map +1 -0
- package/dist/src/commands/generate.d.ts.map +1 -1
- package/dist/src/commands/generate.js +2 -1
- package/dist/src/commands/generate.js.map +1 -1
- package/dist/src/commands/index.d.ts +2 -0
- package/dist/src/commands/index.d.ts.map +1 -1
- package/dist/src/commands/index.js +2 -0
- package/dist/src/commands/index.js.map +1 -1
- package/dist/src/commands/login.d.ts +12 -0
- package/dist/src/commands/login.d.ts.map +1 -0
- package/dist/src/commands/login.js +208 -0
- package/dist/src/commands/login.js.map +1 -0
- package/dist/src/commands/migrate.d.ts +1 -1
- package/dist/src/commands/migrate.d.ts.map +1 -1
- package/dist/src/commands/register-commands.d.ts.map +1 -1
- package/dist/src/commands/register-commands.js +4 -0
- package/dist/src/commands/register-commands.js.map +1 -1
- package/dist/src/commands/switchboard.d.ts.map +1 -1
- package/dist/src/commands/switchboard.js +12 -2
- package/dist/src/commands/switchboard.js.map +1 -1
- package/dist/src/help.d.ts +9 -1
- package/dist/src/help.d.ts.map +1 -1
- package/dist/src/help.js +164 -9
- package/dist/src/help.js.map +1 -1
- package/dist/src/services/auth.d.ts +69 -0
- package/dist/src/services/auth.d.ts.map +1 -0
- package/dist/src/services/auth.js +171 -0
- package/dist/src/services/auth.js.map +1 -0
- package/dist/src/services/generate.d.ts +2 -1
- package/dist/src/services/generate.d.ts.map +1 -1
- package/dist/src/services/generate.js +15 -8
- package/dist/src/services/generate.js.map +1 -1
- package/dist/src/services/migrate/migrate.d.ts +2 -2
- package/dist/src/services/migrate/migrate.d.ts.map +1 -1
- package/dist/src/services/migrate/migrate.js +8 -8
- package/dist/src/services/migrate/migrate.js.map +1 -1
- package/dist/src/services/switchboard.d.ts +12 -0
- package/dist/src/services/switchboard.d.ts.map +1 -1
- package/dist/src/services/switchboard.js +10 -1
- package/dist/src/services/switchboard.js.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -8
package/dist/src/help.js
CHANGED
|
@@ -497,29 +497,42 @@ Command Overview:
|
|
|
497
497
|
2. Loads document models and processors
|
|
498
498
|
3. Provides an API for document operations
|
|
499
499
|
4. Enables real-time document processing
|
|
500
|
+
5. Can authenticate with remote services using your identity from 'ph login'
|
|
500
501
|
|
|
501
502
|
Options:
|
|
502
503
|
--port <PORT> Port to host the API. Default is 4001.
|
|
503
|
-
|
|
504
|
-
--config-file <path> Path to the powerhouse.config.js file. Default is
|
|
504
|
+
|
|
505
|
+
--config-file <path> Path to the powerhouse.config.js file. Default is
|
|
505
506
|
'./powerhouse.config.json'. This configures the switchboard behavior.
|
|
506
|
-
|
|
507
|
+
|
|
507
508
|
--dev Enable development mode to load local packages from the current directory.
|
|
508
509
|
This allows the switchboard to discover and load document models, processors,
|
|
509
510
|
and subgraphs from your local development environment.
|
|
510
|
-
|
|
511
|
+
|
|
511
512
|
--db-path <DB_PATH> Path to the database for storing document data.
|
|
512
|
-
|
|
513
|
+
|
|
513
514
|
--https-key-file <path> Path to the SSL key file if using HTTPS for secure connections.
|
|
514
|
-
|
|
515
|
+
|
|
515
516
|
--https-cert-file <path> Path to the SSL certificate file if using HTTPS.
|
|
516
|
-
|
|
517
|
+
|
|
517
518
|
--packages <pkg...> List of packages to be loaded. If defined, packages specified
|
|
518
519
|
in the config file are ignored.
|
|
519
|
-
|
|
520
|
-
--base-path <path> Base path for the API endpoints. Sets the BASE_PATH environment
|
|
520
|
+
|
|
521
|
+
--base-path <path> Base path for the API endpoints. Sets the BASE_PATH environment
|
|
521
522
|
variable used by the server to prefix all routes.
|
|
522
523
|
|
|
524
|
+
Identity Options:
|
|
525
|
+
--use-identity Enable identity using the keypair from 'ph login'. This allows the
|
|
526
|
+
switchboard to authenticate with remote drives and services using
|
|
527
|
+
your authorized Ethereum identity.
|
|
528
|
+
|
|
529
|
+
--keypair-path <path> Path to a custom keypair file. Overrides the default .keypair.json
|
|
530
|
+
in the current directory.
|
|
531
|
+
|
|
532
|
+
--require-identity Require an existing keypair; fail if not found. Use this when you
|
|
533
|
+
want to ensure the switchboard runs with a valid identity. If no
|
|
534
|
+
keypair exists, run 'ph login' first to create one.
|
|
535
|
+
|
|
523
536
|
Examples:
|
|
524
537
|
$ ph switchboard # Start switchboard with default settings
|
|
525
538
|
$ ph switchboard --port 5000 # Use custom port 5000
|
|
@@ -527,6 +540,8 @@ Examples:
|
|
|
527
540
|
$ ph switchboard --config-file custom.json # Use custom configuration file
|
|
528
541
|
$ ph switchboard --packages pkg1 pkg2 # Load specific packages
|
|
529
542
|
$ ph switchboard --base-path /switchboard # Set API base path to /switchboard
|
|
543
|
+
$ ph switchboard --use-identity # Start with identity from ph login
|
|
544
|
+
$ ph switchboard --require-identity # Require identity, fail if not logged in
|
|
530
545
|
`;
|
|
531
546
|
/**
|
|
532
547
|
* Help text for the reactor command
|
|
@@ -601,4 +616,144 @@ Notes:
|
|
|
601
616
|
- Using the correct CLI version is important for compatibility with your project
|
|
602
617
|
- Version information is read from the package.json file of the CLI
|
|
603
618
|
`;
|
|
619
|
+
/**
|
|
620
|
+
* Help text for the login command
|
|
621
|
+
*/
|
|
622
|
+
export const loginHelp = `
|
|
623
|
+
Command Overview:
|
|
624
|
+
The login command authenticates you with Renown using your Ethereum wallet. This enables
|
|
625
|
+
the CLI to act on behalf of your Ethereum identity for authenticated operations.
|
|
626
|
+
|
|
627
|
+
This command:
|
|
628
|
+
1. Generates or loads a cryptographic identity (DID) for the CLI
|
|
629
|
+
2. Opens your browser to the Renown authentication page
|
|
630
|
+
3. You authorize the CLI's DID to act on behalf of your Ethereum address
|
|
631
|
+
4. Stores the credentials locally in ~/.ph/auth.json
|
|
632
|
+
|
|
633
|
+
Options:
|
|
634
|
+
--renown-url <url> Specify a custom Renown server URL. Defaults to
|
|
635
|
+
https://www.renown.id
|
|
636
|
+
|
|
637
|
+
--timeout <seconds> Set the authentication timeout in seconds. The command will
|
|
638
|
+
wait this long for you to complete authentication in the browser.
|
|
639
|
+
Defaults to 300 seconds (5 minutes).
|
|
640
|
+
|
|
641
|
+
--logout Sign out and clear your stored credentials. Use this when you
|
|
642
|
+
want to switch accounts or revoke local authentication.
|
|
643
|
+
|
|
644
|
+
--status Show your current authentication status without logging in.
|
|
645
|
+
Displays your CLI DID, ETH address, and when you authenticated.
|
|
646
|
+
|
|
647
|
+
--show-did Show only the CLI's DID and exit. Useful for scripts.
|
|
648
|
+
|
|
649
|
+
Authentication Flow:
|
|
650
|
+
1. Run 'ph login' - the CLI generates/loads its cryptographic identity (DID)
|
|
651
|
+
2. A browser window opens to Renown with the CLI's DID
|
|
652
|
+
3. Connect your Ethereum wallet (MetaMask, etc.)
|
|
653
|
+
4. Authorize the CLI's DID to act on behalf of your ETH address
|
|
654
|
+
5. Return to your terminal - authentication is complete!
|
|
655
|
+
|
|
656
|
+
Credentials Storage:
|
|
657
|
+
All identity files are stored per-project in the current working directory:
|
|
658
|
+
|
|
659
|
+
.keypair.json The CLI's cryptographic keypair (ECDSA P-256)
|
|
660
|
+
.auth.json Your authentication credentials including:
|
|
661
|
+
- Your Ethereum address (the account you authorized)
|
|
662
|
+
- Your User DID (did:pkh:eip155:chainId:address)
|
|
663
|
+
- CLI DID (did:key:... - the CLI's cryptographic identity)
|
|
664
|
+
- Credential ID for session validation
|
|
665
|
+
|
|
666
|
+
This allows each project to have its own identity and credentials.
|
|
667
|
+
For CI/CD, provide the keypair via PH_RENOWN_PRIVATE_KEY env variable.
|
|
668
|
+
|
|
669
|
+
Environment Variables:
|
|
670
|
+
PH_RENOWN_PRIVATE_KEY JSON-encoded JWK keypair for the CLI's identity.
|
|
671
|
+
If set, the CLI will use this instead of generating
|
|
672
|
+
or loading from file. Useful for CI/CD environments.
|
|
673
|
+
|
|
674
|
+
Examples:
|
|
675
|
+
$ ph login # Authenticate with default settings
|
|
676
|
+
$ ph login --status # Check authentication status and CLI DID
|
|
677
|
+
$ ph login --show-did # Print only the CLI's DID
|
|
678
|
+
$ ph login --logout # Sign out and clear credentials
|
|
679
|
+
$ ph login --timeout 600 # Wait up to 10 minutes for authentication
|
|
680
|
+
$ ph login --renown-url http://localhost:3000 # Use local Renown server
|
|
681
|
+
|
|
682
|
+
Notes:
|
|
683
|
+
- You only need to authenticate once; credentials persist until you log out
|
|
684
|
+
- The CLI's DID remains stable unless you delete .keypair.json from your project
|
|
685
|
+
- If already authenticated, the command will show your current status
|
|
686
|
+
- The browser must remain open until authentication completes
|
|
687
|
+
- Your wallet signature authorizes the CLI's DID to act on your behalf
|
|
688
|
+
`;
|
|
689
|
+
/**
|
|
690
|
+
* Help text for the access-token command
|
|
691
|
+
*/
|
|
692
|
+
export const accessTokenHelp = `
|
|
693
|
+
Command Overview:
|
|
694
|
+
The access-token command generates a bearer token for API authentication. This token
|
|
695
|
+
can be used to authenticate requests to Powerhouse APIs like reactor-api (Switchboard).
|
|
696
|
+
|
|
697
|
+
This command:
|
|
698
|
+
1. Uses your CLI's cryptographic identity (DID) to sign a verifiable credential
|
|
699
|
+
2. Creates a JWT bearer token with configurable expiration
|
|
700
|
+
3. Outputs the token to stdout (info to stderr) for easy piping
|
|
701
|
+
|
|
702
|
+
Prerequisites:
|
|
703
|
+
You must have a cryptographic identity. Run 'ph login' first to:
|
|
704
|
+
- Generate a keypair (stored in .keypair.json)
|
|
705
|
+
- Optionally link your Ethereum address (stored in .auth.json)
|
|
706
|
+
|
|
707
|
+
Options:
|
|
708
|
+
--expiry <duration> Set the token expiration time. Supports multiple formats:
|
|
709
|
+
- Days: "7d" (default), "30d", "1d"
|
|
710
|
+
- Hours: "24h", "12h", "1h"
|
|
711
|
+
- Seconds: "3600", "3600s", "86400s"
|
|
712
|
+
Default is 7 days.
|
|
713
|
+
|
|
714
|
+
--audience <url> Optional. Set the intended audience (aud claim) for the token.
|
|
715
|
+
This can be used to restrict the token to specific services.
|
|
716
|
+
|
|
717
|
+
Token Details:
|
|
718
|
+
The generated token is a JWT (JSON Web Token) containing:
|
|
719
|
+
- Issuer (iss): Your CLI's DID (did:key:...)
|
|
720
|
+
- Subject (sub): Your CLI's DID
|
|
721
|
+
- Credential Subject: Chain ID, network ID, and address (if authenticated)
|
|
722
|
+
- Expiration (exp): Based on --expiry option
|
|
723
|
+
- Audience (aud): If --audience is specified
|
|
724
|
+
|
|
725
|
+
Output:
|
|
726
|
+
- Token information (DID, address, expiry) is printed to stderr
|
|
727
|
+
- The token itself is printed to stdout for easy piping/copying
|
|
728
|
+
|
|
729
|
+
This allows you to use the command in scripts:
|
|
730
|
+
TOKEN=$(ph access-token)
|
|
731
|
+
curl -H "Authorization: Bearer $TOKEN" http://localhost:4001/graphql
|
|
732
|
+
|
|
733
|
+
Examples:
|
|
734
|
+
$ ph access-token # Generate token valid for 7 days
|
|
735
|
+
$ ph access-token --expiry 30d # Generate token valid for 30 days
|
|
736
|
+
$ ph access-token --expiry 24h # Generate token valid for 24 hours
|
|
737
|
+
$ ph access-token --expiry 3600 # Generate token valid for 1 hour (3600 seconds)
|
|
738
|
+
$ ph access-token --audience http://localhost:4001 # Set audience claim
|
|
739
|
+
$ ph access-token | pbcopy # Copy token to clipboard (macOS)
|
|
740
|
+
$ ph access-token | xclip -selection c # Copy token to clipboard (Linux)
|
|
741
|
+
|
|
742
|
+
Usage with APIs:
|
|
743
|
+
# Generate token and use with curl
|
|
744
|
+
TOKEN=$(ph access-token --expiry 1d)
|
|
745
|
+
curl -X POST http://localhost:4001/graphql \\
|
|
746
|
+
-H "Content-Type: application/json" \\
|
|
747
|
+
-H "Authorization: Bearer $TOKEN" \\
|
|
748
|
+
-d '{"query": "{ drives { id name } }"}'
|
|
749
|
+
|
|
750
|
+
# Export as environment variable
|
|
751
|
+
export PH_ACCESS_TOKEN=$(ph access-token)
|
|
752
|
+
|
|
753
|
+
Notes:
|
|
754
|
+
- Tokens are self-signed using your CLI's private key
|
|
755
|
+
- No network request is made; tokens are generated locally
|
|
756
|
+
- The recipient API must trust your CLI's DID to accept the token
|
|
757
|
+
- For reactor-api, ensure AUTH_ENABLED=true to require authentication
|
|
758
|
+
`;
|
|
604
759
|
//# sourceMappingURL=help.js.map
|
package/dist/src/help.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"help.js","sourceRoot":"","sources":["../../src/help.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgDhC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;CA0B/B,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsCjC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+D3B,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsC1B,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwC5B,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BvB,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoC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AAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoCtB,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsDxB,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkC1B,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqC1B,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwD9B,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuC1B,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;CA0B1B,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkExB,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkE9B,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { type IConnectCrypto, type JsonWebKeyPairStorage, type JwkKeyPair } from "@renown/sdk";
|
|
2
|
+
export interface StoredCredentials {
|
|
3
|
+
address: string;
|
|
4
|
+
chainId: number;
|
|
5
|
+
did: string;
|
|
6
|
+
connectDid: string;
|
|
7
|
+
credentialId: string;
|
|
8
|
+
userDocumentId?: string;
|
|
9
|
+
authenticatedAt: string;
|
|
10
|
+
renownUrl: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Key storage that supports:
|
|
14
|
+
* 1. PH_RENOWN_PRIVATE_KEY environment variable (JSON-encoded JwkKeyPair)
|
|
15
|
+
* 2. Falls back to file storage at .keypair.json in current working directory
|
|
16
|
+
*/
|
|
17
|
+
export declare class KeyStorage implements JsonWebKeyPairStorage {
|
|
18
|
+
#private;
|
|
19
|
+
constructor(filePath?: string);
|
|
20
|
+
loadKeyPair(): Promise<JwkKeyPair | undefined>;
|
|
21
|
+
saveKeyPair(keyPair: JwkKeyPair): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Load stored credentials from disk
|
|
25
|
+
*/
|
|
26
|
+
export declare function loadCredentials(): StoredCredentials | null;
|
|
27
|
+
/**
|
|
28
|
+
* Save credentials to disk (in current working directory)
|
|
29
|
+
*/
|
|
30
|
+
export declare function saveCredentials(credentials: StoredCredentials): void;
|
|
31
|
+
/**
|
|
32
|
+
* Clear stored credentials
|
|
33
|
+
*/
|
|
34
|
+
export declare function clearCredentials(): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Check if user is currently authenticated
|
|
37
|
+
*/
|
|
38
|
+
export declare function isAuthenticated(): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Generate a UUID v4 for session IDs
|
|
41
|
+
*/
|
|
42
|
+
export declare function generateSessionId(): string;
|
|
43
|
+
/**
|
|
44
|
+
* Default Renown URL
|
|
45
|
+
*/
|
|
46
|
+
export declare const DEFAULT_RENOWN_URL = "https://www.renown.id";
|
|
47
|
+
/**
|
|
48
|
+
* Get or create the ConnectCrypto instance
|
|
49
|
+
* Uses PH_RENOWN_PRIVATE_KEY env var if set, otherwise generates/loads from file
|
|
50
|
+
*/
|
|
51
|
+
export declare function getConnectCrypto(): Promise<IConnectCrypto>;
|
|
52
|
+
/**
|
|
53
|
+
* Get the DID from ConnectCrypto
|
|
54
|
+
* This is the did:key:... format DID that identifies this CLI instance
|
|
55
|
+
*/
|
|
56
|
+
export declare function getConnectDid(): Promise<string>;
|
|
57
|
+
/**
|
|
58
|
+
* Get the issuer for signing credentials
|
|
59
|
+
*/
|
|
60
|
+
export declare function getIssuer(): Promise<import("did-jwt-vc").Issuer>;
|
|
61
|
+
/**
|
|
62
|
+
* Get a bearer token for API authentication
|
|
63
|
+
*/
|
|
64
|
+
export declare function getBearerToken(driveUrl: string, address?: string, refresh?: boolean): Promise<string>;
|
|
65
|
+
/**
|
|
66
|
+
* Export the keypair to a JSON string suitable for PH_RENOWN_PRIVATE_KEY
|
|
67
|
+
*/
|
|
68
|
+
export declare function exportKeyPairToEnv(keyPair: JwkKeyPair): string;
|
|
69
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/services/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,KAAK,UAAU,EAChB,MAAM,aAAa,CAAC;AAarB,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,qBAAa,UAAW,YAAW,qBAAqB;;gBAG1C,QAAQ,CAAC,EAAE,MAAM;IAUvB,WAAW,IAAI,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAsB9C,WAAW,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;CA2BtD;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,iBAAiB,GAAG,IAAI,CAU1D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,iBAAiB,GAAG,IAAI,CAEpE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,OAAO,CAS1C;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,OAAO,CAGzC;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAc1C;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB,0BAA0B,CAAC;AAE1D;;;GAGG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,cAAc,CAAC,CAMhE;AAED;;;GAGG;AACH,wBAAsB,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC,CAGrD;AAED;;GAEG;AACH,wBAAsB,SAAS,yCAG9B;AAED;;GAEG;AACH,wBAAsB,cAAc,CAClC,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,MAAM,EAChB,OAAO,UAAQ,GACd,OAAO,CAAC,MAAM,CAAC,CAGjB;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,CAE9D"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { ConnectCrypto, } from "@renown/sdk";
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
const ENV_KEY_NAME = "PH_RENOWN_PRIVATE_KEY";
|
|
5
|
+
const AUTH_FILE = ".auth.json";
|
|
6
|
+
const KEYPAIR_FILE = ".keypair.json";
|
|
7
|
+
const AUTH_PATH = join(process.cwd(), AUTH_FILE);
|
|
8
|
+
const KEYPAIR_PATH = join(process.cwd(), KEYPAIR_FILE);
|
|
9
|
+
// Singleton instance of ConnectCrypto
|
|
10
|
+
let connectCryptoInstance = null;
|
|
11
|
+
/**
|
|
12
|
+
* Key storage that supports:
|
|
13
|
+
* 1. PH_RENOWN_PRIVATE_KEY environment variable (JSON-encoded JwkKeyPair)
|
|
14
|
+
* 2. Falls back to file storage at .keypair.json in current working directory
|
|
15
|
+
*/
|
|
16
|
+
export class KeyStorage {
|
|
17
|
+
#filePath;
|
|
18
|
+
constructor(filePath) {
|
|
19
|
+
this.#filePath = filePath || KEYPAIR_PATH;
|
|
20
|
+
// Ensure directory exists
|
|
21
|
+
const dir = dirname(this.#filePath);
|
|
22
|
+
if (!existsSync(dir)) {
|
|
23
|
+
mkdirSync(dir, { recursive: true });
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async loadKeyPair() {
|
|
27
|
+
// First check environment variable
|
|
28
|
+
const envKey = process.env[ENV_KEY_NAME];
|
|
29
|
+
if (envKey) {
|
|
30
|
+
try {
|
|
31
|
+
const keyPair = JSON.parse(envKey);
|
|
32
|
+
// Validate it has the required structure
|
|
33
|
+
if (keyPair.publicKey && keyPair.privateKey) {
|
|
34
|
+
return keyPair;
|
|
35
|
+
}
|
|
36
|
+
console.warn(`${ENV_KEY_NAME} is set but doesn't contain valid publicKey and privateKey`);
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
console.warn(`Failed to parse ${ENV_KEY_NAME} as JSON:`, e);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// Fall back to file storage
|
|
43
|
+
return this.#loadFromFile();
|
|
44
|
+
}
|
|
45
|
+
async saveKeyPair(keyPair) {
|
|
46
|
+
// Don't save if using env var
|
|
47
|
+
if (process.env[ENV_KEY_NAME]) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
// Save to file
|
|
51
|
+
this.#saveToFile(keyPair);
|
|
52
|
+
}
|
|
53
|
+
#loadFromFile() {
|
|
54
|
+
try {
|
|
55
|
+
if (!existsSync(this.#filePath)) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
const data = readFileSync(this.#filePath, "utf-8");
|
|
59
|
+
const parsed = JSON.parse(data);
|
|
60
|
+
return parsed.keyPair;
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
#saveToFile(keyPair) {
|
|
67
|
+
const data = { keyPair };
|
|
68
|
+
writeFileSync(this.#filePath, JSON.stringify(data, null, 2), "utf-8");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Load stored credentials from disk
|
|
73
|
+
*/
|
|
74
|
+
export function loadCredentials() {
|
|
75
|
+
try {
|
|
76
|
+
if (!existsSync(AUTH_PATH)) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
const content = readFileSync(AUTH_PATH, "utf-8");
|
|
80
|
+
return JSON.parse(content);
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Save credentials to disk (in current working directory)
|
|
88
|
+
*/
|
|
89
|
+
export function saveCredentials(credentials) {
|
|
90
|
+
writeFileSync(AUTH_PATH, JSON.stringify(credentials, null, 2), "utf-8");
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Clear stored credentials
|
|
94
|
+
*/
|
|
95
|
+
export function clearCredentials() {
|
|
96
|
+
try {
|
|
97
|
+
if (existsSync(AUTH_PATH)) {
|
|
98
|
+
writeFileSync(AUTH_PATH, "{}", "utf-8");
|
|
99
|
+
}
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Check if user is currently authenticated
|
|
108
|
+
*/
|
|
109
|
+
export function isAuthenticated() {
|
|
110
|
+
const creds = loadCredentials();
|
|
111
|
+
return creds !== null && !!creds.credentialId;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Generate a UUID v4 for session IDs
|
|
115
|
+
*/
|
|
116
|
+
export function generateSessionId() {
|
|
117
|
+
// Simple UUID v4 implementation using crypto
|
|
118
|
+
const bytes = new Uint8Array(16);
|
|
119
|
+
crypto.getRandomValues(bytes);
|
|
120
|
+
// Set version (4) and variant bits
|
|
121
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
122
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
123
|
+
const hex = Array.from(bytes)
|
|
124
|
+
.map((b) => b.toString(16).padStart(2, "0"))
|
|
125
|
+
.join("");
|
|
126
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Default Renown URL
|
|
130
|
+
*/
|
|
131
|
+
export const DEFAULT_RENOWN_URL = "https://www.renown.id";
|
|
132
|
+
/**
|
|
133
|
+
* Get or create the ConnectCrypto instance
|
|
134
|
+
* Uses PH_RENOWN_PRIVATE_KEY env var if set, otherwise generates/loads from file
|
|
135
|
+
*/
|
|
136
|
+
export async function getConnectCrypto() {
|
|
137
|
+
if (!connectCryptoInstance) {
|
|
138
|
+
const keyStorage = new KeyStorage();
|
|
139
|
+
connectCryptoInstance = new ConnectCrypto(keyStorage);
|
|
140
|
+
}
|
|
141
|
+
return connectCryptoInstance;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Get the DID from ConnectCrypto
|
|
145
|
+
* This is the did:key:... format DID that identifies this CLI instance
|
|
146
|
+
*/
|
|
147
|
+
export async function getConnectDid() {
|
|
148
|
+
const crypto = await getConnectCrypto();
|
|
149
|
+
return crypto.did();
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Get the issuer for signing credentials
|
|
153
|
+
*/
|
|
154
|
+
export async function getIssuer() {
|
|
155
|
+
const crypto = await getConnectCrypto();
|
|
156
|
+
return crypto.getIssuer();
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Get a bearer token for API authentication
|
|
160
|
+
*/
|
|
161
|
+
export async function getBearerToken(driveUrl, address, refresh = false) {
|
|
162
|
+
const crypto = await getConnectCrypto();
|
|
163
|
+
return crypto.getBearerToken(driveUrl, address, refresh);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Export the keypair to a JSON string suitable for PH_RENOWN_PRIVATE_KEY
|
|
167
|
+
*/
|
|
168
|
+
export function exportKeyPairToEnv(keyPair) {
|
|
169
|
+
return JSON.stringify(keyPair);
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../src/services/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,GAId,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C,MAAM,YAAY,GAAG,uBAAuB,CAAC;AAC7C,MAAM,SAAS,GAAG,YAAY,CAAC;AAC/B,MAAM,YAAY,GAAG,eAAe,CAAC;AACrC,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,SAAS,CAAC,CAAC;AACjD,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,YAAY,CAAC,CAAC;AAEvD,sCAAsC;AACtC,IAAI,qBAAqB,GAA0B,IAAI,CAAC;AAaxD;;;;GAIG;AACH,MAAM,OAAO,UAAU;IACrB,SAAS,CAAS;IAElB,YAAY,QAAiB;QAC3B,IAAI,CAAC,SAAS,GAAG,QAAQ,IAAI,YAAY,CAAC;QAE1C,0BAA0B;QAC1B,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CA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,CAAC,UAAU,CAAC,CAAC;IACxD,CAAC;IACD,OAAO,qBAAqB,CAAC;AAC/B,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa;IACjC,MAAM,MAAM,GAAG,MAAM,gBAAgB,EAAE,CAAC;IACxC,OAAO,MAAM,CAAC,GAAG,EAAE,CAAC;AACtB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS;IAC7B,MAAM,MAAM,GAAG,MAAM,gBAAgB,EAAE,CAAC;IACxC,OAAO,MAAM,CAAC,SAAS,EAAE,CAAC;AAC5B,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,QAAgB,EAChB,OAAgB,EAChB,OAAO,GAAG,KAAK;IAEf,MAAM,MAAM,GAAG,MAAM,gBAAgB,EAAE,CAAC;IACxC,OAAO,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AAC3D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAmB;IACpD,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -23,7 +23,8 @@ export type GenerateOptions = {
|
|
|
23
23
|
driveEditorDirName?: string;
|
|
24
24
|
migrationFile?: string;
|
|
25
25
|
schemaFile?: string;
|
|
26
|
-
|
|
26
|
+
useHygen?: boolean;
|
|
27
|
+
useVersioning?: boolean;
|
|
27
28
|
};
|
|
28
29
|
export declare function startGenerate(filePath: string | undefined, options: GenerateOptions): Promise<void>;
|
|
29
30
|
//# sourceMappingURL=generate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../src/services/generate.ts"],"names":[],"mappings":"AAaA,MAAM,MAAM,eAAe,GAAG;IAC5B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,C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IAChB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,aAAa,CAAC,EAAE,WAAW,GAAG,cAAc,CAAC;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF,wBAAsB,aAAa,CACjC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,OAAO,EAAE,eAAe,iBAuGzB"}
|
|
@@ -3,7 +3,8 @@ import { getConfig } from "@powerhousedao/config/node";
|
|
|
3
3
|
import path from "path";
|
|
4
4
|
export async function startGenerate(filePath, options) {
|
|
5
5
|
const baseConfig = getConfig();
|
|
6
|
-
const
|
|
6
|
+
const useVersioning = !!options.useVersioning;
|
|
7
|
+
const useTsMorph = useVersioning || !options.useHygen;
|
|
7
8
|
const config = {
|
|
8
9
|
...baseConfig,
|
|
9
10
|
...{
|
|
@@ -15,7 +16,8 @@ export async function startGenerate(filePath, options) {
|
|
|
15
16
|
...(options.skipFormat && { skipFormat: options.skipFormat }),
|
|
16
17
|
...(options.interactive && { interactive: options.interactive }),
|
|
17
18
|
...(options.watch && { watch: options.watch }),
|
|
18
|
-
|
|
19
|
+
useTsMorph,
|
|
20
|
+
useVersioning,
|
|
19
21
|
},
|
|
20
22
|
};
|
|
21
23
|
const command = {
|
|
@@ -40,7 +42,8 @@ export async function startGenerate(filePath, options) {
|
|
|
40
42
|
isDragAndDropEnabled: options.isDragAndDropEnabled,
|
|
41
43
|
migrationFile: options.migrationFile,
|
|
42
44
|
schemaFile: options.schemaFile,
|
|
43
|
-
|
|
45
|
+
useTsMorph,
|
|
46
|
+
useVersioning,
|
|
44
47
|
};
|
|
45
48
|
if (command.driveEditor) {
|
|
46
49
|
if (!command.driveEditorName) {
|
|
@@ -53,7 +56,7 @@ export async function startGenerate(filePath, options) {
|
|
|
53
56
|
allowedDocumentTypes: command.allowedDocumentTypes,
|
|
54
57
|
isDragAndDropEnabled: command.isDragAndDropEnabled,
|
|
55
58
|
driveEditorDirName: command.driveEditorDirName,
|
|
56
|
-
|
|
59
|
+
useTsMorph,
|
|
57
60
|
});
|
|
58
61
|
}
|
|
59
62
|
else if (command.editor) {
|
|
@@ -67,7 +70,7 @@ export async function startGenerate(filePath, options) {
|
|
|
67
70
|
editorId: command.editorId,
|
|
68
71
|
specifiedPackageName: command.specifiedPackageName,
|
|
69
72
|
editorDirName: command.editorDirName,
|
|
70
|
-
|
|
73
|
+
useTsMorph,
|
|
71
74
|
});
|
|
72
75
|
}
|
|
73
76
|
else if (command.processor && options.processor) {
|
|
@@ -88,12 +91,16 @@ export async function startGenerate(filePath, options) {
|
|
|
88
91
|
});
|
|
89
92
|
}
|
|
90
93
|
else if (filePath) {
|
|
91
|
-
await generateFromFile(
|
|
92
|
-
|
|
94
|
+
await generateFromFile({
|
|
95
|
+
path: filePath,
|
|
96
|
+
config,
|
|
97
|
+
useTsMorph,
|
|
98
|
+
options,
|
|
99
|
+
useVersioning,
|
|
93
100
|
});
|
|
94
101
|
}
|
|
95
102
|
else {
|
|
96
|
-
await generateCode(config,
|
|
103
|
+
await generateCode(config, useTsMorph, useVersioning);
|
|
97
104
|
}
|
|
98
105
|
}
|
|
99
106
|
//# sourceMappingURL=generate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../src/services/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,IAAI,YAAY,EACxB,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,IAAI,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../src/services/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,IAAI,YAAY,EACxB,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,IAAI,MAAM,MAAM,CAAC;AA+BxB,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,QAA4B,EAC5B,OAAwB;IAExB,MAAM,UAAU,GAAG,SAAS,EAAE,CAAC;IAC/B,MAAM,aAAa,GAAG,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC;IAC9C,MAAM,UAAU,GAAG,aAAa,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;IACtD,MAAM,MAAM,GAAG;QACb,GAAG,UAAU;QACb,GAAG;YACD,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,UAAU,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC;YACvD,GAAG,CAAC,OAAO,CAAC,UAAU,IAAI,EAAE,aAAa,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC;YAChE,GA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CAAC,aAAa,EAAE,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,EACvC,MAAM,CACP,CAAC;IACJ,CAAC;SAAM,IAAI,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;QACpD,MAAM,gBAAgB,CAAC,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC,IAAI,IAAI,IAAI,EAAE,MAAM,CAAC,CAAC;IAC7E,CAAC;SAAM,IAAI,OAAO,CAAC,YAAY,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;QAC5D,MAAM,oBAAoB,CAAC,OAAO,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;IAC/D,CAAC;SAAM,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;QACjC,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;QAC9C,MAAM,gBAAgB,CAAC;YACrB,aAAa,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,aAAa,CAAC;YACtD,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS;SAC1E,CAAC,CAAC;IACL,CAAC;SAAM,IAAI,QAAQ,EAAE,CAAC;QACpB,MAAM,gBAAgB,CAAC;YACrB,IAAI,EAAE,QAAQ;YACd,MAAM;YACN,UAAU;YACV,OAAO;YACP,aAAa;SACd,CAAC,CAAC;IACL,CAAC;SAAM,CAAC;QACN,MAAM,YAAY,CAAC,MAAM,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC;IACxD,CAAC;AACH,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** Run all migrations */
|
|
2
2
|
type MigrateOptions = {
|
|
3
|
-
|
|
3
|
+
useHygen?: boolean;
|
|
4
4
|
};
|
|
5
|
-
export declare function migrate({
|
|
5
|
+
export declare function migrate({ useHygen }: MigrateOptions): Promise<void>;
|
|
6
6
|
export {};
|
|
7
7
|
//# sourceMappingURL=migrate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../../../../src/services/migrate/migrate.ts"],"names":[],"mappings":"AAqBA,yBAAyB;AACzB,KAAK,cAAc,GAAG;IACpB,
|
|
1
|
+
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../../../../src/services/migrate/migrate.ts"],"names":[],"mappings":"AAqBA,yBAAyB;AACzB,KAAK,cAAc,GAAG;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AACF,wBAAsB,OAAO,CAAC,EAAE,QAAgB,EAAE,EAAE,cAAc,iBAkBjE"}
|
|
@@ -8,11 +8,11 @@ import { generate } from "../../commands/generate.js";
|
|
|
8
8
|
import { indexTsTemplate } from "./migrations/templates/index.js";
|
|
9
9
|
import { packageJsonExportsTemplate, packageJsonScriptsTemplate, } from "./migrations/templates/packageJson.js";
|
|
10
10
|
import { tsConfigTemplate } from "./migrations/templates/tsConfig.js";
|
|
11
|
-
export async function migrate({
|
|
11
|
+
export async function migrate({ useHygen = false }) {
|
|
12
12
|
await migratePackageJson();
|
|
13
13
|
await migrateTsConfig();
|
|
14
|
-
await runGenerateOnAllDocumentModels(
|
|
15
|
-
await runGenerateOnAllEditors(
|
|
14
|
+
await runGenerateOnAllDocumentModels(useHygen);
|
|
15
|
+
await runGenerateOnAllEditors(useHygen);
|
|
16
16
|
const project = new Project({
|
|
17
17
|
tsConfigFilePath: path.resolve("tsconfig.json"),
|
|
18
18
|
compilerOptions: {
|
|
@@ -166,13 +166,13 @@ function fixImports(project) {
|
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
168
|
/** Run the generate command on all document models */
|
|
169
|
-
async function runGenerateOnAllDocumentModels(
|
|
169
|
+
async function runGenerateOnAllDocumentModels(useHygen) {
|
|
170
170
|
await generate(undefined, {
|
|
171
|
-
|
|
171
|
+
useHygen,
|
|
172
172
|
});
|
|
173
173
|
}
|
|
174
174
|
/** Run the generate command on all editors */
|
|
175
|
-
async function runGenerateOnAllEditors(
|
|
175
|
+
async function runGenerateOnAllEditors(useHygen) {
|
|
176
176
|
const editorsPath = path.join(process.cwd(), "editors");
|
|
177
177
|
const dirs = (await readdir(editorsPath, { withFileTypes: true }))
|
|
178
178
|
.filter((entry) => entry.isDirectory())
|
|
@@ -203,7 +203,7 @@ async function runGenerateOnAllEditors(tsMorph) {
|
|
|
203
203
|
driveEditor: name,
|
|
204
204
|
driveEditorAppId: id,
|
|
205
205
|
driveEditorDirName: dir,
|
|
206
|
-
|
|
206
|
+
useHygen,
|
|
207
207
|
};
|
|
208
208
|
if (allowedDocumentTypes) {
|
|
209
209
|
args.allowedDocumentTypes = allowedDocumentTypes.join(",");
|
|
@@ -216,7 +216,7 @@ async function runGenerateOnAllEditors(tsMorph) {
|
|
|
216
216
|
editorId: id,
|
|
217
217
|
editorDirName: dir,
|
|
218
218
|
documentTypes: documentTypes?.join(","),
|
|
219
|
-
|
|
219
|
+
useHygen,
|
|
220
220
|
};
|
|
221
221
|
await generate(undefined, args);
|
|
222
222
|
}
|