@knocklabs/cli 0.1.0-rc.3 → 0.1.0-rc.4
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.
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ $ npm install -g @knocklabs/cli
|
|
|
16
16
|
$ knock COMMAND
|
|
17
17
|
running command...
|
|
18
18
|
$ knock (--version)
|
|
19
|
-
@knocklabs/cli/0.1.0-rc.
|
|
19
|
+
@knocklabs/cli/0.1.0-rc.4 linux-x64 node-v16.4.2
|
|
20
20
|
$ knock --help [COMMAND]
|
|
21
21
|
USAGE
|
|
22
22
|
$ knock COMMAND
|
|
@@ -66,7 +66,7 @@ FLAGS
|
|
|
66
66
|
--service-token=<value> (required) The service token to authenticate with
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
-
_See code: [dist/commands/commit/index.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.0-rc.
|
|
69
|
+
_See code: [dist/commands/commit/index.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.0-rc.4/dist/commands/commit/index.ts)_
|
|
70
70
|
|
|
71
71
|
## `knock commit promote`
|
|
72
72
|
|
|
@@ -118,7 +118,7 @@ EXAMPLES
|
|
|
118
118
|
$ knock ping
|
|
119
119
|
```
|
|
120
120
|
|
|
121
|
-
_See code: [dist/commands/ping.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.0-rc.
|
|
121
|
+
_See code: [dist/commands/ping.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.0-rc.4/dist/commands/ping.ts)_
|
|
122
122
|
|
|
123
123
|
## `knock plugins`
|
|
124
124
|
|
|
@@ -138,7 +138,7 @@ EXAMPLES
|
|
|
138
138
|
$ knock plugins
|
|
139
139
|
```
|
|
140
140
|
|
|
141
|
-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v2.4.
|
|
141
|
+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v2.4.7/src/commands/plugins/index.ts)_
|
|
142
142
|
|
|
143
143
|
## `knock plugins:install PLUGIN...`
|
|
144
144
|
|
|
@@ -76,7 +76,7 @@ class TranslationPull extends _baseCommand.default {
|
|
|
76
76
|
exists: true
|
|
77
77
|
};
|
|
78
78
|
const targetDirCtx = flags["translations-dir"] || defaultToCwd;
|
|
79
|
-
const prompt = targetDirCtx.exists ? `Pull latest translations into ${targetDirCtx.abspath}
|
|
79
|
+
const prompt = targetDirCtx.exists ? `Pull latest translations into ${targetDirCtx.abspath}?\n This will overwrite the contents of this directory.` : `Create a new translations directory at ${targetDirCtx.abspath}?`;
|
|
80
80
|
const input = flags.force || await (0, _ux.promptToConfirm)(prompt);
|
|
81
81
|
if (!input) return;
|
|
82
82
|
// Fetch all translations then write them to the local file system.
|
|
@@ -137,7 +137,7 @@ class WorkflowPull extends _baseCommand.default {
|
|
|
137
137
|
exists: true
|
|
138
138
|
};
|
|
139
139
|
const targetDirCtx = flags["workflows-dir"] || defaultToCwd;
|
|
140
|
-
const prompt = targetDirCtx.exists ? `Pull latest workflows into ${targetDirCtx.abspath}
|
|
140
|
+
const prompt = targetDirCtx.exists ? `Pull latest workflows into ${targetDirCtx.abspath}?\n This will overwrite the contents of this directory.` : `Create a new workflows directory at ${targetDirCtx.abspath}?`;
|
|
141
141
|
const input = flags.force || await (0, _ux.promptToConfirm)(prompt);
|
|
142
142
|
if (!input) return;
|
|
143
143
|
// Fetch all workflows then write them to the local file system.
|
|
@@ -58,7 +58,7 @@ const writeTranslationsIndexDir = async (indexDirCtx, translations)=>{
|
|
|
58
58
|
// before wiping it clean.
|
|
59
59
|
if (indexDirCtx.exists) {
|
|
60
60
|
await _fsExtra.copy(indexDirCtx.abspath, backupDirPath);
|
|
61
|
-
await _fsExtra.
|
|
61
|
+
await _fsExtra.emptyDir(indexDirCtx.abspath);
|
|
62
62
|
}
|
|
63
63
|
// Write given remote translations into the given translations directory path.
|
|
64
64
|
const writeTranslationDirPromises = translations.map(async (translation)=>{
|
|
@@ -72,9 +72,11 @@ const writeTranslationsIndexDir = async (indexDirCtx, translations)=>{
|
|
|
72
72
|
} catch (error) {
|
|
73
73
|
// In case of any error, wipe the index directory that is likely in a bad
|
|
74
74
|
// state then restore the backup if one existed before.
|
|
75
|
-
await _fsExtra.remove(indexDirCtx.abspath);
|
|
76
75
|
if (indexDirCtx.exists) {
|
|
76
|
+
await _fsExtra.emptyDir(indexDirCtx.abspath);
|
|
77
77
|
await _fsExtra.copy(backupDirPath, indexDirCtx.abspath);
|
|
78
|
+
} else {
|
|
79
|
+
await _fsExtra.remove(indexDirCtx.abspath);
|
|
78
80
|
}
|
|
79
81
|
throw error;
|
|
80
82
|
} finally{
|
|
@@ -14,6 +14,7 @@ _export(exports, {
|
|
|
14
14
|
writeWorkflowsIndexDir: ()=>writeWorkflowsIndexDir,
|
|
15
15
|
buildWorkflowDirBundle: ()=>buildWorkflowDirBundle,
|
|
16
16
|
formatExtractedFilePath: ()=>formatExtractedFilePath,
|
|
17
|
+
pruneWorkflowsIndexDir: ()=>pruneWorkflowsIndexDir,
|
|
17
18
|
toWorkflowJson: ()=>toWorkflowJson
|
|
18
19
|
});
|
|
19
20
|
const _nodePath = /*#__PURE__*/ _interopRequireWildcard(require("node:path"));
|
|
@@ -265,10 +266,12 @@ const writeWorkflowDirFromData = async (workflowDirCtx, remoteWorkflow)=>{
|
|
|
265
266
|
return writeWorkflowDirFromBundle(workflowDirCtx, bundle);
|
|
266
267
|
};
|
|
267
268
|
const writeWorkflowDirFromBundle = async (workflowDirCtx, workflowDirBundle)=>{
|
|
269
|
+
const backupDirPath = _nodePath.resolve(_const.sandboxDir, (0, _lodash.uniqueId)("backup"));
|
|
268
270
|
try {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
271
|
+
if (workflowDirCtx.exists) {
|
|
272
|
+
await _fsExtra.copy(workflowDirCtx.abspath, backupDirPath);
|
|
273
|
+
await _fsExtra.emptyDir(workflowDirCtx.abspath);
|
|
274
|
+
}
|
|
272
275
|
const promises = Object.entries(workflowDirBundle).map(([relpath, fileContent])=>{
|
|
273
276
|
const filePath = _nodePath.resolve(workflowDirCtx.abspath, relpath);
|
|
274
277
|
return relpath === _helpers.WORKFLOW_JSON ? _fsExtra.outputJson(filePath, fileContent, {
|
|
@@ -277,10 +280,43 @@ const writeWorkflowDirFromBundle = async (workflowDirCtx, workflowDirBundle)=>{
|
|
|
277
280
|
});
|
|
278
281
|
await Promise.all(promises);
|
|
279
282
|
} catch (error) {
|
|
280
|
-
|
|
283
|
+
// In case of any error, wipe the target directory that is likely in a bad
|
|
284
|
+
// state then restore the backup if one existed before.
|
|
285
|
+
if (workflowDirCtx.exists) {
|
|
286
|
+
await _fsExtra.emptyDir(workflowDirCtx.abspath);
|
|
287
|
+
await _fsExtra.copy(backupDirPath, workflowDirCtx.abspath);
|
|
288
|
+
} else {
|
|
289
|
+
await _fsExtra.remove(workflowDirCtx.abspath);
|
|
290
|
+
}
|
|
281
291
|
throw error;
|
|
292
|
+
} finally{
|
|
293
|
+
// Always clean up the backup directory in the temp sandbox.
|
|
294
|
+
await _fsExtra.remove(backupDirPath);
|
|
282
295
|
}
|
|
283
296
|
};
|
|
297
|
+
/*
|
|
298
|
+
* Prunes the index directory by removing any files, or directories that aren't
|
|
299
|
+
* workflow dirs found in fetched workflows. We want to preserve any workflow
|
|
300
|
+
* dirs that are going to be updated with remote workflows, so extracted links
|
|
301
|
+
* can be respected.
|
|
302
|
+
*/ const pruneWorkflowsIndexDir = async (indexDirCtx, remoteWorkflows)=>{
|
|
303
|
+
const workflowsByKey = Object.fromEntries(remoteWorkflows.map((w)=>[
|
|
304
|
+
w.key.toLowerCase(),
|
|
305
|
+
w
|
|
306
|
+
]));
|
|
307
|
+
const dirents = await _fsExtra.readdir(indexDirCtx.abspath, {
|
|
308
|
+
withFileTypes: true
|
|
309
|
+
});
|
|
310
|
+
const promises = dirents.map(async (dirent)=>{
|
|
311
|
+
const direntName = dirent.name.toLowerCase();
|
|
312
|
+
const direntPath = _nodePath.resolve(indexDirCtx.abspath, direntName);
|
|
313
|
+
if (await (0, _helpers.isWorkflowDir)(direntPath) && workflowsByKey[direntName]) {
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
await _fsExtra.remove(direntPath);
|
|
317
|
+
});
|
|
318
|
+
await Promise.all(promises);
|
|
319
|
+
};
|
|
284
320
|
const writeWorkflowsIndexDir = async (indexDirCtx, remoteWorkflows)=>{
|
|
285
321
|
const backupDirPath = _nodePath.resolve(_const.sandboxDir, (0, _lodash.uniqueId)("backup"));
|
|
286
322
|
try {
|
|
@@ -288,9 +324,7 @@ const writeWorkflowsIndexDir = async (indexDirCtx, remoteWorkflows)=>{
|
|
|
288
324
|
// before wiping it clean.
|
|
289
325
|
if (indexDirCtx.exists) {
|
|
290
326
|
await _fsExtra.copy(indexDirCtx.abspath, backupDirPath);
|
|
291
|
-
|
|
292
|
-
// workflows.
|
|
293
|
-
await _fsExtra.remove(indexDirCtx.abspath);
|
|
327
|
+
await pruneWorkflowsIndexDir(indexDirCtx, remoteWorkflows);
|
|
294
328
|
}
|
|
295
329
|
// Write given remote workflows into the given workflows directory path.
|
|
296
330
|
const writeWorkflowDirPromises = remoteWorkflows.map(async (workflow)=>{
|
|
@@ -307,9 +341,11 @@ const writeWorkflowsIndexDir = async (indexDirCtx, remoteWorkflows)=>{
|
|
|
307
341
|
} catch (error) {
|
|
308
342
|
// In case of any error, wipe the index directory that is likely in a bad
|
|
309
343
|
// state then restore the backup if one existed before.
|
|
310
|
-
await _fsExtra.remove(indexDirCtx.abspath);
|
|
311
344
|
if (indexDirCtx.exists) {
|
|
345
|
+
await _fsExtra.emptyDir(indexDirCtx.abspath);
|
|
312
346
|
await _fsExtra.copy(backupDirPath, indexDirCtx.abspath);
|
|
347
|
+
} else {
|
|
348
|
+
await _fsExtra.remove(indexDirCtx.abspath);
|
|
313
349
|
}
|
|
314
350
|
throw error;
|
|
315
351
|
} finally{
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knocklabs/cli",
|
|
3
|
-
"version": "0.1.0-rc.
|
|
3
|
+
"version": "0.1.0-rc.4",
|
|
4
4
|
"description": "Knock CLI",
|
|
5
5
|
"author": "@knocklabs",
|
|
6
6
|
"bin": {
|
|
@@ -19,13 +19,13 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@oclif/core": "^1.26.2",
|
|
21
21
|
"@oclif/plugin-help": "^5",
|
|
22
|
-
"@oclif/plugin-plugins": "^2.4.
|
|
22
|
+
"@oclif/plugin-plugins": "^2.4.7",
|
|
23
23
|
"@prantlf/jsonlint": "^11.7.2",
|
|
24
|
-
"axios": "^1.
|
|
24
|
+
"axios": "^1.4.0",
|
|
25
25
|
"date-fns": "^2.29.3",
|
|
26
26
|
"enquirer": "^2.3.6",
|
|
27
27
|
"fs-extra": "^10.1.0",
|
|
28
|
-
"liquidjs": "^10.7.
|
|
28
|
+
"liquidjs": "^10.7.1",
|
|
29
29
|
"locale-codes": "^1.3.1",
|
|
30
30
|
"lodash": "^4.17.21",
|
|
31
31
|
"yup": "^0.32.11"
|