@graftland/cli 0.0.0-stage → 0.2.0-beta.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/LICENSE +202 -0
- package/README.md +22 -2
- package/README.zh-CN.md +22 -0
- package/README.zh-TW.md +22 -0
- package/dist/Manage.d.ts +13 -0
- package/dist/Manage.d.ts.map +1 -0
- package/dist/Manage.js +49 -0
- package/dist/Manage.js.map +1 -0
- package/dist/Start.d.ts +25 -0
- package/dist/Start.d.ts.map +1 -0
- package/dist/Start.js +58 -0
- package/dist/Start.js.map +1 -0
- package/dist/_virtual/_rolldown/runtime.js +12 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +36 -0
- package/dist/bin.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/internal/configSchema.d.ts +7 -0
- package/dist/internal/configSchema.d.ts.map +1 -0
- package/dist/internal/configSchema.js +44 -0
- package/dist/internal/configSchema.js.map +1 -0
- package/dist/internal/env.js +50 -0
- package/dist/internal/env.js.map +1 -0
- package/dist/internal/intercepts.js +12 -0
- package/dist/internal/intercepts.js.map +1 -0
- package/dist/internal/watch.js +25 -0
- package/dist/internal/watch.js.map +1 -0
- package/dist/package.js +5 -0
- package/dist/package.js.map +1 -0
- package/package.json +49 -3
- package/schema.json +178 -0
- package/src/Manage.ts +85 -0
- package/src/Start.ts +97 -0
- package/src/bin.ts +83 -0
- package/src/index.ts +5 -0
- package/src/internal/configSchema.ts +85 -0
- package/src/internal/env.ts +163 -0
- package/src/internal/intercepts.ts +23 -0
- package/src/internal/watch.ts +58 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Cause, ConfigProvider, Context, Deferred, Effect, Exit, FileSystem, Layer, Path, Queue, Ref, Stream } from "effect";
|
|
2
|
+
// src/internal/env.ts
|
|
3
|
+
const options = { preserveEmptyStrings: true };
|
|
4
|
+
var EnvFile = class extends Context.Service()("@graftland/cli/internal/env/EnvFile") {};
|
|
5
|
+
/** Provides `ConfigProvider` and `EnvFile`; a missing file fails the layer. */
|
|
6
|
+
const layer = (file) => Layer.unwrap(Effect.gen(function* () {
|
|
7
|
+
const environment = ConfigProvider.fromEnv(options);
|
|
8
|
+
if (file === void 0) return Layer.merge(ConfigProvider.layer(environment), Layer.succeed(EnvFile, { reload: Effect.succeed(false) }));
|
|
9
|
+
const fs = yield* FileSystem.FileSystem;
|
|
10
|
+
const read = Effect.gen(function* () {
|
|
11
|
+
const target = yield* fs.realPath(file);
|
|
12
|
+
const text = yield* fs.readFileString(target);
|
|
13
|
+
return {
|
|
14
|
+
target,
|
|
15
|
+
text,
|
|
16
|
+
provider: ConfigProvider.fromDotEnvContents(text, options)
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
const initial = yield* read;
|
|
20
|
+
const loaded = yield* Ref.make(initial);
|
|
21
|
+
const fromFile = ConfigProvider.make((path) => Effect.flatMap(Ref.get(loaded), ({ provider }) => provider.load(path)));
|
|
22
|
+
return Layer.merge(ConfigProvider.layer(ConfigProvider.orElse(environment, fromFile)), Layer.succeed(EnvFile, { reload: Effect.gen(function* () {
|
|
23
|
+
const next = yield* read;
|
|
24
|
+
const previous = yield* Ref.getAndSet(loaded, next);
|
|
25
|
+
return next.text !== previous.text;
|
|
26
|
+
}) }));
|
|
27
|
+
}));
|
|
28
|
+
/**
|
|
29
|
+
* The handlers below let interruption through, and with it any failure raised
|
|
30
|
+
* while stopping. Log those; failures without interruption are handled there.
|
|
31
|
+
*/
|
|
32
|
+
const logStopped = (file) => (exit) => Exit.isFailure(exit) && Cause.hasInterrupts(exit.cause) && (Cause.hasFails(exit.cause) || Cause.hasDies(exit.cause)) ? Effect.logError(`Watching ${file} stopped with a failure`, exit.cause) : Effect.void;
|
|
33
|
+
/**
|
|
34
|
+
* Reloads the file when it changes and retries the loader's entries, which
|
|
35
|
+
* reads `!env` again. A file that cannot be read keeps its previous values.
|
|
36
|
+
*/
|
|
37
|
+
const watchEnvFile = (file, reload, retry) => Effect.gen(function* () {
|
|
38
|
+
const fs = yield* FileSystem.FileSystem;
|
|
39
|
+
const path = yield* Path.Path;
|
|
40
|
+
const ready = yield* Deferred.make();
|
|
41
|
+
const events = Stream.callback((queue) => fs.watch(path.dirname(file), { onReady: () => Deferred.doneUnsafe(ready, Effect.void) }).pipe(Stream.filter((event) => path.basename(event.path) === path.basename(file)), Stream.runForEachArray((events) => Queue.offerAll(queue, events)), Effect.scoped, Effect.onExit(logStopped(file)), Effect.catchCauseIf((cause) => !Cause.hasInterrupts(cause), (cause) => Effect.logError(`Watching ${file} failed`, cause)), Effect.andThen(Effect.sleep("1 second")), Effect.forever), { bufferSize: 16 });
|
|
42
|
+
yield* Stream.mergeAll([
|
|
43
|
+
Stream.as(events, void 0),
|
|
44
|
+
Stream.fromEffect(Deferred.await(ready)),
|
|
45
|
+
Stream.tick("1 second").pipe(Stream.drop(1))
|
|
46
|
+
], { concurrency: "unbounded" }).pipe(Stream.runForEach(() => Effect.sleep("100 millis").pipe(Effect.andThen(reload), Effect.flatMap((changed) => changed ? retry : Effect.void), Effect.catchCauseIf((cause) => !Cause.hasInterrupts(cause), (cause) => Effect.logError(`Reloading ${file} failed`, cause)))), Effect.catchCauseIf((cause) => !Cause.hasInterrupts(cause), (cause) => Effect.logError(`Stopped watching ${file}`, cause)));
|
|
47
|
+
}).pipe(Effect.onExit(logStopped(file)));
|
|
48
|
+
export { EnvFile, layer, watchEnvFile };
|
|
49
|
+
|
|
50
|
+
//# sourceMappingURL=env.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.js","names":[],"sources":["../../src/internal/env.ts"],"sourcesContent":["/**\n * Where `!env` values come from: the process environment, then an optional\n * `.env` file that watch mode reads again when it changes.\n */\nimport type { PlatformError } from \"effect\"\nimport {\n\tCause,\n\tConfigProvider,\n\tContext,\n\tDeferred,\n\tEffect,\n\tExit,\n\tFileSystem,\n\tLayer,\n\tPath,\n\tQueue,\n\tRef,\n\tStream,\n} from \"effect\"\n\n// An empty variable is still set: it overrides the file, and the plugin's\n// schema decides whether it is valid.\nconst options = { preserveEmptyStrings: true } as const\n\ninterface Loaded {\n\treadonly target: string\n\treadonly text: string\n\treadonly provider: ConfigProvider.ConfigProvider\n}\n\nexport class EnvFile extends Context.Service<\n\tEnvFile,\n\t{\n\t\t/** Reads the file again; reports whether its contents changed. */\n\t\treadonly reload: Effect.Effect<boolean, PlatformError.PlatformError>\n\t}\n>()(\"@graftland/cli/internal/env/EnvFile\") {}\n\n/** Provides `ConfigProvider` and `EnvFile`; a missing file fails the layer. */\nexport const layer = (file: string | undefined) =>\n\tLayer.unwrap(\n\t\tEffect.gen(function* () {\n\t\t\tconst environment = ConfigProvider.fromEnv(options)\n\t\t\tif (file === undefined)\n\t\t\t\treturn Layer.merge(\n\t\t\t\t\tConfigProvider.layer(environment),\n\t\t\t\t\tLayer.succeed(EnvFile, { reload: Effect.succeed(false) }),\n\t\t\t\t)\n\t\t\tconst fs = yield* FileSystem.FileSystem\n\t\t\t// Resolve the request on every read, including polling. Never pin a\n\t\t\t// symlink to its initial target. The provider and its baseline are\n\t\t\t// committed together from the bytes actually read.\n\t\t\tconst read = Effect.gen(function* () {\n\t\t\t\tconst target = yield* fs.realPath(file)\n\t\t\t\tconst text = yield* fs.readFileString(target)\n\t\t\t\treturn {\n\t\t\t\t\ttarget,\n\t\t\t\t\ttext,\n\t\t\t\t\tprovider: ConfigProvider.fromDotEnvContents(text, options),\n\t\t\t\t}\n\t\t\t})\n\t\t\tconst initial: Loaded = yield* read\n\t\t\tconst loaded = yield* Ref.make(initial)\n\t\t\tconst fromFile = ConfigProvider.make((path) =>\n\t\t\t\tEffect.flatMap(Ref.get(loaded), ({ provider }) => provider.load(path)),\n\t\t\t)\n\t\t\treturn Layer.merge(\n\t\t\t\tConfigProvider.layer(ConfigProvider.orElse(environment, fromFile)),\n\t\t\t\tLayer.succeed(EnvFile, {\n\t\t\t\t\treload: Effect.gen(function* () {\n\t\t\t\t\t\tconst next = yield* read\n\t\t\t\t\t\tconst previous = yield* Ref.getAndSet(loaded, next)\n\t\t\t\t\t\treturn next.text !== previous.text\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t)\n\t\t}),\n\t)\n\n/**\n * The handlers below let interruption through, and with it any failure raised\n * while stopping. Log those; failures without interruption are handled there.\n */\nconst logStopped =\n\t(file: string) =>\n\t<A, E>(exit: Exit.Exit<A, E>) =>\n\t\tExit.isFailure(exit) &&\n\t\tCause.hasInterrupts(exit.cause) &&\n\t\t(Cause.hasFails(exit.cause) || Cause.hasDies(exit.cause))\n\t\t\t? Effect.logError(`Watching ${file} stopped with a failure`, exit.cause)\n\t\t\t: Effect.void\n\n/**\n * Reloads the file when it changes and retries the loader's entries, which\n * reads `!env` again. A file that cannot be read keeps its previous values.\n */\nexport const watchEnvFile = <E, R>(\n\tfile: string,\n\treload: Effect.Effect<boolean, PlatformError.PlatformError>,\n\tretry: Effect.Effect<void, E, R>,\n) =>\n\tEffect.gen(function* () {\n\t\tconst fs = yield* FileSystem.FileSystem\n\t\tconst path = yield* Path.Path\n\t\tconst ready = yield* Deferred.make<void>()\n\t\t// As in HMR, own the source scope inside the producer. Observe its\n\t\t// complete Exit after cleanup, before merge can discard it.\n\t\tconst events = Stream.callback<\n\t\t\tFileSystem.WatchEvent,\n\t\t\tPlatformError.PlatformError\n\t\t>(\n\t\t\t(queue) =>\n\t\t\t\tfs\n\t\t\t\t\t.watch(path.dirname(file), {\n\t\t\t\t\t\tonReady: () => Deferred.doneUnsafe(ready, Effect.void),\n\t\t\t\t\t})\n\t\t\t\t\t.pipe(\n\t\t\t\t\t\tStream.filter(\n\t\t\t\t\t\t\t(event) => path.basename(event.path) === path.basename(file),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tStream.runForEachArray((events) => Queue.offerAll(queue, events)),\n\t\t\t\t\t\tEffect.scoped,\n\t\t\t\t\t\tEffect.onExit(logStopped(file)),\n\t\t\t\t\t\tEffect.catchCauseIf(\n\t\t\t\t\t\t\t(cause) => !Cause.hasInterrupts(cause),\n\t\t\t\t\t\t\t(cause) => Effect.logError(`Watching ${file} failed`, cause),\n\t\t\t\t\t\t),\n\t\t\t\t\t\t// A failed native backend must not stop content reconciliation.\n\t\t\t\t\t\tEffect.andThen(Effect.sleep(\"1 second\")),\n\t\t\t\t\t\tEffect.forever,\n\t\t\t\t\t),\n\t\t\t{ bufferSize: 16 },\n\t\t)\n\t\t// Native events accelerate updates. Poll the request too: its target\n\t\t// may live outside this directory, change, or lose a notification.\n\t\tyield* Stream.mergeAll(\n\t\t\t[\n\t\t\t\tStream.as(events, undefined),\n\t\t\t\tStream.fromEffect(Deferred.await(ready)),\n\t\t\t\tStream.tick(\"1 second\").pipe(Stream.drop(1)),\n\t\t\t],\n\t\t\t{ concurrency: \"unbounded\" },\n\t\t).pipe(\n\t\t\tStream.runForEach(() =>\n\t\t\t\t// Delay to let writes settle.\n\t\t\t\tEffect.sleep(\"100 millis\").pipe(\n\t\t\t\t\tEffect.andThen(reload),\n\t\t\t\t\tEffect.flatMap((changed) => (changed ? retry : Effect.void)),\n\t\t\t\t\tEffect.catchCauseIf(\n\t\t\t\t\t\t(cause) => !Cause.hasInterrupts(cause),\n\t\t\t\t\t\t(cause) => Effect.logError(`Reloading ${file} failed`, cause),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t),\n\t\t\tEffect.catchCauseIf(\n\t\t\t\t(cause) => !Cause.hasInterrupts(cause),\n\t\t\t\t(cause) => Effect.logError(`Stopped watching ${file}`, cause),\n\t\t\t),\n\t\t)\n\t}).pipe(\n\t\t// Observe the whole watcher before forkScoped owns it.\n\t\tEffect.onExit(logStopped(file)),\n\t)\n"],"mappings":"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"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { LogLevel, References, Schema } from "effect";
|
|
2
|
+
import { Intercept } from "@graftland/loader";
|
|
3
|
+
// src/internal/intercepts.ts
|
|
4
|
+
/** References that can be configured by stock CLI entries. */
|
|
5
|
+
const registrations = [Intercept.make(References.CurrentLogAnnotations, Schema.Record(Schema.String, Schema.Unknown).annotate({ description: "Shallowly merges with outer annotations; configured keys win." }), (outer, patch) => ({
|
|
6
|
+
...outer,
|
|
7
|
+
...patch
|
|
8
|
+
})), Intercept.make(References.MinimumLogLevel, Schema.Literals(LogLevel.values).annotate({ description: "Replaces the outer minimum log level." }), (_, level) => level)];
|
|
9
|
+
const layer = Intercept.layer(registrations);
|
|
10
|
+
export { layer, registrations };
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=intercepts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intercepts.js","names":[],"sources":["../../src/internal/intercepts.ts"],"sourcesContent":["import { Intercept } from \"@graftland/loader\"\nimport { LogLevel, References, Schema } from \"effect\"\n\n/** References that can be configured by stock CLI entries. */\nexport const registrations = [\n\tIntercept.make(\n\t\tReferences.CurrentLogAnnotations,\n\t\tSchema.Record(Schema.String, Schema.Unknown).annotate({\n\t\t\tdescription:\n\t\t\t\t\"Shallowly merges with outer annotations; configured keys win.\",\n\t\t}),\n\t\t(outer, patch) => ({ ...outer, ...patch }),\n\t),\n\tIntercept.make(\n\t\tReferences.MinimumLogLevel,\n\t\tSchema.Literals(LogLevel.values).annotate({\n\t\t\tdescription: \"Replaces the outer minimum log level.\",\n\t\t}),\n\t\t(_, level) => level,\n\t),\n]\n\nexport const layer = Intercept.layer(registrations)\n"],"mappings":";;;;AAIA,MAAa,gBAAgB,CAC5B,UAAU,KACT,WAAW,uBACX,OAAO,OAAO,OAAO,QAAQ,OAAO,OAAO,CAAC,CAAC,SAAS,EACrD,aACC,gEACF,CAAC,IACA,OAAO,WAAW;CAAE,GAAG;CAAO,GAAG;AAAM,EACzC,GACA,UAAU,KACT,WAAW,iBACX,OAAO,SAAS,SAAS,MAAM,CAAC,CAAC,SAAS,EACzC,aAAa,wCACd,CAAC,IACA,GAAG,UAAU,KACf,CACD;AAEA,MAAa,QAAQ,UAAU,MAAM,aAAa"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Array, Cause, Effect, Exit, Stream, String } from "effect";
|
|
2
|
+
// src/internal/watch.ts
|
|
3
|
+
const moduleExtensions = [
|
|
4
|
+
".js",
|
|
5
|
+
".mjs",
|
|
6
|
+
".cjs",
|
|
7
|
+
".ts",
|
|
8
|
+
".mts",
|
|
9
|
+
".cts"
|
|
10
|
+
];
|
|
11
|
+
/** Whether a change to this file should reload plugin modules. */
|
|
12
|
+
const isModule = (path) => !Array.contains(String.split(/[/\\]/)(path), "node_modules") && Array.some(moduleExtensions, (extension) => String.endsWith(extension)(path));
|
|
13
|
+
const describe = (result) => result._tag === "Reloaded" ? Effect.logInfo(`Reloaded ${result.entries.length} plugin module(s)`) : Effect.logWarning(result.reason === "ambiguous-exports" ? `Restart required: shared plugin exports diverged in ${Array.join(result.modules, ", ")}` : result.reason === "identity-conflict" ? `Restart required: plugin replacement identities conflict in ${Array.join(result.modules, ", ")}` : `Restart required to pick up ${Array.join(result.modules, ", ")}`);
|
|
14
|
+
/** Owns the HMR stream and retries failed loader entries after each reload. */
|
|
15
|
+
const watchModules = (hmr, directory, retry) => hmr.watch([directory], {
|
|
16
|
+
recursive: true,
|
|
17
|
+
filter: isModule
|
|
18
|
+
}).pipe(Stream.runForEach((result) => Effect.gen(function* () {
|
|
19
|
+
if (result._tag === "Failed") return yield* Effect.failCause(result.cause);
|
|
20
|
+
yield* describe(result);
|
|
21
|
+
yield* retry;
|
|
22
|
+
}).pipe(Effect.catchCauseIf((cause) => !Cause.hasInterrupts(cause), (cause) => Effect.logError("Reloading plugin modules failed", cause)))), Effect.catchCauseIf((cause) => !Cause.hasInterrupts(cause), (cause) => Effect.logError("Watching plugin modules failed", cause)), Effect.andThen(Effect.sleep("1 second")), Effect.forever, Effect.onExit((exit) => Exit.isFailure(exit) && (Cause.hasFails(exit.cause) || Cause.hasDies(exit.cause)) ? Effect.logError("Module watcher exited with a failure", exit.cause) : Effect.void));
|
|
23
|
+
export { isModule, watchModules };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=watch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watch.js","names":[],"sources":["../../src/internal/watch.ts"],"sourcesContent":["import type * as Hmr from \"@graftland/hmr\"\nimport { Array, Cause, Effect, Exit, Stream, String } from \"effect\"\n\nconst moduleExtensions = [\".js\", \".mjs\", \".cjs\", \".ts\", \".mts\", \".cts\"]\n\n/** Whether a change to this file should reload plugin modules. */\nexport const isModule = (path: string) =>\n\t!Array.contains(String.split(/[/\\\\]/)(path), \"node_modules\") &&\n\tArray.some(moduleExtensions, (extension) => String.endsWith(extension)(path))\n\nconst describe = (result: Hmr.ReloadResult) =>\n\tresult._tag === \"Reloaded\"\n\t\t? Effect.logInfo(`Reloaded ${result.entries.length} plugin module(s)`)\n\t\t: Effect.logWarning(\n\t\t\t\tresult.reason === \"ambiguous-exports\"\n\t\t\t\t\t? `Restart required: shared plugin exports diverged in ${Array.join(result.modules, \", \")}`\n\t\t\t\t\t: result.reason === \"identity-conflict\"\n\t\t\t\t\t\t? `Restart required: plugin replacement identities conflict in ${Array.join(result.modules, \", \")}`\n\t\t\t\t\t\t: `Restart required to pick up ${Array.join(result.modules, \", \")}`,\n\t\t\t)\n\n/** Owns the HMR stream and retries failed loader entries after each reload. */\nexport const watchModules = <E, R>(\n\thmr: Pick<Hmr.Hmr, \"watch\">,\n\tdirectory: string,\n\tretry: Effect.Effect<void, E, R>,\n) =>\n\thmr.watch([directory], { recursive: true, filter: isModule }).pipe(\n\t\tStream.runForEach((result) =>\n\t\t\tEffect.gen(function* () {\n\t\t\t\tif (result._tag === \"Failed\")\n\t\t\t\t\treturn yield* Effect.failCause(result.cause)\n\t\t\t\tyield* describe(result)\n\t\t\t\tyield* retry\n\t\t\t}).pipe(\n\t\t\t\tEffect.catchCauseIf(\n\t\t\t\t\t(cause) => !Cause.hasInterrupts(cause),\n\t\t\t\t\t(cause) => Effect.logError(\"Reloading plugin modules failed\", cause),\n\t\t\t\t),\n\t\t\t),\n\t\t),\n\t\tEffect.catchCauseIf(\n\t\t\t(cause) => !Cause.hasInterrupts(cause),\n\t\t\t(cause) => Effect.logError(\"Watching plugin modules failed\", cause),\n\t\t),\n\t\t// A backend failure ends the stream. Reinstall it after a delay rather than\n\t\t// leaving the application running without a watcher.\n\t\tEffect.andThen(Effect.sleep(\"1 second\")),\n\t\tEffect.forever,\n\t\t// onExit runs uninterruptibly, after stream cleanup. Observe the entire\n\t\t// worker before forkScoped owns it, including mixed interruption causes.\n\t\tEffect.onExit((exit) =>\n\t\t\tExit.isFailure(exit) &&\n\t\t\t(Cause.hasFails(exit.cause) || Cause.hasDies(exit.cause))\n\t\t\t\t? Effect.logError(\"Module watcher exited with a failure\", exit.cause)\n\t\t\t\t: Effect.void,\n\t\t),\n\t)\n"],"mappings":";;AAGA,MAAM,mBAAmB;CAAC;CAAO;CAAQ;CAAQ;CAAO;CAAQ;AAAM;;AAGtE,MAAa,YAAY,SACxB,CAAC,MAAM,SAAS,OAAO,MAAM,OAAO,CAAC,CAAC,IAAI,GAAG,cAAc,KAC3D,MAAM,KAAK,mBAAmB,cAAc,OAAO,SAAS,SAAS,CAAC,CAAC,IAAI,CAAC;AAE7E,MAAM,YAAY,WACjB,OAAO,SAAS,aACb,OAAO,QAAQ,YAAY,OAAO,QAAQ,OAAO,kBAAkB,IACnE,OAAO,WACP,OAAO,WAAW,sBACf,uDAAuD,MAAM,KAAK,OAAO,SAAS,IAAI,MACtF,OAAO,WAAW,sBACjB,+DAA+D,MAAM,KAAK,OAAO,SAAS,IAAI,MAC9F,+BAA+B,MAAM,KAAK,OAAO,SAAS,IAAI,GACnE;;AAGH,MAAa,gBACZ,KACA,WACA,UAEA,IAAI,MAAM,CAAC,SAAS,GAAG;CAAE,WAAW;CAAM,QAAQ;AAAS,CAAC,CAAC,CAAC,KAC7D,OAAO,YAAY,WAClB,OAAO,IAAI,aAAa;CACvB,IAAI,OAAO,SAAS,UACnB,OAAO,OAAO,OAAO,UAAU,OAAO,KAAK;CAC5C,OAAO,SAAS,MAAM;CACtB,OAAO;AACR,CAAC,CAAC,CAAC,KACF,OAAO,cACL,UAAU,CAAC,MAAM,cAAc,KAAK,IACpC,UAAU,OAAO,SAAS,mCAAmC,KAAK,CACpE,CACD,CACD,GACA,OAAO,cACL,UAAU,CAAC,MAAM,cAAc,KAAK,IACpC,UAAU,OAAO,SAAS,kCAAkC,KAAK,CACnE,GAGA,OAAO,QAAQ,OAAO,MAAM,UAAU,CAAC,GACvC,OAAO,SAGP,OAAO,QAAQ,SACd,KAAK,UAAU,IAAI,MAClB,MAAM,SAAS,KAAK,KAAK,KAAK,MAAM,QAAQ,KAAK,KAAK,KACpD,OAAO,SAAS,wCAAwC,KAAK,KAAK,IAClE,OAAO,IACX,CACD"}
|
package/dist/package.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.js","names":[],"sources":["../package.json"],"sourcesContent":[""],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graftland/cli",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0-beta.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">=22.19.0"
|
|
7
|
+
},
|
|
8
|
+
"description": "The graft command: start, create, add and remove",
|
|
9
|
+
"license": "Apache-2.0",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/graftland/graft.git",
|
|
13
|
+
"directory": "packages/cli"
|
|
14
|
+
},
|
|
15
|
+
"sideEffects": false,
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"src",
|
|
19
|
+
"schema.json",
|
|
20
|
+
"README.zh-CN.md",
|
|
21
|
+
"README.zh-TW.md"
|
|
22
|
+
],
|
|
23
|
+
"exports": {
|
|
24
|
+
".": "./dist/index.js",
|
|
25
|
+
"./bin": "./dist/bin.js",
|
|
26
|
+
"./internal/configSchema": "./dist/internal/configSchema.js",
|
|
27
|
+
"./package.json": "./package.json"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"effect": "4.1.*"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@effect/vitest": "4.1.2",
|
|
34
|
+
"effect": "4.1.2",
|
|
35
|
+
"vitest": "5.1.0"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@graftland/graft": "0.2.0-beta.0",
|
|
39
|
+
"@graftland/loader": "0.2.0-beta.0",
|
|
40
|
+
"@graftland/hmr": "0.2.0-beta.0",
|
|
41
|
+
"@graftland/create": "0.2.0-beta.0",
|
|
42
|
+
"@graftland/package-manager": "0.2.0-beta.0",
|
|
43
|
+
"@effect/platform-node": "4.1.2"
|
|
44
|
+
},
|
|
45
|
+
"bin": {
|
|
46
|
+
"graft": "./dist/bin.js"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "tsdown && node scripts/schema.mjs",
|
|
50
|
+
"test": "vitest run"
|
|
51
|
+
}
|
|
6
52
|
}
|
package/schema.json
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"anyOf": [
|
|
4
|
+
{
|
|
5
|
+
"type": "array",
|
|
6
|
+
"items": {
|
|
7
|
+
"$ref": "#/definitions/Entry"
|
|
8
|
+
}
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"type": "null"
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"title": "Graft config file",
|
|
15
|
+
"description": "The entries that graft start loads. Each entry loads one plugin, or groups other entries.",
|
|
16
|
+
"definitions": {
|
|
17
|
+
"Intercept": {
|
|
18
|
+
"type": "object",
|
|
19
|
+
"properties": {
|
|
20
|
+
"effect/References/CurrentLogAnnotations": {
|
|
21
|
+
"type": "object",
|
|
22
|
+
"description": "Shallowly merges with outer annotations; configured keys win."
|
|
23
|
+
},
|
|
24
|
+
"effect/References/MinimumLogLevel": {
|
|
25
|
+
"type": "string",
|
|
26
|
+
"enum": [
|
|
27
|
+
"All",
|
|
28
|
+
"Fatal",
|
|
29
|
+
"Error",
|
|
30
|
+
"Warn",
|
|
31
|
+
"Info",
|
|
32
|
+
"Debug",
|
|
33
|
+
"Trace",
|
|
34
|
+
"None"
|
|
35
|
+
],
|
|
36
|
+
"description": "Replaces the outer minimum log level."
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"additionalProperties": false,
|
|
40
|
+
"description": "Patches for references, applying to this entry and its descendants."
|
|
41
|
+
},
|
|
42
|
+
"Entry": {
|
|
43
|
+
"anyOf": [
|
|
44
|
+
{
|
|
45
|
+
"type": "object",
|
|
46
|
+
"properties": {
|
|
47
|
+
"id": {
|
|
48
|
+
"type": "string",
|
|
49
|
+
"description": "Identifies the entry. Graft adds one, and writes it to the file, if an entry has none."
|
|
50
|
+
},
|
|
51
|
+
"name": {
|
|
52
|
+
"type": "string",
|
|
53
|
+
"description": "The plugin's module: a relative path, a package name, or a short name. Ignored for groups."
|
|
54
|
+
},
|
|
55
|
+
"config": {
|
|
56
|
+
"type": "array",
|
|
57
|
+
"description": "The entries of this group.",
|
|
58
|
+
"items": {
|
|
59
|
+
"$ref": "#/definitions/Entry"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"disabled": {
|
|
63
|
+
"type": "boolean",
|
|
64
|
+
"description": "true unloads the entry but keeps it in the file."
|
|
65
|
+
},
|
|
66
|
+
"group": {
|
|
67
|
+
"type": "boolean",
|
|
68
|
+
"enum": [
|
|
69
|
+
true
|
|
70
|
+
],
|
|
71
|
+
"description": "true makes the entry a group of other entries."
|
|
72
|
+
},
|
|
73
|
+
"inject": {
|
|
74
|
+
"type": "array",
|
|
75
|
+
"description": "Service keys to wait for before loading the plugin, in addition to its own inject.",
|
|
76
|
+
"items": {
|
|
77
|
+
"type": "string"
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"isolate": {
|
|
81
|
+
"type": "object",
|
|
82
|
+
"additionalProperties": {
|
|
83
|
+
"anyOf": [
|
|
84
|
+
{
|
|
85
|
+
"type": "boolean",
|
|
86
|
+
"enum": [
|
|
87
|
+
true
|
|
88
|
+
]
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"type": "string"
|
|
92
|
+
}
|
|
93
|
+
]
|
|
94
|
+
},
|
|
95
|
+
"description": "Service or event keys to isolate: true for a private realm, or a label for a shared one."
|
|
96
|
+
},
|
|
97
|
+
"intercept": {
|
|
98
|
+
"$ref": "#/definitions/Intercept"
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
"required": [
|
|
102
|
+
"name",
|
|
103
|
+
"group"
|
|
104
|
+
],
|
|
105
|
+
"allOf": [
|
|
106
|
+
{
|
|
107
|
+
"type": "object",
|
|
108
|
+
"additionalProperties": {}
|
|
109
|
+
}
|
|
110
|
+
]
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
"type": "object",
|
|
114
|
+
"properties": {
|
|
115
|
+
"id": {
|
|
116
|
+
"type": "string",
|
|
117
|
+
"description": "Identifies the entry. Graft adds one, and writes it to the file, if an entry has none."
|
|
118
|
+
},
|
|
119
|
+
"name": {
|
|
120
|
+
"type": "string",
|
|
121
|
+
"description": "The plugin's module: a relative path, a package name, or a short name. Ignored for groups."
|
|
122
|
+
},
|
|
123
|
+
"config": {
|
|
124
|
+
"description": "The plugin's input. For a group, its list of entries."
|
|
125
|
+
},
|
|
126
|
+
"disabled": {
|
|
127
|
+
"type": "boolean",
|
|
128
|
+
"description": "true unloads the entry but keeps it in the file."
|
|
129
|
+
},
|
|
130
|
+
"group": {
|
|
131
|
+
"type": "boolean",
|
|
132
|
+
"enum": [
|
|
133
|
+
false
|
|
134
|
+
],
|
|
135
|
+
"description": "true makes the entry a group of other entries."
|
|
136
|
+
},
|
|
137
|
+
"inject": {
|
|
138
|
+
"type": "array",
|
|
139
|
+
"description": "Service keys to wait for before loading the plugin, in addition to its own inject.",
|
|
140
|
+
"items": {
|
|
141
|
+
"type": "string"
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
"isolate": {
|
|
145
|
+
"type": "object",
|
|
146
|
+
"additionalProperties": {
|
|
147
|
+
"anyOf": [
|
|
148
|
+
{
|
|
149
|
+
"type": "boolean",
|
|
150
|
+
"enum": [
|
|
151
|
+
true
|
|
152
|
+
]
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
"type": "string"
|
|
156
|
+
}
|
|
157
|
+
]
|
|
158
|
+
},
|
|
159
|
+
"description": "Service or event keys to isolate: true for a private realm, or a label for a shared one."
|
|
160
|
+
},
|
|
161
|
+
"intercept": {
|
|
162
|
+
"$ref": "#/definitions/Intercept"
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
"required": [
|
|
166
|
+
"name"
|
|
167
|
+
],
|
|
168
|
+
"allOf": [
|
|
169
|
+
{
|
|
170
|
+
"type": "object",
|
|
171
|
+
"additionalProperties": {}
|
|
172
|
+
}
|
|
173
|
+
]
|
|
174
|
+
}
|
|
175
|
+
]
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
package/src/Manage.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creating projects and changing their dependencies.
|
|
3
|
+
*/
|
|
4
|
+
import * as Create from "@graftland/create"
|
|
5
|
+
import * as PackageManager from "@graftland/package-manager"
|
|
6
|
+
import {
|
|
7
|
+
Array,
|
|
8
|
+
Config,
|
|
9
|
+
Effect,
|
|
10
|
+
Option,
|
|
11
|
+
Predicate,
|
|
12
|
+
Record,
|
|
13
|
+
Schema,
|
|
14
|
+
} from "effect"
|
|
15
|
+
|
|
16
|
+
const report = (result: PackageManager.InstallResult) =>
|
|
17
|
+
Effect.logInfo(
|
|
18
|
+
`${result.agent}: ${result.added.length} added, ${result.updated.length} updated, ${result.removed.length} removed`,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* `name@range`, split at the last `@` so a scope's `@` stays in the name. A
|
|
23
|
+
* bare name means the latest version.
|
|
24
|
+
*/
|
|
25
|
+
const Spec = Schema.Union([
|
|
26
|
+
Schema.TemplateLiteralParser([
|
|
27
|
+
PackageManager.PackageName,
|
|
28
|
+
"@",
|
|
29
|
+
Schema.String,
|
|
30
|
+
]),
|
|
31
|
+
PackageManager.PackageName,
|
|
32
|
+
])
|
|
33
|
+
const decodeSpecs = Schema.decodeEffect(Schema.Array(Spec))
|
|
34
|
+
|
|
35
|
+
const install = (
|
|
36
|
+
directory: string,
|
|
37
|
+
changes: Readonly<Record<string, string | null>>,
|
|
38
|
+
) =>
|
|
39
|
+
Effect.gen(function* () {
|
|
40
|
+
const decoded = yield* Schema.decodeEffect(PackageManager.Changes)(changes)
|
|
41
|
+
// Set by npm, pnpm and Yarn when they run graft, such as through `pnpm dlx`.
|
|
42
|
+
const userAgent = yield* Config.String("npm_config_user_agent").pipe(
|
|
43
|
+
Config.withDefault(""),
|
|
44
|
+
)
|
|
45
|
+
const manager = yield* PackageManager.make({ directory, userAgent })
|
|
46
|
+
const result = yield* manager.install(decoded)
|
|
47
|
+
yield* report(result)
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
export const create = (options: {
|
|
51
|
+
readonly directory: string
|
|
52
|
+
readonly name: Option.Option<string>
|
|
53
|
+
readonly install: boolean
|
|
54
|
+
}) =>
|
|
55
|
+
Effect.gen(function* () {
|
|
56
|
+
const project = yield* Create.create({
|
|
57
|
+
directory: options.directory,
|
|
58
|
+
...Option.match(options.name, {
|
|
59
|
+
onNone: () => ({}),
|
|
60
|
+
onSome: (name) => ({ name }),
|
|
61
|
+
}),
|
|
62
|
+
})
|
|
63
|
+
yield* Effect.logInfo(`Created ${project.name} in ${project.directory}`)
|
|
64
|
+
if (options.install) yield* install(project.directory, {})
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
export const add = (specs: ReadonlyArray<string>) =>
|
|
68
|
+
Effect.flatMap(decodeSpecs(specs), (specs) =>
|
|
69
|
+
install(
|
|
70
|
+
".",
|
|
71
|
+
Record.fromEntries(
|
|
72
|
+
Array.map(specs, (spec) =>
|
|
73
|
+
Predicate.isString(spec)
|
|
74
|
+
? ([spec, "latest"] as const)
|
|
75
|
+
: ([spec[0], spec[2]] as const),
|
|
76
|
+
),
|
|
77
|
+
),
|
|
78
|
+
),
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
export const remove = (names: ReadonlyArray<string>) =>
|
|
82
|
+
install(
|
|
83
|
+
".",
|
|
84
|
+
Record.fromEntries(Array.map(names, (name) => [name, null] as const)),
|
|
85
|
+
)
|
package/src/Start.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs a Graft application from its config file.
|
|
3
|
+
*/
|
|
4
|
+
import { NodeServices } from "@effect/platform-node"
|
|
5
|
+
import { Graft, Plugin } from "@graftland/graft"
|
|
6
|
+
import * as Hmr from "@graftland/hmr"
|
|
7
|
+
import { Include, Loader, ModuleResolver, type Tree } from "@graftland/loader"
|
|
8
|
+
import type { PlatformError, Schema } from "effect"
|
|
9
|
+
import { Effect, FileSystem, Layer, Logger, Path } from "effect"
|
|
10
|
+
import { EnvFile, layer as env, watchEnvFile } from "./internal/env"
|
|
11
|
+
import { layer as intercepts } from "./internal/intercepts"
|
|
12
|
+
import { watchModules } from "./internal/watch"
|
|
13
|
+
|
|
14
|
+
export interface Options {
|
|
15
|
+
/** Path of the config file. */
|
|
16
|
+
readonly config: string
|
|
17
|
+
/** Reload plugin modules and the config file when they change. */
|
|
18
|
+
readonly watch: boolean
|
|
19
|
+
/**
|
|
20
|
+
* A `.env` file that `!env` reads when the process environment does not set
|
|
21
|
+
* a variable. With `watch`, changes to it are read again.
|
|
22
|
+
*/
|
|
23
|
+
readonly envFile?: string | undefined
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Loads the entries of the config file and runs until interrupted. Plugin
|
|
28
|
+
* modules are imported through the hot reloader, so bare specifiers resolve
|
|
29
|
+
* from the application directory whether or not `watch` is on.
|
|
30
|
+
*/
|
|
31
|
+
export const run = (
|
|
32
|
+
options: Options,
|
|
33
|
+
): Effect.Effect<
|
|
34
|
+
never,
|
|
35
|
+
| Graft.ServiceConflict
|
|
36
|
+
| PlatformError.BadArgument
|
|
37
|
+
| PlatformError.PlatformError
|
|
38
|
+
| Schema.SchemaError
|
|
39
|
+
| Loader.StoreError
|
|
40
|
+
| Tree.InvalidOperation
|
|
41
|
+
> =>
|
|
42
|
+
Effect.gen(function* () {
|
|
43
|
+
const path = yield* Path.Path
|
|
44
|
+
const file = path.resolve(options.config)
|
|
45
|
+
const directory = path.dirname(file)
|
|
46
|
+
const base = yield* path.toFileUrl(file)
|
|
47
|
+
const hmr = yield* Hmr.make({ base: base.href })
|
|
48
|
+
const resolver = yield* ModuleResolver.make({
|
|
49
|
+
base: directory,
|
|
50
|
+
importer: hmr.importerScoped,
|
|
51
|
+
})
|
|
52
|
+
yield* Graft.provide(ModuleResolver.ModuleResolver, resolver)
|
|
53
|
+
const included = yield* Graft.plugin(Include.Include, {
|
|
54
|
+
path: file,
|
|
55
|
+
watch: options.watch,
|
|
56
|
+
})
|
|
57
|
+
yield* included.await
|
|
58
|
+
if (options.watch) {
|
|
59
|
+
const { reload } = yield* EnvFile
|
|
60
|
+
const envFile = options.envFile
|
|
61
|
+
const reloader = Plugin.make({
|
|
62
|
+
name: "reloader",
|
|
63
|
+
inject: [Loader.Loader, FileSystem.FileSystem, Path.Path],
|
|
64
|
+
apply: () =>
|
|
65
|
+
Effect.gen(function* () {
|
|
66
|
+
const loader = yield* Loader.Loader
|
|
67
|
+
yield* watchModules(hmr, directory, loader.retry).pipe(
|
|
68
|
+
Effect.forkScoped,
|
|
69
|
+
)
|
|
70
|
+
if (envFile !== undefined)
|
|
71
|
+
yield* watchEnvFile(envFile, reload, loader.retry).pipe(
|
|
72
|
+
Effect.forkScoped,
|
|
73
|
+
)
|
|
74
|
+
}),
|
|
75
|
+
})
|
|
76
|
+
yield* Graft.plugin(reloader)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
yield* Effect.logInfo(
|
|
80
|
+
`Running ${path.relative(process.cwd(), file) || file}`,
|
|
81
|
+
)
|
|
82
|
+
return yield* Effect.never
|
|
83
|
+
}).pipe(
|
|
84
|
+
Effect.scoped,
|
|
85
|
+
// @effect-diagnostics-next-line strictEffectProvide:off -- this runs the whole application, so it is an entry point
|
|
86
|
+
Effect.provide(
|
|
87
|
+
Layer.provideMerge(
|
|
88
|
+
Graft.layer,
|
|
89
|
+
Layer.mergeAll(
|
|
90
|
+
NodeServices.layer,
|
|
91
|
+
intercepts,
|
|
92
|
+
env(options.envFile).pipe(Layer.provide(NodeServices.layer)),
|
|
93
|
+
Logger.layer([Logger.consolePretty()]),
|
|
94
|
+
),
|
|
95
|
+
),
|
|
96
|
+
),
|
|
97
|
+
)
|
package/src/bin.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* The `graft` executable. Running this module starts the program.
|
|
4
|
+
*/
|
|
5
|
+
import { NodeRuntime, NodeServices } from "@effect/platform-node"
|
|
6
|
+
import { Effect, Option } from "effect"
|
|
7
|
+
import { Argument, Command, Flag } from "effect/cli"
|
|
8
|
+
import { version } from "../package.json" with { type: "json" }
|
|
9
|
+
import * as Manage from "./Manage"
|
|
10
|
+
import * as Start from "./Start"
|
|
11
|
+
|
|
12
|
+
const start = Command.make(
|
|
13
|
+
"start",
|
|
14
|
+
{
|
|
15
|
+
config: Argument.String("config").pipe(
|
|
16
|
+
Argument.withDescription("Path of the config file"),
|
|
17
|
+
Argument.withDefault("graft.yml"),
|
|
18
|
+
),
|
|
19
|
+
watch: Flag.Boolean("watch").pipe(
|
|
20
|
+
Flag.withAlias("w"),
|
|
21
|
+
Flag.withDescription("Reload plugins and config when files change"),
|
|
22
|
+
Flag.withDefault(false),
|
|
23
|
+
),
|
|
24
|
+
envFile: Flag.String("env-file").pipe(
|
|
25
|
+
Flag.withDescription(
|
|
26
|
+
"Read variables for !env from a .env file; the process environment takes precedence",
|
|
27
|
+
),
|
|
28
|
+
Flag.optional,
|
|
29
|
+
),
|
|
30
|
+
},
|
|
31
|
+
(options) =>
|
|
32
|
+
Start.run({ ...options, envFile: Option.getOrUndefined(options.envFile) }),
|
|
33
|
+
).pipe(
|
|
34
|
+
Command.withDescription("Run the application described by a config file"),
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
const create = Command.make(
|
|
38
|
+
"create",
|
|
39
|
+
{
|
|
40
|
+
directory: Argument.String("directory").pipe(
|
|
41
|
+
Argument.withDescription("Where to create the project"),
|
|
42
|
+
),
|
|
43
|
+
name: Flag.String("name").pipe(
|
|
44
|
+
Flag.withDescription("Package name; defaults to the directory name"),
|
|
45
|
+
Flag.optional,
|
|
46
|
+
),
|
|
47
|
+
install: Flag.Boolean("install").pipe(
|
|
48
|
+
Flag.withDescription("Install dependencies afterwards"),
|
|
49
|
+
Flag.withDefault(false),
|
|
50
|
+
),
|
|
51
|
+
},
|
|
52
|
+
Manage.create,
|
|
53
|
+
).pipe(Command.withDescription("Create a new Graft project"))
|
|
54
|
+
|
|
55
|
+
const add = Command.make(
|
|
56
|
+
"add",
|
|
57
|
+
{ packages: Argument.variadic(Argument.String("package")) },
|
|
58
|
+
({ packages }) => Manage.add(packages),
|
|
59
|
+
).pipe(
|
|
60
|
+
Command.withDescription(
|
|
61
|
+
"Add dependencies, restoring the project if installing fails",
|
|
62
|
+
),
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
const remove = Command.make(
|
|
66
|
+
"remove",
|
|
67
|
+
{ packages: Argument.variadic(Argument.String("package")) },
|
|
68
|
+
({ packages }) => Manage.remove(packages),
|
|
69
|
+
).pipe(
|
|
70
|
+
Command.withDescription(
|
|
71
|
+
"Remove dependencies, restoring the project if installing fails",
|
|
72
|
+
),
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
const graft = Command.make("graft").pipe(
|
|
76
|
+
Command.withDescription("Run and manage Graft applications"),
|
|
77
|
+
Command.withSubcommands([start, create, add, remove]),
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
Command.run(graft, { version }).pipe(
|
|
81
|
+
Effect.provide(NodeServices.layer),
|
|
82
|
+
NodeRuntime.runMain,
|
|
83
|
+
)
|