dorky 4.1.2 → 4.1.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 (3) hide show
  1. package/bin/index.js +6 -5
  2. package/bin/mcp.js +34 -34
  3. package/package.json +1 -1
package/bin/index.js CHANGED
@@ -96,7 +96,7 @@ async function authorizeGoogleDriveClient(forceReauth = false) {
96
96
  }
97
97
 
98
98
  async function init(storage) {
99
- if (existsSync(DORKY_DIR)) return console.log(chalk.yellow("⚠ Dorky is already initialized."));
99
+ if (existsSync(CREDENTIALS_PATH)) return console.log(chalk.yellow("⚠ Dorky is already initialized."));
100
100
  if (!["aws", "google-drive"].includes(storage)) return console.log(chalk.red("✖ Invalid storage. Use 'aws' or 'google-drive'."));
101
101
 
102
102
  let credentials = {};
@@ -107,14 +107,15 @@ async function init(storage) {
107
107
  }
108
108
  credentials = { storage: "aws", accessKey: process.env.AWS_ACCESS_KEY, secretKey: process.env.AWS_SECRET_KEY, awsRegion: process.env.AWS_REGION, bucket: process.env.BUCKET_NAME };
109
109
  } else {
110
+ if (!existsSync(DORKY_DIR)) mkdirSync(DORKY_DIR);
110
111
  const client = await authorizeGoogleDriveClient(true);
111
112
  credentials = { storage: "google-drive", ...client.credentials };
112
113
  }
113
114
 
114
- mkdirSync(DORKY_DIR);
115
- writeJson(METADATA_PATH, { "stage-1-files": {}, "uploaded-files": {} });
116
- writeJson(HISTORY_PATH, []);
117
- writeFileSync(".dorkyignore", "");
115
+ if (!existsSync(DORKY_DIR)) mkdirSync(DORKY_DIR);
116
+ if (!existsSync(METADATA_PATH)) writeJson(METADATA_PATH, { "stage-1-files": {}, "uploaded-files": {} });
117
+ if (!existsSync(HISTORY_PATH)) writeJson(HISTORY_PATH, []);
118
+ if (!existsSync(".dorkyignore")) writeFileSync(".dorkyignore", "");
118
119
  writeJson(CREDENTIALS_PATH, credentials);
119
120
  console.log(chalk.green("✔ Dorky project initialized successfully."));
120
121
  updateGitIgnore();
package/bin/mcp.js CHANGED
@@ -68,7 +68,7 @@ async function authorizeGoogleDriveClient(forceReauth = false) {
68
68
  }
69
69
 
70
70
  async function init(storage) {
71
- if (existsSync(DORKY_DIR)) return "Dorky is already initialized.";
71
+ if (existsSync(CREDENTIALS_PATH)) return "Dorky is already initialized.";
72
72
  if (!["aws", "google-drive"].includes(storage)) return "Invalid storage. Use 'aws' or 'google-drive'.";
73
73
 
74
74
  let credentials = {};
@@ -78,14 +78,15 @@ async function init(storage) {
78
78
  }
79
79
  credentials = { storage: "aws", accessKey: process.env.AWS_ACCESS_KEY, secretKey: process.env.AWS_SECRET_KEY, awsRegion: process.env.AWS_REGION, bucket: process.env.BUCKET_NAME };
80
80
  } else {
81
+ if (!existsSync(DORKY_DIR)) mkdirSync(DORKY_DIR);
81
82
  const client = await authorizeGoogleDriveClient(true);
82
83
  credentials = { storage: "google-drive", ...client.credentials };
83
84
  }
84
85
 
85
- mkdirSync(DORKY_DIR);
86
- writeJson(METADATA_PATH, { "stage-1-files": {}, "uploaded-files": {} });
87
- writeJson(HISTORY_PATH, []);
88
- writeFileSync(".dorkyignore", "");
86
+ if (!existsSync(DORKY_DIR)) mkdirSync(DORKY_DIR);
87
+ if (!existsSync(METADATA_PATH)) writeJson(METADATA_PATH, { "stage-1-files": {}, "uploaded-files": {} });
88
+ if (!existsSync(HISTORY_PATH)) writeJson(HISTORY_PATH, []);
89
+ if (!existsSync(".dorkyignore")) writeFileSync(".dorkyignore", "");
89
90
  writeJson(CREDENTIALS_PATH, credentials);
90
91
  updateGitIgnore();
91
92
  return "Dorky project initialized successfully.";
@@ -243,6 +244,11 @@ async function push() {
243
244
 
244
245
  if (filesToUpload.length === 0 && filesToDelete.length === 0) return "Nothing to push.";
245
246
 
247
+ const commitFiles = { ...meta["stage-1-files"] };
248
+ const commitId = md5(JSON.stringify(commitFiles)).slice(0, 8);
249
+ const history = existsSync(HISTORY_PATH) ? JSON.parse(readFileSync(HISTORY_PATH)) : [];
250
+ if (history.length > 0 && history[history.length - 1].id === commitId) return "Already on the latest commit. Nothing to push.";
251
+
246
252
  const creds = readJson(CREDENTIALS_PATH);
247
253
  const results = [];
248
254
 
@@ -295,35 +301,30 @@ async function push() {
295
301
  meta["uploaded-files"] = { ...meta["stage-1-files"] };
296
302
  writeJson(METADATA_PATH, meta);
297
303
 
298
- const commitFiles = { ...meta["stage-1-files"] };
299
- const commitId = md5(JSON.stringify(commitFiles)).slice(0, 8);
300
- const history = existsSync(HISTORY_PATH) ? JSON.parse(readFileSync(HISTORY_PATH)) : [];
301
- if (!history.find(e => e.id === commitId)) {
302
- history.push({ id: commitId, timestamp: new Date().toISOString(), files: commitFiles });
303
- writeJson(HISTORY_PATH, history);
304
+ history.push({ id: commitId, timestamp: new Date().toISOString(), files: commitFiles });
305
+ writeJson(HISTORY_PATH, history);
304
306
 
305
- const root = path.basename(process.cwd());
306
- const historyPrefix = path.join(root, ".dorky-history", commitId);
307
- if (creds.storage === "aws") {
308
- await runS3(creds, async (s3, bucket) => {
309
- await Promise.all(Object.keys(commitFiles).map(async f => {
310
- const key = path.join(historyPrefix, f);
311
- await s3.send(new PutObjectCommand({ Bucket: bucket, Key: key, Body: readFileSync(f) }));
312
- }));
313
- });
314
- } else if (creds.storage === "google-drive") {
315
- await runDrive(async (drive) => {
316
- for (const f of Object.keys(commitFiles)) {
317
- const parentId = await getFolderId(path.join(root, ".dorky-history", commitId, path.dirname(f)), drive);
318
- await drive.files.create({
319
- requestBody: { name: path.basename(f), parents: [parentId] },
320
- media: { mimeType: commitFiles[f]["mime-type"], body: createReadStream(f) }
321
- });
322
- }
323
- });
324
- }
325
- results.push(`History commit saved: ${commitId}`);
307
+ const root = path.basename(process.cwd());
308
+ const historyPrefix = path.join(root, ".dorky-history", commitId);
309
+ if (creds.storage === "aws") {
310
+ await runS3(creds, async (s3, bucket) => {
311
+ await Promise.all(Object.keys(commitFiles).map(async f => {
312
+ const key = path.join(historyPrefix, f);
313
+ await s3.send(new PutObjectCommand({ Bucket: bucket, Key: key, Body: readFileSync(f) }));
314
+ }));
315
+ });
316
+ } else if (creds.storage === "google-drive") {
317
+ await runDrive(async (drive) => {
318
+ for (const f of Object.keys(commitFiles)) {
319
+ const parentId = await getFolderId(path.join(root, ".dorky-history", commitId, path.dirname(f)), drive);
320
+ await drive.files.create({
321
+ requestBody: { name: path.basename(f), parents: [parentId] },
322
+ media: { mimeType: commitFiles[f]["mime-type"], body: createReadStream(f) }
323
+ });
324
+ }
325
+ });
326
326
  }
327
+ results.push(`History commit saved: ${commitId}`);
327
328
 
328
329
  return results.join("\n");
329
330
  }
@@ -422,9 +423,8 @@ async function checkout(commitId) {
422
423
 
423
424
  const meta = readJson(METADATA_PATH);
424
425
  meta["stage-1-files"] = { ...entry.files };
425
- meta["uploaded-files"] = { ...entry.files };
426
426
  writeJson(METADATA_PATH, meta);
427
- results.push(`Staged and uploaded state restored to commit ${entry.id}.`);
427
+ results.push(`Staged state restored to commit ${entry.id}. Run push to publish this state.`);
428
428
  return results.join("\n");
429
429
  }
430
430
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dorky",
3
- "version": "4.1.2",
3
+ "version": "4.1.3",
4
4
  "description": "DevOps Records Keeper.",
5
5
  "bin": {
6
6
  "dorky": "bin/index.js",