@positronic/cli 0.0.2
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/dist/src/cli.js +739 -0
- package/dist/src/commands/backend.js +199 -0
- package/dist/src/commands/brain.js +446 -0
- package/dist/src/commands/brain.test.js +2936 -0
- package/dist/src/commands/helpers.js +1315 -0
- package/dist/src/commands/helpers.test.js +832 -0
- package/dist/src/commands/project-config-manager.js +197 -0
- package/dist/src/commands/project.js +130 -0
- package/dist/src/commands/project.test.js +1201 -0
- package/dist/src/commands/resources.js +272 -0
- package/dist/src/commands/resources.test.js +2511 -0
- package/dist/src/commands/schedule.js +73 -0
- package/dist/src/commands/schedule.test.js +1235 -0
- package/dist/src/commands/secret.js +87 -0
- package/dist/src/commands/secret.test.d.js +1 -0
- package/dist/src/commands/secret.test.js +761 -0
- package/dist/src/commands/server.js +816 -0
- package/dist/src/commands/server.test.js +1237 -0
- package/dist/src/commands/test-utils.js +737 -0
- package/dist/src/components/brain-history.js +169 -0
- package/dist/src/components/brain-list.js +108 -0
- package/dist/src/components/brain-rerun.js +313 -0
- package/dist/src/components/brain-show.js +65 -0
- package/dist/src/components/error.js +19 -0
- package/dist/src/components/project-add.js +95 -0
- package/dist/src/components/project-create.js +276 -0
- package/dist/src/components/project-list.js +88 -0
- package/dist/src/components/project-remove.js +91 -0
- package/dist/src/components/project-select.js +224 -0
- package/dist/src/components/project-show.js +41 -0
- package/dist/src/components/resource-clear.js +152 -0
- package/dist/src/components/resource-delete.js +189 -0
- package/dist/src/components/resource-list.js +174 -0
- package/dist/src/components/resource-sync.js +386 -0
- package/dist/src/components/resource-types.js +243 -0
- package/dist/src/components/resource-upload.js +366 -0
- package/dist/src/components/schedule-create.js +259 -0
- package/dist/src/components/schedule-delete.js +161 -0
- package/dist/src/components/schedule-list.js +176 -0
- package/dist/src/components/schedule-runs.js +103 -0
- package/dist/src/components/secret-bulk.js +262 -0
- package/dist/src/components/secret-create.js +199 -0
- package/dist/src/components/secret-delete.js +190 -0
- package/dist/src/components/secret-list.js +190 -0
- package/dist/src/components/secret-sync.js +303 -0
- package/dist/src/components/watch.js +184 -0
- package/dist/src/hooks/useApi.js +512 -0
- package/dist/src/positronic.js +33 -0
- package/dist/src/test/mock-api-client.js +371 -0
- package/dist/src/test/test-dev-server.js +1376 -0
- package/dist/types/cli.d.ts +9 -0
- package/dist/types/cli.d.ts.map +1 -0
- package/dist/types/commands/backend.d.ts +6 -0
- package/dist/types/commands/backend.d.ts.map +1 -0
- package/dist/types/commands/brain.d.ts +35 -0
- package/dist/types/commands/brain.d.ts.map +1 -0
- package/dist/types/commands/helpers.d.ts +55 -0
- package/dist/types/commands/helpers.d.ts.map +1 -0
- package/dist/types/commands/project-config-manager.d.ts +37 -0
- package/dist/types/commands/project-config-manager.d.ts.map +1 -0
- package/dist/types/commands/project.d.ts +55 -0
- package/dist/types/commands/project.d.ts.map +1 -0
- package/dist/types/commands/resources.d.ts +13 -0
- package/dist/types/commands/resources.d.ts.map +1 -0
- package/dist/types/commands/schedule.d.ts +27 -0
- package/dist/types/commands/schedule.d.ts.map +1 -0
- package/dist/types/commands/secret.d.ts +23 -0
- package/dist/types/commands/secret.d.ts.map +1 -0
- package/dist/types/commands/server.d.ts +12 -0
- package/dist/types/commands/server.d.ts.map +1 -0
- package/dist/types/commands/test-utils.d.ts +45 -0
- package/dist/types/commands/test-utils.d.ts.map +1 -0
- package/dist/types/components/brain-history.d.ts +7 -0
- package/dist/types/components/brain-history.d.ts.map +1 -0
- package/dist/types/components/brain-list.d.ts +2 -0
- package/dist/types/components/brain-list.d.ts.map +1 -0
- package/dist/types/components/brain-rerun.d.ts +9 -0
- package/dist/types/components/brain-rerun.d.ts.map +1 -0
- package/dist/types/components/brain-show.d.ts +6 -0
- package/dist/types/components/brain-show.d.ts.map +1 -0
- package/dist/types/components/error.d.ts +10 -0
- package/dist/types/components/error.d.ts.map +1 -0
- package/dist/types/components/project-add.d.ts +9 -0
- package/dist/types/components/project-add.d.ts.map +1 -0
- package/dist/types/components/project-create.d.ts +6 -0
- package/dist/types/components/project-create.d.ts.map +1 -0
- package/dist/types/components/project-list.d.ts +7 -0
- package/dist/types/components/project-list.d.ts.map +1 -0
- package/dist/types/components/project-remove.d.ts +8 -0
- package/dist/types/components/project-remove.d.ts.map +1 -0
- package/dist/types/components/project-select.d.ts +8 -0
- package/dist/types/components/project-select.d.ts.map +1 -0
- package/dist/types/components/project-show.d.ts +7 -0
- package/dist/types/components/project-show.d.ts.map +1 -0
- package/dist/types/components/resource-clear.d.ts +2 -0
- package/dist/types/components/resource-clear.d.ts.map +1 -0
- package/dist/types/components/resource-delete.d.ts +9 -0
- package/dist/types/components/resource-delete.d.ts.map +1 -0
- package/dist/types/components/resource-list.d.ts +2 -0
- package/dist/types/components/resource-list.d.ts.map +1 -0
- package/dist/types/components/resource-sync.d.ts +8 -0
- package/dist/types/components/resource-sync.d.ts.map +1 -0
- package/dist/types/components/resource-types.d.ts +7 -0
- package/dist/types/components/resource-types.d.ts.map +1 -0
- package/dist/types/components/resource-upload.d.ts +8 -0
- package/dist/types/components/resource-upload.d.ts.map +1 -0
- package/dist/types/components/schedule-create.d.ts +7 -0
- package/dist/types/components/schedule-create.d.ts.map +1 -0
- package/dist/types/components/schedule-delete.d.ts +7 -0
- package/dist/types/components/schedule-delete.d.ts.map +1 -0
- package/dist/types/components/schedule-list.d.ts +6 -0
- package/dist/types/components/schedule-list.d.ts.map +1 -0
- package/dist/types/components/schedule-runs.d.ts +8 -0
- package/dist/types/components/schedule-runs.d.ts.map +1 -0
- package/dist/types/components/secret-bulk.d.ts +8 -0
- package/dist/types/components/secret-bulk.d.ts.map +1 -0
- package/dist/types/components/secret-create.d.ts +9 -0
- package/dist/types/components/secret-create.d.ts.map +1 -0
- package/dist/types/components/secret-delete.d.ts +8 -0
- package/dist/types/components/secret-delete.d.ts.map +1 -0
- package/dist/types/components/secret-list.d.ts +7 -0
- package/dist/types/components/secret-list.d.ts.map +1 -0
- package/dist/types/components/secret-sync.d.ts +9 -0
- package/dist/types/components/secret-sync.d.ts.map +1 -0
- package/dist/types/components/watch.d.ts +7 -0
- package/dist/types/components/watch.d.ts.map +1 -0
- package/dist/types/hooks/useApi.d.ts +29 -0
- package/dist/types/hooks/useApi.d.ts.map +1 -0
- package/dist/types/positronic.d.ts +3 -0
- package/dist/types/positronic.d.ts.map +1 -0
- package/dist/types/test/mock-api-client.d.ts +25 -0
- package/dist/types/test/mock-api-client.d.ts.map +1 -0
- package/dist/types/test/test-dev-server.d.ts +129 -0
- package/dist/types/test/test-dev-server.d.ts.map +1 -0
- package/package.json +37 -0
- package/src/cli.ts +981 -0
- package/src/commands/backend.ts +63 -0
- package/src/commands/brain.test.ts +1004 -0
- package/src/commands/brain.ts +215 -0
- package/src/commands/helpers.test.ts +487 -0
- package/src/commands/helpers.ts +870 -0
- package/src/commands/project-config-manager.ts +152 -0
- package/src/commands/project.test.ts +502 -0
- package/src/commands/project.ts +109 -0
- package/src/commands/resources.test.ts +1052 -0
- package/src/commands/resources.ts +97 -0
- package/src/commands/schedule.test.ts +481 -0
- package/src/commands/schedule.ts +65 -0
- package/src/commands/secret.test.ts +210 -0
- package/src/commands/secret.ts +50 -0
- package/src/commands/server.test.ts +493 -0
- package/src/commands/server.ts +353 -0
- package/src/commands/test-utils.ts +324 -0
- package/src/components/brain-history.tsx +198 -0
- package/src/components/brain-list.tsx +105 -0
- package/src/components/brain-rerun.tsx +111 -0
- package/src/components/brain-show.tsx +92 -0
- package/src/components/error.tsx +24 -0
- package/src/components/project-add.tsx +59 -0
- package/src/components/project-create.tsx +83 -0
- package/src/components/project-list.tsx +83 -0
- package/src/components/project-remove.tsx +55 -0
- package/src/components/project-select.tsx +200 -0
- package/src/components/project-show.tsx +58 -0
- package/src/components/resource-clear.tsx +127 -0
- package/src/components/resource-delete.tsx +160 -0
- package/src/components/resource-list.tsx +177 -0
- package/src/components/resource-sync.tsx +170 -0
- package/src/components/resource-types.tsx +55 -0
- package/src/components/resource-upload.tsx +182 -0
- package/src/components/schedule-create.tsx +90 -0
- package/src/components/schedule-delete.tsx +116 -0
- package/src/components/schedule-list.tsx +186 -0
- package/src/components/schedule-runs.tsx +151 -0
- package/src/components/secret-bulk.tsx +79 -0
- package/src/components/secret-create.tsx +49 -0
- package/src/components/secret-delete.tsx +41 -0
- package/src/components/secret-list.tsx +41 -0
- package/src/components/watch.tsx +155 -0
- package/src/hooks/useApi.ts +183 -0
- package/src/positronic.ts +40 -0
- package/src/test/data/resources/config.json +1 -0
- package/src/test/data/resources/data/config.json +1 -0
- package/src/test/data/resources/data/logo.png +2 -0
- package/src/test/data/resources/docs/api.md +3 -0
- package/src/test/data/resources/docs/readme.md +3 -0
- package/src/test/data/resources/example.md +3 -0
- package/src/test/data/resources/file with spaces.txt +1 -0
- package/src/test/data/resources/readme.md +3 -0
- package/src/test/data/resources/test.txt +1 -0
- package/src/test/mock-api-client.ts +145 -0
- package/src/test/test-dev-server.ts +1003 -0
- package/tsconfig.json +11 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
5
|
+
}
|
|
6
|
+
function _array_with_holes(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return arr;
|
|
8
|
+
}
|
|
9
|
+
function _iterable_to_array_limit(arr, i) {
|
|
10
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
11
|
+
if (_i == null) return;
|
|
12
|
+
var _arr = [];
|
|
13
|
+
var _n = true;
|
|
14
|
+
var _d = false;
|
|
15
|
+
var _s, _e;
|
|
16
|
+
try {
|
|
17
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
18
|
+
_arr.push(_s.value);
|
|
19
|
+
if (i && _arr.length === i) break;
|
|
20
|
+
}
|
|
21
|
+
} catch (err) {
|
|
22
|
+
_d = true;
|
|
23
|
+
_e = err;
|
|
24
|
+
} finally{
|
|
25
|
+
try {
|
|
26
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
27
|
+
} finally{
|
|
28
|
+
if (_d) throw _e;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return _arr;
|
|
32
|
+
}
|
|
33
|
+
function _non_iterable_rest() {
|
|
34
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
35
|
+
}
|
|
36
|
+
function _sliced_to_array(arr, i) {
|
|
37
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
38
|
+
}
|
|
39
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
40
|
+
if (!o) return;
|
|
41
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
42
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
43
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
44
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
45
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
46
|
+
}
|
|
47
|
+
import React from 'react';
|
|
48
|
+
import { Box, Text } from 'ink';
|
|
49
|
+
import { useApiGet } from '../hooks/useApi.js';
|
|
50
|
+
import { ErrorComponent } from './error.js';
|
|
51
|
+
export var ResourceList = function() {
|
|
52
|
+
var _useApiGet = useApiGet('/resources'), data = _useApiGet.data, loading = _useApiGet.loading, error = _useApiGet.error;
|
|
53
|
+
if (error) {
|
|
54
|
+
return /*#__PURE__*/ React.createElement(ErrorComponent, {
|
|
55
|
+
error: error
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
if (loading) {
|
|
59
|
+
return /*#__PURE__*/ React.createElement(Text, null, "Loading resources...");
|
|
60
|
+
}
|
|
61
|
+
if (!data || data.resources.length === 0) {
|
|
62
|
+
return /*#__PURE__*/ React.createElement(Text, null, "No resources found in the project.");
|
|
63
|
+
}
|
|
64
|
+
var resources = data.resources, truncated = data.truncated;
|
|
65
|
+
// Build tree structure
|
|
66
|
+
var root = {
|
|
67
|
+
name: 'resources',
|
|
68
|
+
type: 'directory',
|
|
69
|
+
children: new Map()
|
|
70
|
+
};
|
|
71
|
+
// Build the tree from flat resources
|
|
72
|
+
resources.forEach(function(resource) {
|
|
73
|
+
var parts = resource.key.split('/');
|
|
74
|
+
var current = root;
|
|
75
|
+
for(var i = 0; i < parts.length; i++){
|
|
76
|
+
var part = parts[i];
|
|
77
|
+
var isLast = i === parts.length - 1;
|
|
78
|
+
if (!current.children.has(part)) {
|
|
79
|
+
current.children.set(part, {
|
|
80
|
+
name: part,
|
|
81
|
+
type: isLast ? 'file' : 'directory',
|
|
82
|
+
resource: isLast ? resource : undefined,
|
|
83
|
+
children: new Map()
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
current = current.children.get(part);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
return /*#__PURE__*/ React.createElement(Box, {
|
|
90
|
+
flexDirection: "column",
|
|
91
|
+
paddingTop: 1,
|
|
92
|
+
paddingBottom: 1
|
|
93
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
94
|
+
bold: true
|
|
95
|
+
}, "Found ", resources.length, " resource", resources.length === 1 ? '' : 's', ":"), /*#__PURE__*/ React.createElement(Box, {
|
|
96
|
+
marginTop: 1
|
|
97
|
+
}, /*#__PURE__*/ React.createElement(TreeView, {
|
|
98
|
+
node: root
|
|
99
|
+
})), truncated && /*#__PURE__*/ React.createElement(Box, {
|
|
100
|
+
marginTop: 1
|
|
101
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
102
|
+
color: "yellow"
|
|
103
|
+
}, "⚠️ Results truncated. More resources exist than shown.")), resources.some(function(r) {
|
|
104
|
+
return !r.local;
|
|
105
|
+
}) && /*#__PURE__*/ React.createElement(Box, {
|
|
106
|
+
marginTop: 1,
|
|
107
|
+
flexDirection: "column"
|
|
108
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
109
|
+
color: "gray"
|
|
110
|
+
}, "─────"), /*#__PURE__*/ React.createElement(Text, {
|
|
111
|
+
color: "blueBright"
|
|
112
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
113
|
+
color: "blueBright"
|
|
114
|
+
}, "↗"), " = uploaded resource (not in local filesystem)")));
|
|
115
|
+
};
|
|
116
|
+
var TreeView = function(param) {
|
|
117
|
+
var node = param.node, _param_prefix = param.prefix, prefix = _param_prefix === void 0 ? '' : _param_prefix, _param_isLast = param.isLast, isLast = _param_isLast === void 0 ? true : _param_isLast, _param_depth = param.depth, depth = _param_depth === void 0 ? 0 : _param_depth;
|
|
118
|
+
var children = Array.from(node.children.entries()).sort(function(param, param1) {
|
|
119
|
+
var _param = _sliced_to_array(param, 1), a = _param[0], _param1 = _sliced_to_array(param1, 1), b = _param1[0];
|
|
120
|
+
// Sort directories first, then alphabetically
|
|
121
|
+
var aIsDir = node.children.get(a).type === 'directory';
|
|
122
|
+
var bIsDir = node.children.get(b).type === 'directory';
|
|
123
|
+
if (aIsDir && !bIsDir) return -1;
|
|
124
|
+
if (!aIsDir && bIsDir) return 1;
|
|
125
|
+
return a.localeCompare(b);
|
|
126
|
+
});
|
|
127
|
+
// Don't render the root node itself, just its children
|
|
128
|
+
if (node.name === 'resources' && node.type === 'directory') {
|
|
129
|
+
return /*#__PURE__*/ React.createElement(Box, {
|
|
130
|
+
flexDirection: "column"
|
|
131
|
+
}, children.map(function(param, index) {
|
|
132
|
+
var _param = _sliced_to_array(param, 2), name = _param[0], child = _param[1];
|
|
133
|
+
return /*#__PURE__*/ React.createElement(React.Fragment, {
|
|
134
|
+
key: name
|
|
135
|
+
}, index > 0 && /*#__PURE__*/ React.createElement(Box, null, /*#__PURE__*/ React.createElement(Text, null, " ")), /*#__PURE__*/ React.createElement(TreeView, {
|
|
136
|
+
node: child,
|
|
137
|
+
prefix: "",
|
|
138
|
+
isLast: index === children.length - 1,
|
|
139
|
+
depth: 0
|
|
140
|
+
}));
|
|
141
|
+
}));
|
|
142
|
+
}
|
|
143
|
+
var connector = isLast ? '└── ' : '├── ';
|
|
144
|
+
var extension = isLast ? ' ' : '│ ';
|
|
145
|
+
var isTopLevel = depth === 0;
|
|
146
|
+
// Determine if this is a remote resource
|
|
147
|
+
var isRemote = node.resource && !node.resource.local;
|
|
148
|
+
return /*#__PURE__*/ React.createElement(Box, {
|
|
149
|
+
flexDirection: "column"
|
|
150
|
+
}, /*#__PURE__*/ React.createElement(Box, null, !isTopLevel && /*#__PURE__*/ React.createElement(Text, {
|
|
151
|
+
dimColor: true
|
|
152
|
+
}, prefix, connector), /*#__PURE__*/ React.createElement(Text, {
|
|
153
|
+
color: isRemote ? 'blueBright' : undefined
|
|
154
|
+
}, node.name, node.resource && /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(Text, {
|
|
155
|
+
color: isRemote ? 'blueBright' : 'gray'
|
|
156
|
+
}, " (", formatSize(node.resource.size), ")"), isRemote && /*#__PURE__*/ React.createElement(Text, {
|
|
157
|
+
color: "blueBright"
|
|
158
|
+
}, " ↗")))), children.map(function(param, index) {
|
|
159
|
+
var _param = _sliced_to_array(param, 2), name = _param[0], child = _param[1];
|
|
160
|
+
return /*#__PURE__*/ React.createElement(TreeView, {
|
|
161
|
+
key: name,
|
|
162
|
+
node: child,
|
|
163
|
+
prefix: prefix + (isTopLevel ? '' : extension),
|
|
164
|
+
isLast: index === children.length - 1,
|
|
165
|
+
depth: depth + 1
|
|
166
|
+
});
|
|
167
|
+
}));
|
|
168
|
+
};
|
|
169
|
+
function formatSize(bytes) {
|
|
170
|
+
if (bytes < 1024) return "".concat(bytes, " B");
|
|
171
|
+
if (bytes < 1024 * 1024) return "".concat((bytes / 1024).toFixed(1), " KB");
|
|
172
|
+
if (bytes < 1024 * 1024 * 1024) return "".concat((bytes / (1024 * 1024)).toFixed(1), " MB");
|
|
173
|
+
return "".concat((bytes / (1024 * 1024 * 1024)).toFixed(1), " GB");
|
|
174
|
+
}
|
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
5
|
+
}
|
|
6
|
+
function _array_with_holes(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return arr;
|
|
8
|
+
}
|
|
9
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
10
|
+
try {
|
|
11
|
+
var info = gen[key](arg);
|
|
12
|
+
var value = info.value;
|
|
13
|
+
} catch (error) {
|
|
14
|
+
reject(error);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (info.done) {
|
|
18
|
+
resolve(value);
|
|
19
|
+
} else {
|
|
20
|
+
Promise.resolve(value).then(_next, _throw);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function _async_to_generator(fn) {
|
|
24
|
+
return function() {
|
|
25
|
+
var self = this, args = arguments;
|
|
26
|
+
return new Promise(function(resolve, reject) {
|
|
27
|
+
var gen = fn.apply(self, args);
|
|
28
|
+
function _next(value) {
|
|
29
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
30
|
+
}
|
|
31
|
+
function _throw(err) {
|
|
32
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
33
|
+
}
|
|
34
|
+
_next(undefined);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function _define_property(obj, key, value) {
|
|
39
|
+
if (key in obj) {
|
|
40
|
+
Object.defineProperty(obj, key, {
|
|
41
|
+
value: value,
|
|
42
|
+
enumerable: true,
|
|
43
|
+
configurable: true,
|
|
44
|
+
writable: true
|
|
45
|
+
});
|
|
46
|
+
} else {
|
|
47
|
+
obj[key] = value;
|
|
48
|
+
}
|
|
49
|
+
return obj;
|
|
50
|
+
}
|
|
51
|
+
function _iterable_to_array_limit(arr, i) {
|
|
52
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
53
|
+
if (_i == null) return;
|
|
54
|
+
var _arr = [];
|
|
55
|
+
var _n = true;
|
|
56
|
+
var _d = false;
|
|
57
|
+
var _s, _e;
|
|
58
|
+
try {
|
|
59
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
60
|
+
_arr.push(_s.value);
|
|
61
|
+
if (i && _arr.length === i) break;
|
|
62
|
+
}
|
|
63
|
+
} catch (err) {
|
|
64
|
+
_d = true;
|
|
65
|
+
_e = err;
|
|
66
|
+
} finally{
|
|
67
|
+
try {
|
|
68
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
69
|
+
} finally{
|
|
70
|
+
if (_d) throw _e;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return _arr;
|
|
74
|
+
}
|
|
75
|
+
function _non_iterable_rest() {
|
|
76
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
77
|
+
}
|
|
78
|
+
function _object_spread(target) {
|
|
79
|
+
for(var i = 1; i < arguments.length; i++){
|
|
80
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
81
|
+
var ownKeys = Object.keys(source);
|
|
82
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
83
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
84
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
ownKeys.forEach(function(key) {
|
|
88
|
+
_define_property(target, key, source[key]);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return target;
|
|
92
|
+
}
|
|
93
|
+
function ownKeys(object, enumerableOnly) {
|
|
94
|
+
var keys = Object.keys(object);
|
|
95
|
+
if (Object.getOwnPropertySymbols) {
|
|
96
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
97
|
+
if (enumerableOnly) {
|
|
98
|
+
symbols = symbols.filter(function(sym) {
|
|
99
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
keys.push.apply(keys, symbols);
|
|
103
|
+
}
|
|
104
|
+
return keys;
|
|
105
|
+
}
|
|
106
|
+
function _object_spread_props(target, source) {
|
|
107
|
+
source = source != null ? source : {};
|
|
108
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
109
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
110
|
+
} else {
|
|
111
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
112
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return target;
|
|
116
|
+
}
|
|
117
|
+
function _sliced_to_array(arr, i) {
|
|
118
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
119
|
+
}
|
|
120
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
121
|
+
if (!o) return;
|
|
122
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
123
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
124
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
125
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
126
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
127
|
+
}
|
|
128
|
+
function _ts_generator(thisArg, body) {
|
|
129
|
+
var f, y, t, _ = {
|
|
130
|
+
label: 0,
|
|
131
|
+
sent: function() {
|
|
132
|
+
if (t[0] & 1) throw t[1];
|
|
133
|
+
return t[1];
|
|
134
|
+
},
|
|
135
|
+
trys: [],
|
|
136
|
+
ops: []
|
|
137
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
138
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
139
|
+
return this;
|
|
140
|
+
}), g;
|
|
141
|
+
function verb(n) {
|
|
142
|
+
return function(v) {
|
|
143
|
+
return step([
|
|
144
|
+
n,
|
|
145
|
+
v
|
|
146
|
+
]);
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
function step(op) {
|
|
150
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
151
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
152
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
153
|
+
if (y = 0, t) op = [
|
|
154
|
+
op[0] & 2,
|
|
155
|
+
t.value
|
|
156
|
+
];
|
|
157
|
+
switch(op[0]){
|
|
158
|
+
case 0:
|
|
159
|
+
case 1:
|
|
160
|
+
t = op;
|
|
161
|
+
break;
|
|
162
|
+
case 4:
|
|
163
|
+
_.label++;
|
|
164
|
+
return {
|
|
165
|
+
value: op[1],
|
|
166
|
+
done: false
|
|
167
|
+
};
|
|
168
|
+
case 5:
|
|
169
|
+
_.label++;
|
|
170
|
+
y = op[1];
|
|
171
|
+
op = [
|
|
172
|
+
0
|
|
173
|
+
];
|
|
174
|
+
continue;
|
|
175
|
+
case 7:
|
|
176
|
+
op = _.ops.pop();
|
|
177
|
+
_.trys.pop();
|
|
178
|
+
continue;
|
|
179
|
+
default:
|
|
180
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
181
|
+
_ = 0;
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
185
|
+
_.label = op[1];
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
189
|
+
_.label = t[1];
|
|
190
|
+
t = op;
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
if (t && _.label < t[2]) {
|
|
194
|
+
_.label = t[2];
|
|
195
|
+
_.ops.push(op);
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
if (t[2]) _.ops.pop();
|
|
199
|
+
_.trys.pop();
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
op = body.call(thisArg, _);
|
|
203
|
+
} catch (e) {
|
|
204
|
+
op = [
|
|
205
|
+
6,
|
|
206
|
+
e
|
|
207
|
+
];
|
|
208
|
+
y = 0;
|
|
209
|
+
} finally{
|
|
210
|
+
f = t = 0;
|
|
211
|
+
}
|
|
212
|
+
if (op[0] & 5) throw op[1];
|
|
213
|
+
return {
|
|
214
|
+
value: op[0] ? op[1] : void 0,
|
|
215
|
+
done: true
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
import React from 'react';
|
|
220
|
+
import { useState, useEffect } from 'react';
|
|
221
|
+
import { Box, Text } from 'ink';
|
|
222
|
+
import { ErrorComponent } from './error.js';
|
|
223
|
+
import { syncResources, generateTypes } from '../commands/helpers.js';
|
|
224
|
+
export var ResourceSync = function(param) {
|
|
225
|
+
var localResources = param.localResources, resourcesDir = param.resourcesDir;
|
|
226
|
+
var _useState = _sliced_to_array(useState({
|
|
227
|
+
uploadCount: 0,
|
|
228
|
+
skipCount: 0,
|
|
229
|
+
errorCount: 0,
|
|
230
|
+
totalCount: localResources.length,
|
|
231
|
+
deleteCount: 0,
|
|
232
|
+
errors: [],
|
|
233
|
+
currentAction: 'connecting'
|
|
234
|
+
}), 2), stats = _useState[0], setStats = _useState[1];
|
|
235
|
+
var _useState1 = _sliced_to_array(useState(null), 2), error = _useState1[0], setError = _useState1[1];
|
|
236
|
+
useEffect(function() {
|
|
237
|
+
if (!resourcesDir) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
var performSync = function() {
|
|
241
|
+
return _async_to_generator(function() {
|
|
242
|
+
var projectRootPath, onProgress, result, typeError, err;
|
|
243
|
+
return _ts_generator(this, function(_state) {
|
|
244
|
+
switch(_state.label){
|
|
245
|
+
case 0:
|
|
246
|
+
_state.trys.push([
|
|
247
|
+
0,
|
|
248
|
+
6,
|
|
249
|
+
,
|
|
250
|
+
7
|
|
251
|
+
]);
|
|
252
|
+
// Get the project root path (parent of resources dir)
|
|
253
|
+
projectRootPath = resourcesDir.replace(/[/\\]resources$/, '');
|
|
254
|
+
onProgress = function(progress) {
|
|
255
|
+
setStats({
|
|
256
|
+
uploadCount: progress.stats.uploadCount || 0,
|
|
257
|
+
skipCount: progress.stats.skipCount || 0,
|
|
258
|
+
errorCount: progress.stats.errorCount || 0,
|
|
259
|
+
totalCount: progress.stats.totalCount || localResources.length,
|
|
260
|
+
deleteCount: progress.stats.deleteCount || 0,
|
|
261
|
+
errors: progress.stats.errors || [],
|
|
262
|
+
currentFile: progress.currentFile,
|
|
263
|
+
currentAction: progress.action
|
|
264
|
+
});
|
|
265
|
+
};
|
|
266
|
+
return [
|
|
267
|
+
4,
|
|
268
|
+
syncResources(projectRootPath, undefined, onProgress)
|
|
269
|
+
];
|
|
270
|
+
case 1:
|
|
271
|
+
result = _state.sent();
|
|
272
|
+
// Update final stats with done status
|
|
273
|
+
setStats(_object_spread_props(_object_spread({}, result), {
|
|
274
|
+
currentAction: 'done'
|
|
275
|
+
}));
|
|
276
|
+
_state.label = 2;
|
|
277
|
+
case 2:
|
|
278
|
+
_state.trys.push([
|
|
279
|
+
2,
|
|
280
|
+
4,
|
|
281
|
+
,
|
|
282
|
+
5
|
|
283
|
+
]);
|
|
284
|
+
return [
|
|
285
|
+
4,
|
|
286
|
+
generateTypes(projectRootPath)
|
|
287
|
+
];
|
|
288
|
+
case 3:
|
|
289
|
+
_state.sent();
|
|
290
|
+
return [
|
|
291
|
+
3,
|
|
292
|
+
5
|
|
293
|
+
];
|
|
294
|
+
case 4:
|
|
295
|
+
typeError = _state.sent();
|
|
296
|
+
// Don't fail the sync if type generation fails
|
|
297
|
+
console.error('Failed to generate types:', typeError);
|
|
298
|
+
return [
|
|
299
|
+
3,
|
|
300
|
+
5
|
|
301
|
+
];
|
|
302
|
+
case 5:
|
|
303
|
+
return [
|
|
304
|
+
3,
|
|
305
|
+
7
|
|
306
|
+
];
|
|
307
|
+
case 6:
|
|
308
|
+
err = _state.sent();
|
|
309
|
+
setError({
|
|
310
|
+
title: 'Sync Failed',
|
|
311
|
+
message: err.message || 'An unknown error occurred',
|
|
312
|
+
details: err.code === 'ECONNREFUSED' ? "Please ensure the server is running ('positronic server' or 'px s')" : undefined
|
|
313
|
+
});
|
|
314
|
+
setStats(function(prev) {
|
|
315
|
+
return _object_spread_props(_object_spread({}, prev), {
|
|
316
|
+
currentAction: 'error'
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
return [
|
|
320
|
+
3,
|
|
321
|
+
7
|
|
322
|
+
];
|
|
323
|
+
case 7:
|
|
324
|
+
return [
|
|
325
|
+
2
|
|
326
|
+
];
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
})();
|
|
330
|
+
};
|
|
331
|
+
performSync();
|
|
332
|
+
}, [
|
|
333
|
+
localResources,
|
|
334
|
+
resourcesDir
|
|
335
|
+
]);
|
|
336
|
+
var uploadCount = stats.uploadCount, skipCount = stats.skipCount, errorCount = stats.errorCount, totalCount = stats.totalCount, deleteCount = stats.deleteCount, currentFile = stats.currentFile, currentAction = stats.currentAction, errors = stats.errors;
|
|
337
|
+
var processedCount = uploadCount + skipCount + errorCount;
|
|
338
|
+
if (error) {
|
|
339
|
+
return /*#__PURE__*/ React.createElement(ErrorComponent, {
|
|
340
|
+
error: error
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
if (currentAction === 'connecting') {
|
|
344
|
+
return /*#__PURE__*/ React.createElement(Box, null, /*#__PURE__*/ React.createElement(Text, null, "\uD83D\uDD0C Connecting to server..."));
|
|
345
|
+
}
|
|
346
|
+
return /*#__PURE__*/ React.createElement(Box, {
|
|
347
|
+
flexDirection: "column"
|
|
348
|
+
}, currentAction !== 'done' && currentFile && /*#__PURE__*/ React.createElement(Box, null, /*#__PURE__*/ React.createElement(Text, null, currentAction === 'uploading' ? '⬆️ Uploading' : currentAction === 'deleting' ? '🗑️ Deleting' : '🔍 Checking', " ", currentFile, "...")), totalCount > 0 && currentAction !== 'done' && /*#__PURE__*/ React.createElement(Box, {
|
|
349
|
+
marginTop: 1
|
|
350
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
351
|
+
dimColor: true
|
|
352
|
+
}, "Progress: ", processedCount, "/", totalCount, " files processed")), totalCount === 0 && currentAction === 'done' && /*#__PURE__*/ React.createElement(Box, {
|
|
353
|
+
flexDirection: "column"
|
|
354
|
+
}, /*#__PURE__*/ React.createElement(Text, null, "\uD83D\uDCC1 No files found in the resources directory."), /*#__PURE__*/ React.createElement(Text, {
|
|
355
|
+
dimColor: true
|
|
356
|
+
}, "Resources directory has been created and is ready for use.")), errors.length > 0 && /*#__PURE__*/ React.createElement(Box, {
|
|
357
|
+
flexDirection: "column",
|
|
358
|
+
marginTop: 1
|
|
359
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
360
|
+
color: "red",
|
|
361
|
+
bold: true
|
|
362
|
+
}, "Errors:"), errors.map(function(error, i) {
|
|
363
|
+
return /*#__PURE__*/ React.createElement(Box, {
|
|
364
|
+
key: i,
|
|
365
|
+
paddingLeft: 2
|
|
366
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
367
|
+
color: "red"
|
|
368
|
+
}, "❌ ", error.file, ": ", error.message));
|
|
369
|
+
})), currentAction === 'done' && totalCount > 0 && /*#__PURE__*/ React.createElement(Box, {
|
|
370
|
+
flexDirection: "column",
|
|
371
|
+
marginTop: 1
|
|
372
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
373
|
+
bold: true
|
|
374
|
+
}, "\uD83D\uDCCA Sync Summary:"), /*#__PURE__*/ React.createElement(Box, {
|
|
375
|
+
paddingLeft: 2,
|
|
376
|
+
flexDirection: "column"
|
|
377
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
378
|
+
color: "green"
|
|
379
|
+
}, " • Uploaded: ", uploadCount), /*#__PURE__*/ React.createElement(Text, {
|
|
380
|
+
color: "blue"
|
|
381
|
+
}, " • Skipped (up to date): ", skipCount), deleteCount > 0 && /*#__PURE__*/ React.createElement(Text, {
|
|
382
|
+
color: "yellow"
|
|
383
|
+
}, " • Deleted: ", deleteCount), errorCount > 0 && /*#__PURE__*/ React.createElement(Text, {
|
|
384
|
+
color: "red"
|
|
385
|
+
}, " • Errors: ", errorCount))));
|
|
386
|
+
};
|