@shivaedev/create-app 0.11.24 → 0.13.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.
Files changed (42) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.md +4 -0
  3. package/dist/cli.js +85 -82
  4. package/dist/createApp.d.ts +3 -2
  5. package/dist/createApp.d.ts.map +1 -1
  6. package/dist/createApp.js +7 -17
  7. package/dist/createApp.js.map +1 -1
  8. package/dist/generation.d.ts +21 -0
  9. package/dist/generation.d.ts.map +1 -0
  10. package/dist/generation.js +31 -0
  11. package/dist/generation.js.map +1 -0
  12. package/dist/historicalTemplate.d.ts +6 -0
  13. package/dist/historicalTemplate.d.ts.map +1 -0
  14. package/dist/historicalTemplate.js +17 -0
  15. package/dist/historicalTemplate.js.map +1 -0
  16. package/dist/packTemplate.js +3 -3
  17. package/dist/packTemplate.js.map +1 -1
  18. package/dist/runProcess.d.ts +10 -0
  19. package/dist/runProcess.d.ts.map +1 -0
  20. package/dist/runProcess.js +19 -0
  21. package/dist/runProcess.js.map +1 -0
  22. package/dist/starterPatch.d.ts +12 -0
  23. package/dist/starterPatch.d.ts.map +1 -0
  24. package/dist/starterPatch.js +36 -0
  25. package/dist/starterPatch.js.map +1 -0
  26. package/dist/template.js +2 -2
  27. package/dist/template.js.map +1 -1
  28. package/dist/updateApp.d.ts +4 -0
  29. package/dist/updateApp.d.ts.map +1 -0
  30. package/dist/updateApp.js +36 -0
  31. package/dist/updateApp.js.map +1 -0
  32. package/package.json +13 -8
  33. package/src/cli.ts +12 -4
  34. package/src/createApp.ts +12 -18
  35. package/src/generation.ts +35 -0
  36. package/src/historicalTemplate.ts +17 -0
  37. package/src/packTemplate.ts +3 -3
  38. package/src/runProcess.ts +25 -0
  39. package/src/starterPatch.ts +43 -0
  40. package/src/template.ts +2 -2
  41. package/src/updateApp.ts +40 -0
  42. package/template.json +1 -1
@@ -1,7 +1,7 @@
1
1
  import { Buffer } from "node:buffer";
2
2
  import { basename, join } from "node:path";
3
3
  import { Effect, FileSystem, type PlatformError, Schema } from "effect";
4
- import { MIGRATION_FILE_PATTERN, MIGRATIONS_DIRECTORY } from "@shivaedev/effect-sql/migrationConvention.ts";
4
+ import { MIGRATION_FILE_PATTERN } from "@shivaedev/effect-sql/migrationConvention.ts";
5
5
  import { CreateAppError } from "#CreateAppError.ts";
6
6
  import { prepareFile, type Template, Versions } from "#template.ts";
7
7
 
@@ -11,7 +11,7 @@ const appPaths = new Map([
11
11
  ["pnpm-workspace.copy.yaml", "pnpm-workspace.yaml"],
12
12
  ]);
13
13
  const excluded = new Set(["node_modules", "dist", "coverage", "pnpm-lock.yaml", ".git"]);
14
- const rootExcluded = new Set(["published-versions.json", "AGENTS.md", "CLAUDE.md", "README.md"]);
14
+ const rootExcluded = new Set(["published-versions.json", "AGENTS.md", "CLAUDE.md", "README.md", "quality.config.ts"]);
15
15
  function included(path: string) {
16
16
  return !(rootExcluded.has(path) || excluded.has(basename(path))) && (!basename(path).startsWith(".env") || basename(path) === ".env.example");
17
17
  }
@@ -31,7 +31,7 @@ export const packTemplate = Effect.fn("CreateApp.packTemplate")(function* (start
31
31
  if ((yield* fs.stat(join(starter, path))).type === "Directory") {
32
32
  yield* visit(path);
33
33
  } else {
34
- if (directory === join(MIGRATIONS_DIRECTORY) && !MIGRATION_FILE_PATTERN.test(name)) {
34
+ if (basename(directory) === "migrations" && !MIGRATION_FILE_PATTERN.test(name)) {
35
35
  return yield* new CreateAppError({ message: `Invalid migration filename: ${path}` });
36
36
  }
37
37
  const target = appPaths.get(path) ?? path;
@@ -0,0 +1,25 @@
1
+ import { Effect, Stream } from "effect";
2
+ import { ChildProcess, ChildProcessSpawner } from "effect/process";
3
+ import { CreateAppError } from "./CreateAppError.ts";
4
+
5
+ export const runProcess = Effect.fn("CreateApp.runProcess")(function* (cwd: string, command: string, args: readonly string[]) {
6
+ return yield* Effect.scoped(
7
+ Effect.gen(function* () {
8
+ const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
9
+ const child = yield* spawner.spawn(ChildProcess.make(command, args, { cwd, stdin: "ignore" }));
10
+ const [stdout, stderr, code] = yield* Effect.all(
11
+ [Stream.mkString(Stream.decodeText(child.stdout)), Stream.mkString(Stream.decodeText(child.stderr)), child.exitCode],
12
+ { concurrency: "unbounded" },
13
+ );
14
+ return { code: Number(code), stderr, stdout };
15
+ }),
16
+ );
17
+ });
18
+
19
+ export const checkedProcess = Effect.fn("CreateApp.checkedProcess")(function* (cwd: string, command: string, args: readonly string[]) {
20
+ const result = yield* runProcess(cwd, command, args);
21
+ if (result.code !== 0) {
22
+ return yield* new CreateAppError({ message: `${command} ${args[0]} failed: ${result.stderr.trim()}` });
23
+ }
24
+ return result.stdout;
25
+ });
@@ -0,0 +1,43 @@
1
+ import { join } from "node:path";
2
+ import { Effect, FileSystem } from "effect";
3
+ import { renderTemplate } from "./generation.ts";
4
+ import { checkedProcess } from "./runProcess.ts";
5
+ import type { Template } from "./template.ts";
6
+
7
+ export const starterPatch = Effect.fn("CreateApp.starterPatch")(function* (
8
+ target: string,
9
+ directory: string,
10
+ name: string,
11
+ before: Template,
12
+ after: Template,
13
+ ) {
14
+ const fs = yield* FileSystem.FileSystem;
15
+ const deleted = new Set<string>();
16
+ for (const entry of before) {
17
+ if (!(yield* fs.exists(join(target, entry.path)))) {
18
+ deleted.add(entry.path);
19
+ }
20
+ }
21
+ const base = before.filter((entry) => !deleted.has(entry.path));
22
+ const incoming = after.filter((entry) => !deleted.has(entry.path));
23
+ const repository = join(directory, "merge");
24
+ yield* fs.makeDirectory(repository);
25
+ yield* checkedProcess(repository, "git", ["init", "--quiet"]);
26
+ yield* renderTemplate(repository, base, name);
27
+ yield* checkedProcess(repository, "git", ["add", "--all"]);
28
+ const tree = (yield* checkedProcess(repository, "git", ["write-tree"])).trim();
29
+ for (const entry of base) {
30
+ yield* checkedProcess(target, "git", ["hash-object", "-w", "--", join(repository, entry.path)]);
31
+ }
32
+ for (const path of yield* fs.readDirectory(repository)) {
33
+ if (path !== ".git") {
34
+ yield* fs.remove(join(repository, path), { recursive: true });
35
+ }
36
+ }
37
+ yield* renderTemplate(repository, incoming, name);
38
+ yield* checkedProcess(repository, "git", ["add", "--all"]);
39
+ const patch = yield* checkedProcess(repository, "git", ["diff", "--cached", "--binary", "--full-index", "--no-renames", tree]);
40
+ const path = join(directory, "starter.patch");
41
+ yield* fs.writeFileString(path, patch);
42
+ return { empty: patch.length === 0, path };
43
+ });
package/src/template.ts CHANGED
@@ -61,13 +61,13 @@ export function prepareManifest(source: string, versions: Readonly<Record<string
61
61
  }
62
62
 
63
63
  export function prepareFile(path: string, content: Buffer, versions: Readonly<Record<string, string>>) {
64
- if (["src/server/dev.ts", "src/test-support/adminCommand.ts", "src/test-support/deployChild.ts"].includes(path)) {
64
+ if (["src/test-support/adminCommand.ts", "src/test-support/deployChild.ts"].includes(path)) {
65
65
  return Buffer.from(content.toString().replaceAll('"--conditions=source", ', ""));
66
66
  }
67
67
  if (path === "package.json") {
68
68
  return Buffer.from(prepareManifest(content.toString(), versions));
69
69
  }
70
- if (["tsconfig.json", "vite.config.ts", "vitest.config.ts"].includes(path)) {
70
+ if (["tsconfig.json", "vite.config.ts", "vitest.config.ts", "src/server/dev.ts"].includes(path)) {
71
71
  return Buffer.from(content.toString().replaceAll('"source", ', "").replaceAll('["source"]', "[]"));
72
72
  }
73
73
  return content;
@@ -0,0 +1,40 @@
1
+ import { join, resolve } from "node:path";
2
+ import { Console, Effect, FileSystem, Schema } from "effect";
3
+ import { CreateAppError } from "./CreateAppError.ts";
4
+ import { GENERATION_FILE, Generation, readTemplate, writeGeneration } from "./generation.ts";
5
+ import { historicalTemplate } from "./historicalTemplate.ts";
6
+ import { checkedProcess, runProcess } from "./runProcess.ts";
7
+ import { starterPatch } from "./starterPatch.ts";
8
+
9
+ export const updateApp = Effect.fn("CreateApp.updateApp")(function* (folder: string, templatePath: string, version: string) {
10
+ return yield* Effect.scoped(
11
+ Effect.gen(function* () {
12
+ const fs = yield* FileSystem.FileSystem;
13
+ const target = resolve(folder);
14
+ yield* checkedProcess(target, "git", ["rev-parse", "--show-toplevel"]);
15
+ if ((yield* checkedProcess(target, "git", ["status", "--porcelain"])).trim() !== "") {
16
+ return yield* new CreateAppError({ message: "Refusing to update a dirty working tree. Commit or stash your changes first." });
17
+ }
18
+ const generation = yield* Schema.decodeUnknownEffect(Schema.fromJsonString(Generation))(
19
+ yield* fs.readFileString(join(target, GENERATION_FILE)),
20
+ );
21
+ const directory = yield* fs.makeTempDirectoryScoped({ prefix: "create-app-update-" });
22
+ const current = yield* readTemplate(templatePath);
23
+ const previous = generation.version === version ? current : yield* historicalTemplate(directory, generation.version);
24
+ const patch = yield* starterPatch(target, directory, generation.name, previous, current);
25
+ if (!patch.empty) {
26
+ const result = yield* runProcess(target, "git", ["apply", "--3way", patch.path]);
27
+ if (result.code !== 0) {
28
+ const conflicts = (yield* checkedProcess(target, "git", ["diff", "--name-only", "--diff-filter=U"])).trim();
29
+ return yield* new CreateAppError({
30
+ message: conflicts
31
+ ? `Resolve these conflicts, then commit your changes:\n${conflicts}\nThe recorded version remains ${generation.version}.`
32
+ : result.stderr.trim(),
33
+ });
34
+ }
35
+ }
36
+ yield* writeGeneration(target, { ...generation, version });
37
+ yield* Console.log(`Applied create-app ${version}. Review the changes, run pnpm install and commit when ready.`);
38
+ }),
39
+ );
40
+ });