@shivaedev/create-app 0.12.0 → 0.13.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.
Files changed (42) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +4 -0
  3. package/dist/cli.js +83 -80
  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 +1 -1
  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 +9 -4
  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 +1 -1
  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
@@ -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
+ });