@a5gard/asgard 0.0.1 → 0.0.3

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 (134) hide show
  1. package/.env +2 -1
  2. package/.vscode/ntrsync/10516_DevStack_todo.md +1 -23
  3. package/.vscode/ntrsync/10519_Catalyst Software_todo.md +57 -63
  4. package/.vscode/ntrsync/10526_self evaluation_todo.md +0 -0
  5. package/.vscode/ntrsync/10527_self eval.md +335 -0
  6. package/README.md +4 -2
  7. package/dist/commands/add-source.d.ts.map +1 -1
  8. package/dist/commands/add-source.js +3 -2
  9. package/dist/commands/add-source.js.map +1 -1
  10. package/dist/commands/combine-timelines.d.ts.map +1 -1
  11. package/dist/commands/combine-timelines.js +5 -3
  12. package/dist/commands/combine-timelines.js.map +1 -1
  13. package/dist/commands/create-config.d.ts +4 -0
  14. package/dist/commands/create-config.d.ts.map +1 -0
  15. package/dist/commands/create-config.js +7 -0
  16. package/dist/commands/create-config.js.map +1 -0
  17. package/dist/commands/create-project.d.ts.map +1 -1
  18. package/dist/commands/create-project.js +10 -11
  19. package/dist/commands/create-project.js.map +1 -1
  20. package/dist/commands/create-timeline.d.ts.map +1 -1
  21. package/dist/commands/create-timeline.js +3 -1
  22. package/dist/commands/create-timeline.js.map +1 -1
  23. package/dist/commands/delete-project.d.ts.map +1 -1
  24. package/dist/commands/delete-project.js +4 -2
  25. package/dist/commands/delete-project.js.map +1 -1
  26. package/dist/commands/delete-source.d.ts.map +1 -1
  27. package/dist/commands/delete-source.js +4 -2
  28. package/dist/commands/delete-source.js.map +1 -1
  29. package/dist/commands/delete-timeline.d.ts.map +1 -1
  30. package/dist/commands/delete-timeline.js +5 -3
  31. package/dist/commands/delete-timeline.js.map +1 -1
  32. package/dist/commands/delete-version.d.ts.map +1 -1
  33. package/dist/commands/delete-version.js +5 -4
  34. package/dist/commands/delete-version.js.map +1 -1
  35. package/dist/commands/download-file.d.ts.map +1 -1
  36. package/dist/commands/download-file.js +2 -1
  37. package/dist/commands/download-file.js.map +1 -1
  38. package/dist/commands/download-folder.d.ts.map +1 -1
  39. package/dist/commands/download-folder.js +2 -1
  40. package/dist/commands/download-folder.js.map +1 -1
  41. package/dist/commands/download-source.d.ts.map +1 -1
  42. package/dist/commands/download-source.js +2 -0
  43. package/dist/commands/download-source.js.map +1 -1
  44. package/dist/commands/gh-setup.d.ts.map +1 -1
  45. package/dist/commands/gh-setup.js +5 -42
  46. package/dist/commands/gh-setup.js.map +1 -1
  47. package/dist/commands/load-project.d.ts.map +1 -1
  48. package/dist/commands/load-project.js +4 -2
  49. package/dist/commands/load-project.js.map +1 -1
  50. package/dist/commands/midgardr.d.ts.map +1 -1
  51. package/dist/commands/midgardr.js +4 -3
  52. package/dist/commands/midgardr.js.map +1 -1
  53. package/dist/commands/publish-project.d.ts.map +1 -1
  54. package/dist/commands/publish-project.js +73 -23
  55. package/dist/commands/publish-project.js.map +1 -1
  56. package/dist/commands/replace-timeline.d.ts.map +1 -1
  57. package/dist/commands/replace-timeline.js +6 -4
  58. package/dist/commands/replace-timeline.js.map +1 -1
  59. package/dist/commands/restore-version.d.ts.map +1 -1
  60. package/dist/commands/restore-version.js +7 -5
  61. package/dist/commands/restore-version.js.map +1 -1
  62. package/dist/commands/save-project.d.ts.map +1 -1
  63. package/dist/commands/save-project.js +2 -0
  64. package/dist/commands/save-project.js.map +1 -1
  65. package/dist/commands/set-source.d.ts.map +1 -1
  66. package/dist/commands/set-source.js +3 -2
  67. package/dist/commands/set-source.js.map +1 -1
  68. package/dist/commands/switch-timeline.d.ts.map +1 -1
  69. package/dist/commands/switch-timeline.js +5 -3
  70. package/dist/commands/switch-timeline.js.map +1 -1
  71. package/dist/commands/sync-source.d.ts.map +1 -1
  72. package/dist/commands/sync-source.js +2 -1
  73. package/dist/commands/sync-source.js.map +1 -1
  74. package/dist/commands/upload-project+++.d.ts.map +1 -1
  75. package/dist/commands/upload-project+++.js +2 -0
  76. package/dist/commands/upload-project+++.js.map +1 -1
  77. package/dist/commands/upload-project++.d.ts.map +1 -1
  78. package/dist/commands/upload-project++.js +2 -0
  79. package/dist/commands/upload-project++.js.map +1 -1
  80. package/dist/commands/upload-project+.d.ts.map +1 -1
  81. package/dist/commands/upload-project+.js +2 -0
  82. package/dist/commands/upload-project+.js.map +1 -1
  83. package/dist/commands/upload-project.d.ts.map +1 -1
  84. package/dist/commands/upload-project.js +3 -2
  85. package/dist/commands/upload-project.js.map +1 -1
  86. package/dist/commands/view-timeline.d.ts.map +1 -1
  87. package/dist/commands/view-timeline.js +5 -3
  88. package/dist/commands/view-timeline.js.map +1 -1
  89. package/dist/commands/view-versions.d.ts.map +1 -1
  90. package/dist/commands/view-versions.js +3 -2
  91. package/dist/commands/view-versions.js.map +1 -1
  92. package/dist/git/helpers.d.ts +5 -1
  93. package/dist/git/helpers.d.ts.map +1 -1
  94. package/dist/git/helpers.js +102 -15
  95. package/dist/git/helpers.js.map +1 -1
  96. package/dist/git/sync-repo.d.ts +6 -1
  97. package/dist/git/sync-repo.d.ts.map +1 -1
  98. package/dist/git/sync-repo.js +173 -5
  99. package/dist/git/sync-repo.js.map +1 -1
  100. package/dist/utils/box.d.ts +1 -0
  101. package/dist/utils/box.d.ts.map +1 -1
  102. package/dist/utils/box.js +102 -20
  103. package/dist/utils/box.js.map +1 -1
  104. package/package.json +2 -2
  105. package/src/commands/add-source.js +3 -2
  106. package/src/commands/combine-timelines.js +6 -3
  107. package/src/commands/create-config.js +8 -0
  108. package/src/commands/create-project.js +10 -11
  109. package/src/commands/create-timeline.js +5 -2
  110. package/src/commands/delete-project.js +5 -2
  111. package/src/commands/delete-source.js +4 -2
  112. package/src/commands/delete-timeline.js +5 -3
  113. package/src/commands/delete-version.js +5 -4
  114. package/src/commands/download-file.js +2 -1
  115. package/src/commands/download-folder.js +3 -2
  116. package/src/commands/download-source.js +2 -0
  117. package/src/commands/gh-setup.js +3 -2
  118. package/src/commands/load-project.js +5 -2
  119. package/src/commands/midgardr.js +4 -3
  120. package/src/commands/publish-project.js +16 -18
  121. package/src/commands/replace-timeline.js +6 -4
  122. package/src/commands/restore-version.js +8 -5
  123. package/src/commands/save-project.js +2 -0
  124. package/src/commands/set-source.js +3 -2
  125. package/src/commands/switch-timeline.js +5 -3
  126. package/src/commands/sync-source.js +3 -1
  127. package/src/commands/upload-project+++.js +2 -0
  128. package/src/commands/upload-project++.js +4 -1
  129. package/src/commands/upload-project+.js +5 -0
  130. package/src/commands/upload-project.js +6 -3
  131. package/src/commands/view-timeline.js +5 -3
  132. package/src/commands/view-versions.js +4 -3
  133. package/src/git/helpers.js +113 -18
  134. package/src/git/sync-repo.js +190 -5
@@ -2,15 +2,200 @@ import fs from 'fs-extra';
2
2
  import path from 'path';
3
3
  import simpleGit from 'simple-git';
4
4
  import { execSync } from 'child_process';
5
+ import { Pwsh } from '../git/helpers.js'
6
+ import inquirer from 'inquirer';
7
+ import { fileURLToPath } from 'url';
8
+ import 'dotenv/config';
5
9
 
6
- export async function syncRepo() {
10
+ const CONFIG_PATH = path.join(process.cwd(), 'config.asgard');
11
+
12
+ export async function promptConfig() {
13
+ let existingConfig = {};
14
+
15
+ if (fs.existsSync(CONFIG_PATH)) {
16
+ existingConfig = JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf-8'));
17
+ }
18
+ const currentDir = process.cwd();
19
+ const questions = [
20
+ {
21
+ type: 'input',
22
+ name: 'owner',
23
+ message: 'GitHub Owner (Username or Org):',
24
+ default: existingConfig.owner,
25
+ validate: (input) => input ? true : 'Owner is required',
26
+ },
27
+ {
28
+ type: 'input',
29
+ name: 'repo',
30
+ message: 'GitHub Repository Name:',
31
+ default: existingConfig.repo,
32
+ validate: (input) => input ? true : 'Repo is required',
33
+ },
34
+ {
35
+ type: 'list',
36
+ name: 'pkgMgr',
37
+ message: 'Package Manager:',
38
+ choices: ['npm', 'yarn', 'pnpm', 'bun'],
39
+ default: existingConfig.pkgMgr || 'npm',
40
+ },
41
+ {
42
+ type: 'input',
43
+ name: 'branch',
44
+ message: 'Default Branch:',
45
+ default: existingConfig.branch || 'main',
46
+ },
47
+ {
48
+ type: 'input',
49
+ name: 'workspacePath',
50
+ message: 'Confirm Workspace Root Path:',
51
+ default: currentDir, // Just defaults to where you are
52
+ },
53
+ {
54
+ type: 'confirm',
55
+ name: 'icons',
56
+ message: 'Enable Icons?',
57
+ default: existingConfig.icons || false,
58
+ },
59
+ {
60
+ type: 'confirm',
61
+ name: 'uiComps',
62
+ message: 'Enable UI Components?',
63
+ default: existingConfig.uiComps || false,
64
+ }
65
+ ];
66
+
67
+ const answers = await inquirer.prompt(questions);
68
+ fs.writeFileSync(CONFIG_PATH, JSON.stringify(answers, null, 2));
69
+ return {
70
+ ...answers,
71
+ token: process.env.GITHUB_TOKEN,
72
+ };
73
+ }
74
+ export async function syncRepo1() {
7
75
  try {
8
76
  const cwd = process.cwd();
9
- execSync('git add .', { cwd, stdio: 'inherit' });
10
- execSync('git commit -m "Syncing local repo with remote" || true', { cwd, stdio: 'inherit' });
11
- execSync('git pull --rebase', { cwd, stdio: 'inherit' });
12
- execSync('git push', { cwd, stdio: 'inherit' });
77
+ await Pwsh('git add *');
78
+ await Pwsh('git diff --cached --quiet || git commit -m "Syncing local repo with remote"');
79
+ await Pwsh('git pull --rebase');
80
+ await Pwsh('git push');
13
81
  } catch (error) {
14
82
  throw new Error(`Sync failed on branch detection/sync: ${error.message}`);
15
83
  }
84
+ }
85
+
86
+ const configasgard = {
87
+ repo: '',
88
+ owner: '',
89
+ pkgMgr: '',
90
+ branch: '',
91
+ workspacePath: '',
92
+ icons: false,
93
+ uiComps: false,
94
+ }
95
+ export async function getLocalFiles(dir, baseDir = dir) {
96
+ const files = fs.readdirSync(dir);
97
+ let results = [];
98
+
99
+ for (const file of files) {
100
+ const fullPath = path.join(dir, file);
101
+ if (fs.statSync(fullPath).isDirectory()) {
102
+ results = results.concat(await this.getLocalFiles(fullPath, baseDir));
103
+ } else {
104
+ const relativePath = path.relative(baseDir, fullPath).replace(/\\/g, '/');
105
+ const content = fs.readFileSync(fullPath, { encoding: 'base64' });
106
+ results.push({ path: relativePath, content });
107
+ }
108
+ }
109
+ return results;
110
+ }
111
+
112
+ export async function pushChanges(okit, owner, repo, branch, files, message) {
113
+ const { data: refData } = await okit.rest.git.getRef({ owner, repo, ref: `heads/${branch}` });
114
+ const currentCommitSha = refData.object.sha;
115
+
116
+ const { data: commitData } = await okit.rest.git.getCommit({ owner, repo, commit_sha: currentCommitSha });
117
+
118
+ const tree = files.map(file => ({
119
+ path: file.path,
120
+ mode: '100644',
121
+ type: 'blob',
122
+ content: Buffer.from(file.content, 'base64').toString('utf-8')
123
+ }));
124
+
125
+ const { data: treeData } = await okit.rest.git.createTree({
126
+ owner, repo, tree, base_tree: commitData.tree.sha
127
+ });
128
+
129
+ const { data: newCommitData } = await okit.rest.git.createCommit({
130
+ owner, repo, message, tree: treeData.sha, parents: [currentCommitSha]
131
+ });
132
+
133
+ await okit.rest.git.updateRef({
134
+ owner, repo, ref: `heads/${branch}`, sha: newCommitData.sha
135
+ });
136
+ }
137
+
138
+ export async function pullLatestChanges(okit, owner, repo, branch, workspacePath) {
139
+ try {
140
+ const refResponse = await okit.rest.git.getRef({ owner, repo, ref: `heads/${branch}` });
141
+ const latestCommitSha = refResponse.data.object.sha;
142
+
143
+ const commitResponse = await okit.rest.git.getCommit({ owner, repo, commit_sha: latestCommitSha });
144
+
145
+ const treeResponse = await okit.rest.git.getTree({
146
+ owner,
147
+ repo,
148
+ tree_sha: commitResponse.data.tree.sha,
149
+ recursive: 'true'
150
+ });
151
+
152
+ for (const item of treeResponse.data.tree) {
153
+ if (item.type === 'blob' && item.path) {
154
+ if (!item.sha) continue;
155
+
156
+ const blobResponse = await okit.rest.git.getBlob({ owner, repo, file_sha: item.sha });
157
+ const content = Buffer.from(blobResponse.data.content, 'base64').toString('utf-8');
158
+
159
+ const filePath = path.join(workspacePath, item.path);
160
+ const fileDir = path.dirname(filePath);
161
+
162
+ if (!fs.existsSync(fileDir)) {
163
+ fs.mkdirSync(fileDir, { recursive: true });
164
+ }
165
+
166
+ fs.writeFileSync(filePath, content);
167
+ }
168
+ }
169
+ console.log('Successfully pulled latest changes');
170
+ } catch (error) {
171
+ if (error.status === 404) {
172
+ console.log('Branch does not exist on remote');
173
+ } else {
174
+ console.error('Error pulling changes:', error.message);
175
+ throw error;
176
+ }
177
+ }
178
+ }
179
+
180
+ export async function syncRepo(ctx) {
181
+ const { token, owner, repo, branch, workspacePath } = ctx;
182
+ const okit = new Octokit({ auth: token });
183
+
184
+ try {
185
+ console.log("Syncing via Octokit...");
186
+
187
+ // 1. Pull logic (using your existing snippet)
188
+ await pullLatestChanges(okit, owner, repo, branch, workspacePath);
189
+
190
+ // 2. Scan and Push
191
+ const localFiles = await getLocalFiles(workspacePath);
192
+ if (localFiles.length > 0) {
193
+ await pushChanges(okit, owner, repo, branch, localFiles, "Syncing local repo with remote");
194
+ console.log("Push successful.");
195
+ } else {
196
+ console.log("Nothing to push.");
197
+ }
198
+ } catch (error) {
199
+ console.error(`Sync failed: ${error.message}`);
200
+ }
16
201
  }