alchemy 0.1.18 → 0.2.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/README.md +506 -0
- package/lib/alchemy.d.ts +67 -0
- package/lib/alchemy.js +48 -0
- package/lib/apply.d.ts +3 -20
- package/lib/apply.js +95 -82
- package/lib/aws/account-id.d.ts +0 -1
- package/lib/aws/account-id.js +0 -1
- package/lib/aws/bucket.d.ts +4 -7
- package/lib/aws/bucket.js +8 -12
- package/lib/aws/function.d.ts +4 -7
- package/lib/aws/function.js +9 -30
- package/lib/aws/index.d.ts +1 -1
- package/lib/aws/index.js +1 -1
- package/lib/aws/oidc/github-oidc-provider.d.ts +2 -6
- package/lib/aws/oidc/github-oidc-provider.js +10 -15
- package/lib/aws/oidc/index.d.ts +0 -1
- package/lib/aws/oidc/index.js +0 -1
- package/lib/aws/oidc/oidc-provider.d.ts +4 -6
- package/lib/aws/oidc/oidc-provider.js +9 -11
- package/lib/aws/policy-attachment.d.ts +9 -0
- package/lib/aws/policy-attachment.js +20 -0
- package/lib/aws/policy.d.ts +4 -16
- package/lib/aws/policy.js +9 -40
- package/lib/aws/queue.d.ts +4 -34
- package/lib/aws/queue.js +10 -20
- package/lib/aws/role.d.ts +4 -7
- package/lib/aws/role.js +17 -26
- package/lib/aws/ses.d.ts +4 -10
- package/lib/aws/ses.js +118 -131
- package/lib/aws/table.d.ts +4 -7
- package/lib/aws/table.js +8 -11
- package/lib/cloudflare/api.d.ts +0 -1
- package/lib/cloudflare/api.js +0 -1
- package/lib/cloudflare/asset-manifest.d.ts +0 -1
- package/lib/cloudflare/asset-manifest.js +0 -1
- package/lib/cloudflare/auth.d.ts +0 -1
- package/lib/cloudflare/auth.js +0 -1
- package/lib/cloudflare/bindings.d.ts +1 -1
- package/lib/cloudflare/bindings.js +3 -2
- package/lib/cloudflare/bound.d.ts +0 -1
- package/lib/cloudflare/bound.js +0 -1
- package/lib/cloudflare/bucket.d.ts +7 -15
- package/lib/cloudflare/bucket.js +12 -19
- package/lib/cloudflare/durable-object-namespace.d.ts +0 -3
- package/lib/cloudflare/durable-object-namespace.js +0 -4
- package/lib/cloudflare/generate-asset-manifest.d.ts +0 -1
- package/lib/cloudflare/generate-asset-manifest.js +1 -2
- package/lib/cloudflare/index.d.ts +2 -1
- package/lib/cloudflare/index.js +2 -1
- package/lib/cloudflare/kv-namespace.d.ts +6 -9
- package/lib/cloudflare/kv-namespace.js +16 -20
- package/lib/cloudflare/state.d.ts +0 -1
- package/lib/cloudflare/state.js +0 -1
- package/lib/cloudflare/static-site-router.d.ts +0 -1
- package/lib/cloudflare/static-site-router.js +0 -4
- package/lib/cloudflare/static-site.d.ts +5 -11
- package/lib/cloudflare/static-site.js +25 -37
- package/lib/cloudflare/types.d.ts +0 -1
- package/lib/cloudflare/types.js +0 -1
- package/lib/cloudflare/upload-asset-manifest.d.ts +0 -1
- package/lib/cloudflare/upload-asset-manifest.js +0 -1
- package/lib/cloudflare/worker-metadata.d.ts +0 -1
- package/lib/cloudflare/worker-metadata.js +0 -1
- package/lib/cloudflare/worker-migration.d.ts +0 -1
- package/lib/cloudflare/worker-migration.js +0 -1
- package/lib/cloudflare/worker.d.ts +8 -14
- package/lib/cloudflare/worker.js +38 -50
- package/lib/cloudflare/wrangler.json.d.ts +243 -0
- package/lib/cloudflare/wrangler.json.js +35 -0
- package/lib/cloudflare/zone-settings.d.ts +301 -0
- package/lib/cloudflare/zone-settings.js +1 -0
- package/lib/cloudflare/zone.d.ts +196 -0
- package/lib/cloudflare/zone.js +175 -0
- package/lib/context.d.ts +58 -0
- package/lib/context.js +36 -0
- package/lib/destroy.d.ts +10 -13
- package/lib/destroy.js +104 -43
- package/lib/{esbuild.d.ts → esbuild/bundle.d.ts} +4 -18
- package/lib/{esbuild.js → esbuild/bundle.js} +10 -24
- package/lib/esbuild/index.d.ts +1 -0
- package/lib/esbuild/index.js +1 -0
- package/lib/fs/file.d.ts +13 -0
- package/lib/fs/file.js +20 -0
- package/lib/fs/folder.d.ts +10 -0
- package/lib/fs/folder.js +16 -0
- package/lib/fs/index.d.ts +2 -0
- package/lib/fs/index.js +2 -0
- package/lib/github/client.d.ts +0 -1
- package/lib/github/client.js +0 -1
- package/lib/github/index.d.ts +0 -1
- package/lib/github/index.js +0 -1
- package/lib/github/secret.d.ts +4 -6
- package/lib/github/secret.js +10 -12
- package/lib/index.d.ts +6 -10
- package/lib/index.js +5 -9
- package/lib/project/index.d.ts +1 -0
- package/lib/project/index.js +1 -0
- package/lib/project/vite.d.ts +39 -0
- package/lib/project/vite.js +68 -0
- package/lib/resource.d.ts +34 -62
- package/lib/resource.js +29 -270
- package/lib/scope.d.ts +37 -14
- package/lib/scope.js +97 -23
- package/lib/secret.d.ts +2 -7
- package/lib/secret.js +7 -20
- package/lib/state.d.ts +14 -10
- package/lib/state.js +20 -14
- package/lib/stripe/index.d.ts +0 -1
- package/lib/stripe/index.js +0 -1
- package/lib/stripe/price.d.ts +4 -5
- package/lib/stripe/price.js +10 -20
- package/lib/stripe/product.d.ts +4 -5
- package/lib/stripe/product.js +10 -20
- package/lib/stripe/webhook.d.ts +4 -6
- package/lib/stripe/webhook.js +12 -25
- package/lib/test/bun.d.ts +19 -0
- package/lib/test/bun.js +55 -0
- package/lib/{utils → util}/content-type.d.ts +0 -1
- package/lib/{utils → util}/content-type.js +0 -1
- package/lib/{encrypt.d.ts → util/encrypt.d.ts} +0 -1
- package/lib/{encrypt.js → util/encrypt.js} +0 -1
- package/lib/{error.d.ts → util/ignore.d.ts} +0 -1
- package/lib/{error.js → util/ignore.js} +0 -1
- package/lib/{utils → util}/retry.d.ts +0 -1
- package/lib/{utils → util}/retry.js +0 -1
- package/lib/util/rm.d.ts +1 -0
- package/lib/util/rm.js +11 -0
- package/lib/util/serde.d.ts +3 -0
- package/lib/{serde.js → util/serde.js} +19 -10
- package/lib/util/slugify.d.ts +1 -0
- package/lib/util/slugify.js +3 -0
- package/package.json +7 -5
- package/src/alchemy.ts +127 -0
- package/src/apply.ts +116 -115
- package/src/aws/bucket.ts +11 -14
- package/src/aws/function.ts +13 -33
- package/src/aws/index.ts +1 -0
- package/src/aws/oidc/github-oidc-provider.ts +14 -19
- package/src/aws/oidc/oidc-provider.ts +19 -12
- package/src/aws/policy-attachment.ts +51 -0
- package/src/aws/policy.ts +15 -60
- package/src/aws/queue.ts +17 -21
- package/src/aws/role.ts +25 -28
- package/src/aws/ses.ts +150 -164
- package/src/aws/table.ts +15 -15
- package/src/cloudflare/bindings.ts +8 -0
- package/src/cloudflare/bucket.ts +39 -47
- package/src/cloudflare/durable-object-namespace.ts +0 -10
- package/src/cloudflare/generate-asset-manifest.ts +1 -1
- package/src/cloudflare/index.ts +2 -0
- package/src/cloudflare/kv-namespace.ts +35 -33
- package/src/cloudflare/static-site-router.ts +0 -3
- package/src/cloudflare/static-site.ts +55 -71
- package/src/cloudflare/worker.ts +106 -112
- package/src/cloudflare/wrangler.json.ts +309 -0
- package/src/cloudflare/zone-settings.ts +368 -0
- package/src/cloudflare/zone.ts +491 -0
- package/src/context.ts +122 -0
- package/src/destroy.ts +124 -73
- package/src/{esbuild.ts → esbuild/bundle.ts} +16 -28
- package/src/esbuild/index.ts +1 -0
- package/src/fs/file.ts +39 -0
- package/src/fs/folder.ts +32 -0
- package/src/fs/index.ts +2 -0
- package/src/github/secret.ts +19 -16
- package/src/index.ts +7 -15
- package/src/project/index.ts +1 -0
- package/src/project/vite.ts +152 -0
- package/src/resource.ts +101 -462
- package/src/scope.ts +125 -36
- package/src/secret.ts +9 -32
- package/src/state.ts +38 -21
- package/src/stripe/price.ts +17 -22
- package/src/stripe/product.ts +17 -22
- package/src/stripe/webhook.ts +21 -27
- package/src/test/bun.ts +105 -0
- package/src/util/rm.ts +11 -0
- package/src/util/serde.ts +53 -0
- package/src/util/slugify.ts +3 -0
- package/lib/$.d.ts +0 -12
- package/lib/$.d.ts.map +0 -1
- package/lib/$.js +0 -42
- package/lib/$.js.map +0 -1
- package/lib/alchemize.d.ts +0 -47
- package/lib/alchemize.d.ts.map +0 -1
- package/lib/alchemize.js +0 -116
- package/lib/alchemize.js.map +0 -1
- package/lib/apply.d.ts.map +0 -1
- package/lib/apply.js.map +0 -1
- package/lib/aws/account-id.d.ts.map +0 -1
- package/lib/aws/account-id.js.map +0 -1
- package/lib/aws/bucket.d.ts.map +0 -1
- package/lib/aws/bucket.js.map +0 -1
- package/lib/aws/function.d.ts.map +0 -1
- package/lib/aws/function.js.map +0 -1
- package/lib/aws/index.d.ts.map +0 -1
- package/lib/aws/index.js.map +0 -1
- package/lib/aws/oidc/github-oidc-provider.d.ts.map +0 -1
- package/lib/aws/oidc/github-oidc-provider.js.map +0 -1
- package/lib/aws/oidc/index.d.ts.map +0 -1
- package/lib/aws/oidc/index.js.map +0 -1
- package/lib/aws/oidc/oidc-provider.d.ts.map +0 -1
- package/lib/aws/oidc/oidc-provider.js.map +0 -1
- package/lib/aws/policy.d.ts.map +0 -1
- package/lib/aws/policy.js.map +0 -1
- package/lib/aws/queue.d.ts.map +0 -1
- package/lib/aws/queue.js.map +0 -1
- package/lib/aws/role.d.ts.map +0 -1
- package/lib/aws/role.js.map +0 -1
- package/lib/aws/ses.d.ts.map +0 -1
- package/lib/aws/ses.js.map +0 -1
- package/lib/aws/table.d.ts.map +0 -1
- package/lib/aws/table.js.map +0 -1
- package/lib/cloudflare/api.d.ts.map +0 -1
- package/lib/cloudflare/api.js.map +0 -1
- package/lib/cloudflare/asset-manifest.d.ts.map +0 -1
- package/lib/cloudflare/asset-manifest.js.map +0 -1
- package/lib/cloudflare/auth.d.ts.map +0 -1
- package/lib/cloudflare/auth.js.map +0 -1
- package/lib/cloudflare/bindings.d.ts.map +0 -1
- package/lib/cloudflare/bindings.js.map +0 -1
- package/lib/cloudflare/bound.d.ts.map +0 -1
- package/lib/cloudflare/bound.js.map +0 -1
- package/lib/cloudflare/bucket.d.ts.map +0 -1
- package/lib/cloudflare/bucket.js.map +0 -1
- package/lib/cloudflare/durable-object-namespace.d.ts.map +0 -1
- package/lib/cloudflare/durable-object-namespace.js.map +0 -1
- package/lib/cloudflare/generate-asset-manifest.d.ts.map +0 -1
- package/lib/cloudflare/generate-asset-manifest.js.map +0 -1
- package/lib/cloudflare/index.d.ts.map +0 -1
- package/lib/cloudflare/index.js.map +0 -1
- package/lib/cloudflare/kv-namespace.d.ts.map +0 -1
- package/lib/cloudflare/kv-namespace.js.map +0 -1
- package/lib/cloudflare/state.d.ts.map +0 -1
- package/lib/cloudflare/state.js.map +0 -1
- package/lib/cloudflare/static-site-router.d.ts.map +0 -1
- package/lib/cloudflare/static-site-router.js.map +0 -1
- package/lib/cloudflare/static-site.d.ts.map +0 -1
- package/lib/cloudflare/static-site.js.map +0 -1
- package/lib/cloudflare/types.d.ts.map +0 -1
- package/lib/cloudflare/types.js.map +0 -1
- package/lib/cloudflare/upload-asset-manifest.d.ts.map +0 -1
- package/lib/cloudflare/upload-asset-manifest.js.map +0 -1
- package/lib/cloudflare/worker-metadata.d.ts.map +0 -1
- package/lib/cloudflare/worker-metadata.js.map +0 -1
- package/lib/cloudflare/worker-migration.d.ts.map +0 -1
- package/lib/cloudflare/worker-migration.js.map +0 -1
- package/lib/cloudflare/worker.d.ts.map +0 -1
- package/lib/cloudflare/worker.js.map +0 -1
- package/lib/destroy.d.ts.map +0 -1
- package/lib/destroy.js.map +0 -1
- package/lib/encrypt.d.ts.map +0 -1
- package/lib/encrypt.js.map +0 -1
- package/lib/error.d.ts.map +0 -1
- package/lib/error.js.map +0 -1
- package/lib/esbuild.d.ts.map +0 -1
- package/lib/esbuild.js.map +0 -1
- package/lib/fs.d.ts +0 -12
- package/lib/fs.d.ts.map +0 -1
- package/lib/fs.js +0 -41
- package/lib/fs.js.map +0 -1
- package/lib/github/client.d.ts.map +0 -1
- package/lib/github/client.js.map +0 -1
- package/lib/github/index.d.ts.map +0 -1
- package/lib/github/index.js.map +0 -1
- package/lib/github/secret.d.ts.map +0 -1
- package/lib/github/secret.js.map +0 -1
- package/lib/global.d.ts +0 -16
- package/lib/global.d.ts.map +0 -1
- package/lib/global.js +0 -42
- package/lib/global.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/input.d.ts +0 -7
- package/lib/input.d.ts.map +0 -1
- package/lib/input.js +0 -2
- package/lib/input.js.map +0 -1
- package/lib/main.d.ts +0 -3
- package/lib/main.d.ts.map +0 -1
- package/lib/main.js +0 -32
- package/lib/main.js.map +0 -1
- package/lib/output.d.ts +0 -25
- package/lib/output.d.ts.map +0 -1
- package/lib/output.js +0 -23
- package/lib/output.js.map +0 -1
- package/lib/print.d.ts +0 -7
- package/lib/print.d.ts.map +0 -1
- package/lib/print.js +0 -10
- package/lib/print.js.map +0 -1
- package/lib/resource.d.ts.map +0 -1
- package/lib/resource.js.map +0 -1
- package/lib/scope.d.ts.map +0 -1
- package/lib/scope.js.map +0 -1
- package/lib/secret.d.ts.map +0 -1
- package/lib/secret.js.map +0 -1
- package/lib/serde.d.ts +0 -3
- package/lib/serde.d.ts.map +0 -1
- package/lib/serde.js.map +0 -1
- package/lib/slug.d.ts +0 -2
- package/lib/slug.d.ts.map +0 -1
- package/lib/slug.js +0 -4
- package/lib/slug.js.map +0 -1
- package/lib/state.d.ts.map +0 -1
- package/lib/state.js.map +0 -1
- package/lib/stripe/index.d.ts.map +0 -1
- package/lib/stripe/index.js.map +0 -1
- package/lib/stripe/price.d.ts.map +0 -1
- package/lib/stripe/price.js.map +0 -1
- package/lib/stripe/product.d.ts.map +0 -1
- package/lib/stripe/product.js.map +0 -1
- package/lib/stripe/webhook.d.ts.map +0 -1
- package/lib/stripe/webhook.js.map +0 -1
- package/lib/utils/content-type.d.ts.map +0 -1
- package/lib/utils/content-type.js.map +0 -1
- package/lib/utils/retry.d.ts.map +0 -1
- package/lib/utils/retry.js.map +0 -1
- package/src/$.ts +0 -69
- package/src/alchemize.ts +0 -195
- package/src/fs.ts +0 -47
- package/src/global.ts +0 -63
- package/src/input.ts +0 -19
- package/src/main.ts +0 -34
- package/src/output.ts +0 -75
- package/src/print.ts +0 -18
- package/src/serde.ts +0 -46
- package/src/slug.ts +0 -3
- /package/src/{utils → util}/content-type.ts +0 -0
- /package/src/{encrypt.ts → util/encrypt.ts} +0 -0
- /package/src/{error.ts → util/ignore.ts} +0 -0
- /package/src/{utils → util}/retry.ts +0 -0
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import * as esbuild from "esbuild";
|
|
2
|
+
import type { Context } from "../context";
|
|
3
|
+
import { Resource } from "../resource";
|
|
2
4
|
export interface BundleProps {
|
|
3
5
|
/**
|
|
4
6
|
* Entry point for the bundle
|
|
@@ -41,7 +43,7 @@ export interface BundleProps {
|
|
|
41
43
|
*/
|
|
42
44
|
options?: Partial<esbuild.BuildOptions>;
|
|
43
45
|
}
|
|
44
|
-
export interface
|
|
46
|
+
export interface Bundle extends Resource<"esbuild::Bundle"> {
|
|
45
47
|
/**
|
|
46
48
|
* Path to the bundled file
|
|
47
49
|
*/
|
|
@@ -51,21 +53,7 @@ export interface BundleOutput {
|
|
|
51
53
|
*/
|
|
52
54
|
hash: string;
|
|
53
55
|
}
|
|
54
|
-
declare const
|
|
55
|
-
export declare class Bundle extends Bundle_base {
|
|
56
|
-
/**
|
|
57
|
-
* Get the metafile from the last build
|
|
58
|
-
*/
|
|
59
|
-
getMetafile(ctx: {
|
|
60
|
-
get<T>(key: string): Promise<T | undefined>;
|
|
61
|
-
}): Promise<esbuild.Metafile | undefined>;
|
|
62
|
-
/**
|
|
63
|
-
* Get the hash from the last build
|
|
64
|
-
*/
|
|
65
|
-
getHash(ctx: {
|
|
66
|
-
get<T>(key: string): Promise<T | undefined>;
|
|
67
|
-
}): Promise<string | undefined>;
|
|
68
|
-
}
|
|
56
|
+
export declare const Bundle: ((this: Context<Bundle>, id: string, props: BundleProps) => Promise<Bundle>) | (((this: any, id: string, props: BundleProps) => never) & (new (_: never) => never));
|
|
69
57
|
export declare function bundle(props: BundleProps): Promise<esbuild.BuildResult<{
|
|
70
58
|
bundle: boolean;
|
|
71
59
|
splitting?: boolean;
|
|
@@ -148,5 +136,3 @@ export declare function bundle(props: BundleProps): Promise<esbuild.BuildResult<
|
|
|
148
136
|
logOverride?: Record<string, esbuild.LogLevel>;
|
|
149
137
|
tsconfigRaw?: string | esbuild.TsconfigRaw;
|
|
150
138
|
}>>;
|
|
151
|
-
export {};
|
|
152
|
-
//# sourceMappingURL=esbuild.d.ts.map
|
|
@@ -2,46 +2,33 @@ import * as esbuild from "esbuild";
|
|
|
2
2
|
import crypto from "node:crypto";
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
|
-
import { Resource } from "
|
|
6
|
-
export
|
|
5
|
+
import { Resource } from "../resource";
|
|
6
|
+
export const Bundle = Resource("esbuild::Bundle", {
|
|
7
7
|
alwaysUpdate: true,
|
|
8
|
-
}, async (
|
|
8
|
+
}, async function (id, props) {
|
|
9
9
|
// Determine output path
|
|
10
10
|
const outputPath = getOutputPath(props);
|
|
11
11
|
// Ensure output directory exists
|
|
12
12
|
await fs.promises.mkdir(path.dirname(outputPath), { recursive: true });
|
|
13
|
-
if (
|
|
13
|
+
if (this.phase === "delete") {
|
|
14
14
|
await fs.promises.unlink(outputPath).catch(() => { });
|
|
15
15
|
// Also clean up sourcemap if it exists
|
|
16
16
|
await fs.promises.unlink(outputPath + ".map").catch(() => { });
|
|
17
|
-
return
|
|
17
|
+
return this.destroy();
|
|
18
18
|
}
|
|
19
19
|
const result = await bundle(props);
|
|
20
20
|
// Calculate hash of the output
|
|
21
21
|
const contents = await fs.promises.readFile(outputPath);
|
|
22
22
|
const hash = crypto.createHash("sha256").update(contents).digest("hex");
|
|
23
23
|
// Store metadata in context
|
|
24
|
-
await
|
|
25
|
-
await
|
|
24
|
+
await this.set("metafile", result.metafile);
|
|
25
|
+
await this.set("hash", hash);
|
|
26
26
|
// Return output info
|
|
27
|
-
return {
|
|
27
|
+
return this({
|
|
28
28
|
path: outputPath,
|
|
29
29
|
hash,
|
|
30
|
-
};
|
|
31
|
-
})
|
|
32
|
-
/**
|
|
33
|
-
* Get the metafile from the last build
|
|
34
|
-
*/
|
|
35
|
-
async getMetafile(ctx) {
|
|
36
|
-
return ctx.get("metafile");
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Get the hash from the last build
|
|
40
|
-
*/
|
|
41
|
-
async getHash(ctx) {
|
|
42
|
-
return ctx.get("hash");
|
|
43
|
-
}
|
|
44
|
-
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
45
32
|
export async function bundle(props) {
|
|
46
33
|
const outputPath = getOutputPath(props);
|
|
47
34
|
// Build the bundle
|
|
@@ -64,4 +51,3 @@ function getOutputPath(props) {
|
|
|
64
51
|
return (props.outfile ||
|
|
65
52
|
path.join(props.outdir || "dist", path.basename(props.entryPoint, path.extname(props.entryPoint)) + ".js"));
|
|
66
53
|
}
|
|
67
|
-
//# sourceMappingURL=esbuild.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./bundle";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./bundle";
|
package/lib/fs/file.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Context } from "../context";
|
|
2
|
+
import { Resource } from "../resource";
|
|
3
|
+
export interface File extends Resource<"fs::File"> {
|
|
4
|
+
path: string;
|
|
5
|
+
content: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const File: ((this: Context<File>, id: string, { path: filePath, content, }: {
|
|
8
|
+
path: string;
|
|
9
|
+
content: string;
|
|
10
|
+
}) => Promise<File>) | (((this: any, id: string, props: {
|
|
11
|
+
path: string;
|
|
12
|
+
content: string;
|
|
13
|
+
}) => never) & (new (_: never) => never));
|
package/lib/fs/file.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { Resource } from "../resource";
|
|
4
|
+
import { ignore } from "../util/ignore";
|
|
5
|
+
export const File = Resource("fs::File", async function (id, { path: filePath, content, }) {
|
|
6
|
+
if (this.phase === "delete") {
|
|
7
|
+
await ignore("ENOENT", async () => fs.promises.unlink(filePath));
|
|
8
|
+
return this.destroy();
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
await fs.promises.mkdir(path.dirname(filePath), {
|
|
12
|
+
recursive: true,
|
|
13
|
+
});
|
|
14
|
+
await fs.promises.writeFile(filePath, content);
|
|
15
|
+
}
|
|
16
|
+
return this({
|
|
17
|
+
path: filePath,
|
|
18
|
+
content,
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Context } from "../context";
|
|
2
|
+
import { Resource } from "../resource";
|
|
3
|
+
export interface Folder extends Resource<"fs::Folder"> {
|
|
4
|
+
path: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const Folder: ((this: Context<Folder>, id: string, { path: dirPath }: {
|
|
7
|
+
path: string;
|
|
8
|
+
}) => Promise<Folder>) | (((this: any, id: string, props: {
|
|
9
|
+
path: string;
|
|
10
|
+
}) => never) & (new (_: never) => never));
|
package/lib/fs/folder.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { Resource } from "../resource";
|
|
3
|
+
import { ignore } from "../util/ignore";
|
|
4
|
+
export const Folder = Resource("fs::Folder", async function (id, { path: dirPath }) {
|
|
5
|
+
if (this.phase === "delete") {
|
|
6
|
+
// we just do a best effort attempt
|
|
7
|
+
await ignore(["ENOENT", "ENOTEMPTY"], async () => fs.promises.rmdir(dirPath));
|
|
8
|
+
return this.destroy();
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
await ignore("EEXIST", async () => fs.promises.mkdir(dirPath, { recursive: true }));
|
|
12
|
+
}
|
|
13
|
+
return this({
|
|
14
|
+
path: dirPath,
|
|
15
|
+
});
|
|
16
|
+
});
|
package/lib/fs/index.js
ADDED
package/lib/github/client.d.ts
CHANGED
package/lib/github/client.js
CHANGED
package/lib/github/index.d.ts
CHANGED
package/lib/github/index.js
CHANGED
package/lib/github/secret.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { Context } from "../context";
|
|
2
|
+
import { Resource } from "../resource";
|
|
1
3
|
import type { Secret } from "../secret";
|
|
2
4
|
/**
|
|
3
5
|
* Properties for creating or updating a GitHub Secret
|
|
@@ -27,7 +29,7 @@ export interface GitHubSecretProps {
|
|
|
27
29
|
/**
|
|
28
30
|
* Output returned after Secret creation/update
|
|
29
31
|
*/
|
|
30
|
-
export interface GitHubSecretOutput extends Omit<GitHubSecretProps, "value"> {
|
|
32
|
+
export interface GitHubSecretOutput extends Resource<"github::Secret">, Omit<GitHubSecretProps, "value"> {
|
|
31
33
|
/**
|
|
32
34
|
* The ID of the resource
|
|
33
35
|
*/
|
|
@@ -37,11 +39,7 @@ export interface GitHubSecretOutput extends Omit<GitHubSecretProps, "value"> {
|
|
|
37
39
|
*/
|
|
38
40
|
updatedAt: string;
|
|
39
41
|
}
|
|
40
|
-
declare const GitHubSecret_base: import("../resource").Provider<"github::Secret", [props: GitHubSecretProps], GitHubSecretOutput>;
|
|
41
42
|
/**
|
|
42
43
|
* Resource for managing GitHub repository secrets
|
|
43
44
|
*/
|
|
44
|
-
export declare
|
|
45
|
-
}
|
|
46
|
-
export {};
|
|
47
|
-
//# sourceMappingURL=secret.d.ts.map
|
|
45
|
+
export declare const GitHubSecret: ((this: Context<GitHubSecretOutput>, id: string, props: GitHubSecretProps) => Promise<GitHubSecretOutput>) | (((this: any, id: string, props: GitHubSecretProps) => never) & (new (_: never) => never));
|
package/lib/github/secret.js
CHANGED
|
@@ -4,15 +4,16 @@ import { createGitHubClient, verifyGitHubAuth } from "./client";
|
|
|
4
4
|
/**
|
|
5
5
|
* Resource for managing GitHub repository secrets
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
7
|
+
export const GitHubSecret = Resource("github::Secret", async function (id, props) {
|
|
8
8
|
// Create authenticated Octokit client - will automatically handle token resolution
|
|
9
|
+
/// TODO: use fetch
|
|
9
10
|
const octokit = await createGitHubClient({ token: props.token });
|
|
10
11
|
// Verify authentication and permissions
|
|
11
|
-
if (!
|
|
12
|
+
if (!this.quiet) {
|
|
12
13
|
await verifyGitHubAuth(octokit, props.owner, props.repository);
|
|
13
14
|
}
|
|
14
|
-
if (
|
|
15
|
-
if (
|
|
15
|
+
if (this.phase === "delete") {
|
|
16
|
+
if (this.output?.id) {
|
|
16
17
|
try {
|
|
17
18
|
// Delete the secret
|
|
18
19
|
await octokit.rest.actions.deleteRepoSecret({
|
|
@@ -32,7 +33,7 @@ export class GitHubSecret extends Resource("github::Secret", async (ctx, props)
|
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
// Return void (a deleted resource has no content)
|
|
35
|
-
return
|
|
36
|
+
return this.destroy();
|
|
36
37
|
}
|
|
37
38
|
else {
|
|
38
39
|
try {
|
|
@@ -44,7 +45,7 @@ export class GitHubSecret extends Resource("github::Secret", async (ctx, props)
|
|
|
44
45
|
// Encrypt the secret value using libsodium
|
|
45
46
|
const encryptedValue = await encryptString(props.value.unencrypted, publicKey.key);
|
|
46
47
|
// Create or update the secret with the encrypted value and key_id
|
|
47
|
-
|
|
48
|
+
await octokit.rest.actions.createOrUpdateRepoSecret({
|
|
48
49
|
owner: props.owner,
|
|
49
50
|
repo: props.repository,
|
|
50
51
|
secret_name: props.name,
|
|
@@ -52,15 +53,14 @@ export class GitHubSecret extends Resource("github::Secret", async (ctx, props)
|
|
|
52
53
|
key_id: publicKey.key_id,
|
|
53
54
|
});
|
|
54
55
|
// GitHub doesn't return the secret details on create/update, so we need to construct it
|
|
55
|
-
|
|
56
|
+
return this({
|
|
56
57
|
id: `${props.owner}/${props.repository}/${props.name}`,
|
|
57
58
|
owner: props.owner,
|
|
58
59
|
repository: props.repository,
|
|
59
60
|
name: props.name,
|
|
60
61
|
token: props.token,
|
|
61
62
|
updatedAt: new Date().toISOString(),
|
|
62
|
-
};
|
|
63
|
-
return output;
|
|
63
|
+
});
|
|
64
64
|
}
|
|
65
65
|
catch (error) {
|
|
66
66
|
if (error.status === 403 &&
|
|
@@ -74,8 +74,7 @@ export class GitHubSecret extends Resource("github::Secret", async (ctx, props)
|
|
|
74
74
|
throw error;
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
-
})
|
|
78
|
-
}
|
|
77
|
+
});
|
|
79
78
|
/**
|
|
80
79
|
* Encrypt a value for GitHub using libsodium
|
|
81
80
|
* Based on GitHub's documentation for encrypting secrets
|
|
@@ -96,4 +95,3 @@ async function encryptString(value, publicKey) {
|
|
|
96
95
|
// Convert the encrypted message to base64
|
|
97
96
|
return sodium.to_base64(encryptedBin, sodium.base64_variants.ORIGINAL);
|
|
98
97
|
}
|
|
99
|
-
//# sourceMappingURL=secret.js.map
|
package/lib/index.d.ts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
export * from "
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./error";
|
|
4
|
-
export * from "./global";
|
|
5
|
-
export * from "./input";
|
|
6
|
-
export * from "./output";
|
|
7
|
-
export * from "./print";
|
|
8
|
-
export { Resource, type Context, type CreateContext, type DeleteContext, type UpdateContext, } from "./resource";
|
|
1
|
+
export type * from "./context";
|
|
2
|
+
export * from "./resource";
|
|
9
3
|
export * from "./secret";
|
|
10
|
-
export
|
|
11
|
-
|
|
4
|
+
export * from "./state";
|
|
5
|
+
export * from "./util/ignore";
|
|
6
|
+
import { alchemy } from "./alchemy";
|
|
7
|
+
export default alchemy;
|
package/lib/index.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
export * from "
|
|
2
|
-
export * from "./alchemize";
|
|
3
|
-
export * from "./error";
|
|
4
|
-
export * from "./global";
|
|
5
|
-
export * from "./input";
|
|
6
|
-
export * from "./output";
|
|
7
|
-
export * from "./print";
|
|
8
|
-
export { Resource, } from "./resource";
|
|
1
|
+
export * from "./resource";
|
|
9
2
|
export * from "./secret";
|
|
10
|
-
|
|
3
|
+
export * from "./state";
|
|
4
|
+
export * from "./util/ignore";
|
|
5
|
+
import { alchemy } from "./alchemy";
|
|
6
|
+
export default alchemy;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./vite";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./vite";
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Context } from "../context";
|
|
2
|
+
import { Resource } from "../resource";
|
|
3
|
+
type ViteTemplate = "vanilla" | "vanilla-ts" | "vue" | "vue-ts" | "react" | "react-ts" | "react-swc" | "react-swc-ts" | "preact" | "preact-ts" | "lit" | "lit-ts" | "svelte" | "svelte-ts" | "solid" | "solid-ts" | "qwik" | "qwik-ts";
|
|
4
|
+
export interface ViteProjectProps {
|
|
5
|
+
/**
|
|
6
|
+
* The name/path of the project
|
|
7
|
+
*/
|
|
8
|
+
name: string;
|
|
9
|
+
/**
|
|
10
|
+
* The Vite template to use
|
|
11
|
+
*/
|
|
12
|
+
template: ViteTemplate;
|
|
13
|
+
/**
|
|
14
|
+
* The extends to add to the tsconfig.json file
|
|
15
|
+
*/
|
|
16
|
+
extends?: string;
|
|
17
|
+
/**
|
|
18
|
+
* The references to add to the tsconfig.json file
|
|
19
|
+
*/
|
|
20
|
+
references?: string[];
|
|
21
|
+
/**
|
|
22
|
+
* @default false
|
|
23
|
+
*/
|
|
24
|
+
tailwind?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Force overwrite the project config tfiles during the update phase
|
|
27
|
+
*
|
|
28
|
+
* @default false
|
|
29
|
+
*/
|
|
30
|
+
overwrite?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface ViteProject extends ViteProjectProps, Resource {
|
|
33
|
+
/**
|
|
34
|
+
* The name/path of the project
|
|
35
|
+
*/
|
|
36
|
+
name: string;
|
|
37
|
+
}
|
|
38
|
+
export declare const ViteProject: ((this: Context<ViteProject>, id: string, props: ViteProjectProps) => Promise<ViteProject>) | (((this: any, id: string, props: ViteProjectProps) => never) & (new (_: never) => never));
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { exec } from "child_process";
|
|
2
|
+
import fs from "fs/promises";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { promisify } from "util";
|
|
5
|
+
import { Resource } from "../resource";
|
|
6
|
+
import { rm } from "../util/rm";
|
|
7
|
+
const execAsync = promisify(exec);
|
|
8
|
+
export const ViteProject = Resource("project::ViteProject", async function (id, props) {
|
|
9
|
+
if (this.phase === "delete") {
|
|
10
|
+
try {
|
|
11
|
+
if (await fs.exists(props.name)) {
|
|
12
|
+
// TODO: OS agnostic - fs.rm is slow to delete node_modules/
|
|
13
|
+
await execAsync("rm -rf " + props.name);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
console.error(`Error deleting project ${id}:`, error);
|
|
18
|
+
}
|
|
19
|
+
return this.destroy();
|
|
20
|
+
}
|
|
21
|
+
if (this.phase === "update") {
|
|
22
|
+
if (props.overwrite) {
|
|
23
|
+
await modifyConfig(props);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
console.warn("ViteProject does not support updates - the project must be recreated to change the template");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
// Create phase
|
|
31
|
+
await execAsync(`bun create vite ${id} --template ${props.template}`);
|
|
32
|
+
await modifyConfig(props);
|
|
33
|
+
}
|
|
34
|
+
return this(props);
|
|
35
|
+
});
|
|
36
|
+
async function modifyConfig(props) {
|
|
37
|
+
if (props.tailwind) {
|
|
38
|
+
await execAsync(`bun add tailwindcss @tailwindcss/vite`);
|
|
39
|
+
await fs.writeFile(path.join(props.name, "vite.config.ts"), `import tailwindcss from "@tailwindcss/vite";
|
|
40
|
+
import react from "@vitejs/plugin-react";
|
|
41
|
+
import { defineConfig } from "vite";
|
|
42
|
+
|
|
43
|
+
// https://vite.dev/config/
|
|
44
|
+
export default defineConfig({
|
|
45
|
+
plugins: [react(), tailwindcss()],
|
|
46
|
+
});`);
|
|
47
|
+
// Add Tailwind CSS import to index.css
|
|
48
|
+
const indexCssPath = path.join(props.name, "src", "index.css");
|
|
49
|
+
const currentCss = await fs.readFile(indexCssPath, "utf-8");
|
|
50
|
+
if (!currentCss.includes('@import "tailwindcss";')) {
|
|
51
|
+
await fs.writeFile(indexCssPath, '@import "tailwindcss";\n\n' + currentCss);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
await Promise.all([
|
|
55
|
+
rm(path.join(props.name, "tsconfig.app.json")),
|
|
56
|
+
rm(path.join(props.name, "tsconfig.node.json")),
|
|
57
|
+
fs.writeFile(path.join(props.name, "tsconfig.json"), JSON.stringify({
|
|
58
|
+
extends: props.extends,
|
|
59
|
+
compilerOptions: {
|
|
60
|
+
types: ["@cloudflare/workers-types"],
|
|
61
|
+
allowImportingTsExtensions: true,
|
|
62
|
+
jsx: "react-jsx",
|
|
63
|
+
},
|
|
64
|
+
include: ["vite/*.ts", "src/**/*.ts", "src/**/*.tsx", "src/env.d.ts"],
|
|
65
|
+
references: props.references?.map((path) => ({ path })),
|
|
66
|
+
}, null, 2)),
|
|
67
|
+
]);
|
|
68
|
+
}
|
package/lib/resource.d.ts
CHANGED
|
@@ -1,71 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import { type Export, type Output, type Resolved } from "./output";
|
|
5
|
-
import { type Scope as IScope } from "./scope";
|
|
6
|
-
import type { State, StateStore } from "./state";
|
|
1
|
+
import type { Context } from "./context";
|
|
2
|
+
import { Scope as _Scope } from "./scope";
|
|
3
|
+
export declare const PROVIDERS: Map<string, any>;
|
|
7
4
|
export type ResourceID = string;
|
|
8
5
|
export type ResourceFQN = string;
|
|
9
|
-
export type
|
|
10
|
-
export declare const ResourceID: unique symbol;
|
|
11
|
-
export declare const ResourceFQN: unique symbol;
|
|
12
|
-
export declare const ResourceHandle: unique symbol;
|
|
13
|
-
export declare const Provider: unique symbol;
|
|
14
|
-
export declare const Input: unique symbol;
|
|
15
|
-
export declare const Value: unique symbol;
|
|
16
|
-
export declare const Apply: unique symbol;
|
|
17
|
-
export declare const Provide: unique symbol;
|
|
18
|
-
export declare const Scope: unique symbol;
|
|
19
|
-
export declare const Options: unique symbol;
|
|
6
|
+
export type ResourceKind = string;
|
|
20
7
|
export interface ProviderOptions {
|
|
21
8
|
/**
|
|
22
9
|
* If true, the resource will be updated even if the inputs have not changed.
|
|
23
10
|
*/
|
|
24
11
|
alwaysUpdate: boolean;
|
|
25
12
|
}
|
|
26
|
-
export type
|
|
27
|
-
[
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
[Value]?: Out;
|
|
31
|
-
[Apply]: <O>(value: Out) => O;
|
|
32
|
-
[Provide]: (value: Out) => void;
|
|
33
|
-
[Options]: ProviderOptions;
|
|
34
|
-
} & Output<Out> & Export<Resolved<Out>>;
|
|
35
|
-
export interface BaseContext {
|
|
36
|
-
quiet: boolean;
|
|
37
|
-
stage: string;
|
|
38
|
-
resourceID: ResourceID;
|
|
39
|
-
resourceFQN: ResourceFQN;
|
|
40
|
-
scope: IScope;
|
|
41
|
-
get<T>(key: string): Promise<T | undefined>;
|
|
42
|
-
set<T>(key: string, value: T): Promise<void>;
|
|
43
|
-
delete<T>(key: string): Promise<T | undefined>;
|
|
44
|
-
/**
|
|
45
|
-
* Indicate that this resource is being replaced.
|
|
46
|
-
* This will cause the resource to be deleted at the end of the stack's CREATE phase.
|
|
47
|
-
*/
|
|
48
|
-
replace(): void;
|
|
49
|
-
}
|
|
50
|
-
export interface CreateContext extends BaseContext {
|
|
51
|
-
event: "create";
|
|
52
|
-
output?: undefined;
|
|
53
|
-
}
|
|
54
|
-
export interface UpdateContext<Outputs> extends BaseContext {
|
|
55
|
-
event: "update";
|
|
56
|
-
output: Outputs;
|
|
57
|
-
}
|
|
58
|
-
export interface DeleteContext<Outputs> extends BaseContext {
|
|
59
|
-
event: "delete";
|
|
60
|
-
output: Outputs;
|
|
61
|
-
}
|
|
62
|
-
export type Context<Outputs> = CreateContext | UpdateContext<Outputs> | DeleteContext<Outputs>;
|
|
63
|
-
export type Provider<Type extends ResourceType = ResourceType, In extends any[] = any[], Out = any> = {
|
|
13
|
+
export type ResourceProps = {
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
};
|
|
16
|
+
export type Provider<Type extends string = string, F extends ResourceLifecycleHandler = ResourceLifecycleHandler> = F & IsClass & {
|
|
64
17
|
type: Type;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
export
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
18
|
+
options: Partial<ProviderOptions> | undefined;
|
|
19
|
+
handler: F;
|
|
20
|
+
};
|
|
21
|
+
export type PendingResource<Out = unknown, Kind extends ResourceKind = ResourceKind, ID extends ResourceID = ResourceID, FQN extends ResourceFQN = ResourceFQN, Scope extends _Scope = _Scope, Seq extends number = number> = Promise<Out> & {
|
|
22
|
+
Kind: Kind;
|
|
23
|
+
ID: ID;
|
|
24
|
+
FQN: FQN;
|
|
25
|
+
Seq: Seq;
|
|
26
|
+
Scope: Scope;
|
|
27
|
+
signal: () => void;
|
|
28
|
+
};
|
|
29
|
+
export interface Resource<Kind extends ResourceKind = ResourceKind, ID extends ResourceID = ResourceID, FQN extends ResourceFQN = ResourceFQN, Scope extends _Scope = _Scope, Seq extends number = number> {
|
|
30
|
+
Kind: Kind;
|
|
31
|
+
ID: ID;
|
|
32
|
+
FQN: FQN;
|
|
33
|
+
Scope: Scope;
|
|
34
|
+
Seq: Seq;
|
|
35
|
+
}
|
|
36
|
+
type IsClass = {
|
|
37
|
+
new (_: never): never;
|
|
38
|
+
};
|
|
39
|
+
type ResourceLifecycleHandler = (this: Context<any>, id: string, props: any) => Promise<Resource<string>>;
|
|
40
|
+
type Handler<F extends (...args: any[]) => any> = F | (((this: any, id: string, props: Parameters<F>[1]) => never) & IsClass);
|
|
41
|
+
export declare function Resource<const Type extends string, F extends ResourceLifecycleHandler>(type: Type, fn: F): Handler<F>;
|
|
42
|
+
export declare function Resource<const Type extends string, F extends ResourceLifecycleHandler>(type: Type, options: Partial<ProviderOptions>, fn: F): Handler<F>;
|
|
43
|
+
export {};
|