Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/connect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@tanstack/react-router-devtools": "^1.122.0",
"@xstate/store": "^3.5.1",
"clsx": "^2.1.1",
"effect": "^3.17.0",
"effect": "^3.17.1",
"framer-motion": "^12.10.1",
"graphql-request": "^7.2.0",
"lucide-react": "^0.508.0",
Expand Down
5 changes: 5 additions & 0 deletions apps/create-hypergraph/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# create-hypergraph

## 0.2.0
### Minor Changes

- 3204607: Use workspace deps for create-hypergraph templates and replace with current version on copy into dist directory

## 0.1.0
### Patch Changes

Expand Down
19 changes: 10 additions & 9 deletions apps/create-hypergraph/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-hypergraph",
"version": "0.1.3",
"version": "0.2.0",
"description": "CLI toolchain to scaffold a Hypergraph-enabled application with a given template.",
"type": "module",
"bin": {
Expand All @@ -26,12 +26,13 @@
"scripts": {
"test": "vitest run",
"dev": "NODE_ENV=development pnpx tsx ./src/bin.ts",
"build": "tsdown && tsx scripts/copy-package-json.ts && pnpm run copy-all",
"copy-templates": "cp -r template-* dist/",
"build": "tsdown && pnpm run copy-all",
"copy-packagejson": "tsx scripts/copy-package-json.ts",
"copy-templates": "tsx scripts/copy-template-dir.ts",
"copy-readme": "cp README.md dist/README.md",
"copy-changelog": "cp CHANGELOG.md dist/CHANGELOG.md",
"copy-llms": "cp llms.txt dist/llms.txt",
"copy-all": "pnpm run copy-templates && pnpm run copy-readme && pnpm run copy-changelog && pnpm run copy-llms",
"copy-all": "pnpm run copy-packagejson && pnpm run copy-templates && pnpm run copy-readme && pnpm run copy-changelog && pnpm run copy-llms",
"check": "tsc --noEmit",
"start": "node ./dist/bin.js",
"lint": "biome check",
Expand All @@ -53,14 +54,14 @@
},
"homepage": "https://github.com/graphprotocol/hypergraph/tree/main/apps/create-hypergraph-app#readme",
"devDependencies": {
"@effect/cli": "^0.68.0",
"@effect/language-service": "^0.28.0",
"@effect/platform": "^0.89.0",
"@effect/platform-node": "^0.92.0",
"@effect/cli": "^0.69.0",
"@effect/language-service": "^0.28.3",
"@effect/platform": "^0.90.0",
"@effect/platform-node": "^0.94.0",
"@effect/printer-ansi": "^0.45.0",
"@effect/vitest": "^0.25.0",
"@types/node": "^24.1.0",
"effect": "^3.17.0",
"effect": "^3.17.1",
"execa": "^9.6.0",
"tsdown": "^0.13.0",
"tsx": "^4.20.3"
Expand Down
170 changes: 170 additions & 0 deletions apps/create-hypergraph/scripts/copy-template-dir.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
import { readdirSync } from 'node:fs';
import type { PlatformError } from '@effect/platform/Error';
import * as FileSystem from '@effect/platform/FileSystem';
import * as Path from '@effect/platform/Path';
import * as NodeFileSystem from '@effect/platform-node/NodeFileSystem';
import * as NodePath from '@effect/platform-node/NodePath';
import { Cause, Chunk, Console, Data, Effect, pipe, Stream } from 'effect';

const workspaceDepsToReplace = {
'@graphprotocol/hypergraph': {
packageJson: 'packages/hypergraph/package.json',
},
'@graphprotocol/hypergraph-react': {
packageJson: 'packages/hypergraph-react/package.json',
},
'@graphprotocol/typesync': {
packageJson: 'packages/typesync/package.json',
},
} as const satisfies Record<
'@graphprotocol/hypergraph' | '@graphprotocol/hypergraph-react' | '@graphprotocol/typesync',
{ packageJson: `packages/${string}/package.json` }
>;
const ignore = new Set(['.git', 'node_modules', '.tanstack', 'dist', 'publish', 'build', '.next']);

class CopyTemplateDirService extends Effect.Service<CopyTemplateDirService>()(
'/Hypergraph/create-hypergraph/services/CopyTemplateDirService',
{
dependencies: [NodeFileSystem.layer, NodePath.layer],
effect: Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const path = yield* Path.Path;

const cwd = process.cwd();

const getTemplateDirectories = () =>
Effect.gen(function* () {
return yield* Stream.fromIterable(readdirSync(cwd, { withFileTypes: true })).pipe(
Stream.filter((entry) => entry.name.startsWith('template-') && entry.isDirectory()),
Stream.map((entry) => entry.name),
Stream.runCollect,
);
});

function fetchWorkspaceDepCurrentVersion(packagejson: `packages/${string}/package.json`) {
return pipe(
fs.readFileString(path.resolve(cwd, '..', '..', packagejson)),
Effect.tapError((err) => Console.error('Failure reading remplate package.json', { cause: err, packagejson })),
Effect.map((_) => JSON.parse(_)),
Effect.map((json) => String(json.version)),
);
}
function fetchAllWorkspaceDepsCurrentVersion() {
return Stream.fromIterable(Object.entries(workspaceDepsToReplace)).pipe(
Stream.mapEffect(([dep, { packageJson }]) =>
Effect.gen(function* () {
const version = yield* fetchWorkspaceDepCurrentVersion(packageJson);

return [dep, version] as const;
}),
),
Stream.runCollect,
);
}

const updatePackageJsonWorkspaceDeps = (
packageJsonPath: string,
destPackageJsonPath: string,
replaced: Record<string, string>,
) =>
Effect.gen(function* () {
// read the package.json
// update the hypergraph workspace deps with the current version
const packageJson = yield* fs.readFileString(packageJsonPath).pipe(Effect.map(JSON.parse));

packageJson.dependencies = {
...packageJson.dependencies,
...replaced,
};

yield* fs.writeFileString(destPackageJsonPath, JSON.stringify(packageJson, null, 2));
});

const copy = (src: string, dest: string, replaced: Record<string, string>): Effect.Effect<void, PlatformError> =>
Effect.gen(function* () {
yield* fs.makeDirectory(dest, { recursive: true });
const entries = readdirSync(src, { withFileTypes: true });

for (const entry of entries) {
if (entry.isDirectory() && ignore.has(entry.name)) continue;

const srcPath = path.join(src, entry.name);
const destPath = path.join(dest, entry.name);

if (entry.isDirectory()) {
yield* copy(srcPath, destPath, replaced);
} else {
// update the package.json
if (entry.name === 'package.json') {
yield* updatePackageJsonWorkspaceDeps(srcPath, destPath, replaced);
continue;
}
yield* fs.copyFile(srcPath, destPath);
}
}
});

return {
copyTemplates() {
return Effect.gen(function* () {
const workspaceDeps = yield* fetchAllWorkspaceDepsCurrentVersion();
const workspaceDepsMap = Chunk.reduce(
workspaceDeps,
{} as Record<string, string>,
(map, [currDep, currVersion]) => {
map[currDep] = currVersion;

return map;
},
);

// iterate through all templates, copy all files, update package.json deps
yield* Stream.fromIterableEffect(getTemplateDirectories())
.pipe(
Stream.runForEach((template) =>
Effect.gen(function* () {
yield* Console.info('Copying template:', template, 'into dist');

const templateDir = path.resolve(process.cwd(), template);
const templateDirExists = yield* fs.exists(templateDir);
if (!templateDirExists) {
throw new TemplateDirDoesNotExistError({ template: templateDir });
}

const templateDestDir = path.resolve(process.cwd(), 'dist', template);

yield* copy(templateDir, templateDestDir, workspaceDepsMap);
}),
),
)
.pipe(
Effect.tapErrorCause((cause) =>
Console.error('Failure copying template to dist', { cause: Cause.pretty(cause) }),
),
Effect.andThen(() => Console.info('Completed copying template directories to dist with updated deps')),
);
});
},
} as const;
}),
},
) {}

class TemplateDirDoesNotExistError extends Data.TaggedError(
'Hypergraph/create-hypergraph/errors/TemplateDirDoesNotExistError',
)<{
readonly template: string;
}> {}

const program = pipe(
Console.log('Copying templates to dist dir'),
() =>
Effect.gen(function* () {
const copy = yield* CopyTemplateDirService;

yield* copy.copyTemplates();
}),
Effect.provide(CopyTemplateDirService.Default),
);

Effect.runPromise(program);
2 changes: 1 addition & 1 deletion apps/create-hypergraph/src/Cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const createHypergraphApp = Command.make('create-hypergraph-app', {

export const run = Command.run(createHypergraphApp, {
name: 'create-hypergraph-app',
version: '0.1.3',
version: '0.2.0',
});

// ========================
Expand Down
8 changes: 4 additions & 4 deletions apps/create-hypergraph/template-vite-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
},
"dependencies": {
"@graphprotocol/grc-20": "^0.21.6",
"@graphprotocol/hypergraph": "0.1.0",
"@graphprotocol/hypergraph-react": "0.1.0",
"@graphprotocol/typesync": "^0.1.0",
"@graphprotocol/hypergraph": "workspace:*",
"@graphprotocol/hypergraph-react": "workspace:*",
"@graphprotocol/typesync": "workspace:*",
"@radix-ui/react-navigation-menu": "^1.2.13",
"@radix-ui/react-slot": "^1.2.3",
"@radix-ui/react-tooltip": "^1.2.7",
Expand All @@ -23,7 +23,7 @@
"@tanstack/react-router": "^1.129.2",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"effect": "^3.17.0",
"effect": "^3.17.1",
"lucide-react": "^0.525.0",
"react": "^19.1.0",
"react-dom": "^19.1.0",
Expand Down
34 changes: 0 additions & 34 deletions apps/create-hypergraph/test/Cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,38 +234,4 @@ describe('create-hypergraph CLI', () => {
}
}),
);

it.effect(
'test dependency installation when not skipped',
() =>
Effect.gen(function* () {
yield* cleanupTestDirs();
const tempDir = yield* createTempDir();

try {
// Run CLI without skipping dependency installation
const output = yield* run(
[
'--template',
'vite-react',
'--package-manager',
'pnpm',
'--skip-initialize-git',
// Note: not skipping install deps
'test-deps-app',
],
tempDir,
);

expect(output).toContain('Successfully scaffolded your hypergraph enabled app');

// Verify node_modules directory was created
const projectPath = join(tempDir, 'test-deps-app');
expect(existsSync(join(projectPath, 'node_modules'))).toBe(true);
} finally {
yield* cleanupTempDir(tempDir);
}
}),
{ timeout: 60000 }, // 60 second timeout for dependency installation
);
});
2 changes: 1 addition & 1 deletion apps/events/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@xstate/store": "^3.5.1",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"effect": "^3.17.0",
"effect": "^3.17.1",
"framer-motion": "^12.10.1",
"graphql-request": "^7.1.2",
"isomorphic-ws": "^5.0.0",
Expand Down
2 changes: 1 addition & 1 deletion apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@privy-io/server-auth": "^1.26.0",
"body-parser": "^2.2.0",
"cors": "^2.8.5",
"effect": "^3.17.0",
"effect": "^3.17.1",
"express": "^5.1.0",
"prisma": "^6.7.0",
"siwe": "^3.0.0",
Expand Down
16 changes: 8 additions & 8 deletions apps/typesync/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@
"hypergraph": "pnpx tsx ./src/bin.ts typesync"
},
"devDependencies": {
"@effect/cli": "^0.68.0",
"@effect/experimental": "^0.53.0",
"@effect/language-service": "^0.28.0",
"@effect/platform": "^0.89.0",
"@effect/platform-node": "^0.92.0",
"@effect/cli": "^0.69.0",
"@effect/experimental": "^0.54.0",
"@effect/language-service": "^0.28.3",
"@effect/platform": "^0.90.0",
"@effect/platform-node": "^0.94.0",
"@effect/printer": "^0.45.0",
"@effect/sql": "^0.43.0",
"@effect/sql-sqlite-node": "^0.44.0",
"@effect/sql": "^0.44.0",
"@effect/sql-sqlite-node": "^0.45.0",
"@effect/vitest": "^0.25.0",
"@graphql-codegen/cli": "^5.0.7",
"@graphql-codegen/client-preset": "^4.8.3",
Expand Down Expand Up @@ -81,7 +81,7 @@
"@tanstack/react-router-devtools": "^1.129.5",
"better-sqlite3": "^12.2.0",
"date-fns": "^4.1.0",
"effect": "^3.17.0",
"effect": "^3.17.1",
"graphql": "^16.11.0",
"graphql-request": "^7.2.0",
"jotai": "^2.12.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/hypergraph-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"@graphprotocol/grc-20": "^0.21.6",
"@noble/hashes": "^1.8.0",
"@tanstack/react-query": "^5.75.5",
"effect": "^3.17.0",
"effect": "^3.17.1",
"graphql-request": "^7.1.2",
"siwe": "^3.0.0",
"uuid": "^11.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/hypergraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"@serenity-kit/noble-sodium": "^0.2.1",
"@xstate/store": "^3.5.1",
"bs58check": "^4.0.0",
"effect": "^3.17.0",
"effect": "^3.17.1",
"permissionless": "^0.2.47",
"siwe": "^3.0.0",
"uuid": "^11.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/typesync/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@
},
"dependencies": {
"@graphprotocol/grc-20": "^0.21.6",
"effect": "^3.17.0"
"effect": "^3.17.1"
}
}
Loading
Loading