@genex-ai/cli-demo 0.6.2 → 0.7.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 (2) hide show
  1. package/dist/index.js +54 -15
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -788,32 +788,71 @@ async function deployGame(sshUrl, opts, log) {
788
788
  return false;
789
789
  }
790
790
  const gitDir = await fs6.mkdtemp(path7.join(os2.tmpdir(), "genex-deploy-"));
791
- const gitEnv = { GIT_DIR: gitDir, GIT_WORK_TREE: siteDir };
791
+ const base = { GIT_DIR: gitDir };
792
+ const ident = {
793
+ GIT_AUTHOR_NAME: "genex",
794
+ GIT_AUTHOR_EMAIL: "agent@genex.local",
795
+ GIT_COMMITTER_NAME: "genex",
796
+ GIT_COMMITTER_EMAIL: "agent@genex.local"
797
+ };
798
+ const EMPTY_TREE = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
792
799
  try {
793
- if ((await run("git", ["init", "-q"], gitEnv)).code !== 0) {
800
+ if ((await run("git", ["init", "-q"], base)).code !== 0) {
794
801
  log.warn("git init failed \u2014 the game was not pushed.");
795
802
  return false;
796
803
  }
797
- await run("git", ["add", "-A"], gitEnv);
798
- const tracked = await run("git", ["ls-files"], gitEnv);
799
- if (/(^|\/)genex_key(\.pub)?$/m.test(tracked.out)) {
804
+ await fs6.writeFile(
805
+ path7.join(gitDir, "info", "exclude"),
806
+ ["node_modules/", "dist/", ".git/", KEY_NAME, `${KEY_NAME}.pub`, ".genex/", ""].join("\n")
807
+ );
808
+ const stage = async (workTree, indexName) => {
809
+ const env = { ...base, GIT_WORK_TREE: workTree, GIT_INDEX_FILE: path7.join(gitDir, indexName) };
810
+ await run("git", ["add", "-A"], env);
811
+ const tracked = await run("git", ["ls-files"], env);
812
+ if (/(^|\/)genex_key(\.pub)?$/m.test(tracked.out)) throw new Error("KEY_STAGED");
813
+ if (!tracked.out.trim()) return null;
814
+ const tree = (await run("git", ["write-tree"], env)).out.trim();
815
+ return tree || null;
816
+ };
817
+ const commitTree = async (tree, message) => (await run("git", ["commit-tree", tree, "-m", message], { ...base, ...ident })).out.trim();
818
+ let mainTree;
819
+ try {
820
+ mainTree = await stage(siteDir, "index-main");
821
+ } catch {
800
822
  log.error(`Refusing to deploy: ${KEY_NAME} is staged. Add it to .gitignore and retry.`);
801
823
  return false;
802
824
  }
803
- const commit = await run(
804
- "git",
805
- ["-c", "user.email=agent@genex.local", "-c", "user.name=genex", "commit", "-q", "-m", "build"],
806
- gitEnv
807
- );
808
- if (commit.code !== 0 && !/nothing to commit/i.test(commit.out + commit.err)) {
825
+ if (!mainTree || mainTree === EMPTY_TREE) {
809
826
  log.warn("Nothing to commit \u2014 the build produced no files.");
810
827
  return false;
811
828
  }
829
+ await run("git", ["update-ref", "refs/heads/main", await commitTree(mainTree, "build")], base);
830
+ let pushSource = false;
831
+ if (siteDir !== cwd) {
832
+ try {
833
+ const srcTree = await stage(cwd, "index-source");
834
+ if (srcTree && srcTree !== EMPTY_TREE) {
835
+ await run("git", ["update-ref", "refs/heads/source", await commitTree(srcTree, "source")], base);
836
+ pushSource = true;
837
+ }
838
+ } catch {
839
+ log.dim(" (Couldn't publish source for remixing \u2014 the deploy key was in the way.)");
840
+ }
841
+ }
812
842
  log.step("Pushing your game over SSH\u2026");
813
- const push = await run("git", ["push", "-q", sshUrl, "+HEAD:main"], {
814
- ...gitEnv,
815
- GIT_SSH_COMMAND: `ssh -i ${keyPath} -o IdentitiesOnly=yes -o StrictHostKeyChecking=accept-new`
816
- });
843
+ const refspecs = ["+refs/heads/main:main"];
844
+ if (pushSource) refspecs.push("+refs/heads/source:source");
845
+ const push = await run(
846
+ "git",
847
+ ["push", "-q", ...pushSource ? ["--atomic"] : [], sshUrl, ...refspecs],
848
+ {
849
+ ...base,
850
+ // Quote the key path: git splits GIT_SSH_COMMAND with shell-like rules, so a
851
+ // project folder with a space (e.g. "fly drone") otherwise breaks the `-i`
852
+ // argument and ssh fails with "Could not resolve hostname …".
853
+ GIT_SSH_COMMAND: `ssh -i "${keyPath}" -o IdentitiesOnly=yes -o StrictHostKeyChecking=accept-new`
854
+ }
855
+ );
817
856
  if (push.code === 0) {
818
857
  log.success("Pushed.");
819
858
  if (opts.playUrl) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@genex-ai/cli-demo",
3
- "version": "0.6.2",
3
+ "version": "0.7.0",
4
4
  "description": "Set up your ~/.claude workspace, authorize, create a game project, generate AI assets, and publish (genex CLI).",
5
5
  "type": "module",
6
6
  "bin": {