@factorialco/fcode-cli 1.1.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 (234) hide show
  1. package/README.md +1021 -0
  2. package/bin/dev +17 -0
  3. package/bin/dev.cmd +3 -0
  4. package/bin/run +7 -0
  5. package/bin/run.cmd +3 -0
  6. package/dist/commands/add.d.ts +6 -0
  7. package/dist/commands/add.js +22 -0
  8. package/dist/commands/clone.d.ts +26 -0
  9. package/dist/commands/clone.js +177 -0
  10. package/dist/commands/dependencies/add.d.ts +9 -0
  11. package/dist/commands/dependencies/add.js +13 -0
  12. package/dist/commands/dependencies/install.d.ts +14 -0
  13. package/dist/commands/dependencies/install.js +44 -0
  14. package/dist/commands/dependencies/pull.d.ts +12 -0
  15. package/dist/commands/dependencies/pull.js +14 -0
  16. package/dist/commands/dependencies/push.d.ts +12 -0
  17. package/dist/commands/dependencies/push.js +14 -0
  18. package/dist/commands/dependencies/reset.d.ts +9 -0
  19. package/dist/commands/dependencies/reset.js +13 -0
  20. package/dist/commands/dependencies/status.d.ts +9 -0
  21. package/dist/commands/dependencies/status.js +13 -0
  22. package/dist/commands/http.d.ts +22 -0
  23. package/dist/commands/http.js +272 -0
  24. package/dist/commands/login.d.ts +18 -0
  25. package/dist/commands/login.js +62 -0
  26. package/dist/commands/logout.d.ts +10 -0
  27. package/dist/commands/logout.js +34 -0
  28. package/dist/commands/modules/add.d.ts +9 -0
  29. package/dist/commands/modules/add.js +13 -0
  30. package/dist/commands/modules/pull.d.ts +13 -0
  31. package/dist/commands/modules/pull.js +43 -0
  32. package/dist/commands/modules/push.d.ts +13 -0
  33. package/dist/commands/modules/push.js +35 -0
  34. package/dist/commands/modules/remove.d.ts +9 -0
  35. package/dist/commands/modules/remove.js +19 -0
  36. package/dist/commands/modules/reset.d.ts +9 -0
  37. package/dist/commands/modules/reset.js +13 -0
  38. package/dist/commands/modules/status.d.ts +11 -0
  39. package/dist/commands/modules/status.js +40 -0
  40. package/dist/commands/pre-debug.d.ts +20 -0
  41. package/dist/commands/pre-debug.js +120 -0
  42. package/dist/commands/process-metadata.d.ts +18 -0
  43. package/dist/commands/process-metadata.js +63 -0
  44. package/dist/commands/processes/add.d.ts +9 -0
  45. package/dist/commands/processes/add.js +13 -0
  46. package/dist/commands/processes/install-dependencies.d.ts +14 -0
  47. package/dist/commands/processes/install-dependencies.js +30 -0
  48. package/dist/commands/processes/pull.d.ts +13 -0
  49. package/dist/commands/processes/pull.js +47 -0
  50. package/dist/commands/processes/push.d.ts +13 -0
  51. package/dist/commands/processes/push.js +39 -0
  52. package/dist/commands/processes/remove.d.ts +9 -0
  53. package/dist/commands/processes/remove.js +19 -0
  54. package/dist/commands/processes/reset.d.ts +9 -0
  55. package/dist/commands/processes/reset.js +13 -0
  56. package/dist/commands/processes/status.d.ts +11 -0
  57. package/dist/commands/processes/status.js +58 -0
  58. package/dist/commands/pull.d.ts +9 -0
  59. package/dist/commands/pull.js +32 -0
  60. package/dist/commands/push.d.ts +9 -0
  61. package/dist/commands/push.js +29 -0
  62. package/dist/commands/remote/add.d.ts +10 -0
  63. package/dist/commands/remote/add.js +32 -0
  64. package/dist/commands/remote/list.d.ts +7 -0
  65. package/dist/commands/remote/list.js +33 -0
  66. package/dist/commands/remote/set.d.ts +10 -0
  67. package/dist/commands/remote/set.js +28 -0
  68. package/dist/commands/reset.d.ts +6 -0
  69. package/dist/commands/reset.js +19 -0
  70. package/dist/commands/run.d.ts +16 -0
  71. package/dist/commands/run.js +56 -0
  72. package/dist/commands/runtime-env.d.ts +12 -0
  73. package/dist/commands/runtime-env.js +42 -0
  74. package/dist/commands/settings/get.d.ts +12 -0
  75. package/dist/commands/settings/get.js +67 -0
  76. package/dist/commands/settings/remove.d.ts +9 -0
  77. package/dist/commands/settings/remove.js +35 -0
  78. package/dist/commands/settings/set.d.ts +10 -0
  79. package/dist/commands/settings/set.js +39 -0
  80. package/dist/commands/setup-debug.d.ts +12 -0
  81. package/dist/commands/setup-debug.js +118 -0
  82. package/dist/commands/status.d.ts +6 -0
  83. package/dist/commands/status.js +22 -0
  84. package/dist/commands/team/pull.d.ts +8 -0
  85. package/dist/commands/team/pull.js +23 -0
  86. package/dist/commands/team/push.d.ts +11 -0
  87. package/dist/commands/team/push.js +41 -0
  88. package/dist/commands/team/status.d.ts +8 -0
  89. package/dist/commands/team/status.js +40 -0
  90. package/dist/commands/test/scaffold.d.ts +9 -0
  91. package/dist/commands/test/scaffold.js +61 -0
  92. package/dist/commands/test.d.ts +13 -0
  93. package/dist/commands/test.js +72 -0
  94. package/dist/commands/variables/add.d.ts +12 -0
  95. package/dist/commands/variables/add.js +21 -0
  96. package/dist/commands/variables/pull.d.ts +12 -0
  97. package/dist/commands/variables/pull.js +14 -0
  98. package/dist/commands/variables/push.d.ts +12 -0
  99. package/dist/commands/variables/push.js +14 -0
  100. package/dist/commands/variables/remove.d.ts +9 -0
  101. package/dist/commands/variables/remove.js +19 -0
  102. package/dist/commands/variables/reset.d.ts +9 -0
  103. package/dist/commands/variables/reset.js +13 -0
  104. package/dist/commands/variables/status.d.ts +12 -0
  105. package/dist/commands/variables/status.js +58 -0
  106. package/dist/config/global.d.ts +15 -0
  107. package/dist/config/global.js +77 -0
  108. package/dist/config/index.d.ts +14 -0
  109. package/dist/config/index.js +44 -0
  110. package/dist/config/remote.d.ts +15 -0
  111. package/dist/config/remote.js +60 -0
  112. package/dist/config/settings.d.ts +16 -0
  113. package/dist/config/settings.js +54 -0
  114. package/dist/config/workspace.d.ts +28 -0
  115. package/dist/config/workspace.js +158 -0
  116. package/dist/core/commands/api-client-command.d.ts +6 -0
  117. package/dist/core/commands/api-client-command.js +30 -0
  118. package/dist/core/commands/base-command.d.ts +11 -0
  119. package/dist/core/commands/base-command.js +61 -0
  120. package/dist/core/commands/dependency-command.d.ts +5 -0
  121. package/dist/core/commands/dependency-command.js +16 -0
  122. package/dist/core/commands/modules-command.d.ts +7 -0
  123. package/dist/core/commands/modules-command.js +18 -0
  124. package/dist/core/commands/processes-command.d.ts +8 -0
  125. package/dist/core/commands/processes-command.js +27 -0
  126. package/dist/core/commands/resource-command.d.ts +24 -0
  127. package/dist/core/commands/resource-command.js +92 -0
  128. package/dist/core/commands/variables-command.d.ts +5 -0
  129. package/dist/core/commands/variables-command.js +16 -0
  130. package/dist/core/dependencies/env-dependencies-command.d.ts +19 -0
  131. package/dist/core/dependencies/env-dependencies-command.js +70 -0
  132. package/dist/core/dependencies/env-process-dependencies-command.d.ts +15 -0
  133. package/dist/core/dependencies/env-process-dependencies-command.js +78 -0
  134. package/dist/core/dependencies/javascript-env-dependencies.d.ts +8 -0
  135. package/dist/core/dependencies/javascript-env-dependencies.js +77 -0
  136. package/dist/core/dependencies/python-env-dependencies.d.ts +9 -0
  137. package/dist/core/dependencies/python-env-dependencies.js +91 -0
  138. package/dist/core/errors.d.ts +55 -0
  139. package/dist/core/errors.js +144 -0
  140. package/dist/core/executors/execution-task.d.ts +29 -0
  141. package/dist/core/executors/execution-task.js +139 -0
  142. package/dist/core/executors/javascript-execution-task.d.ts +13 -0
  143. package/dist/core/executors/javascript-execution-task.js +618 -0
  144. package/dist/core/executors/python/context.d.ts +2 -0
  145. package/dist/core/executors/python/context.js +3 -0
  146. package/dist/core/executors/python/datastore.d.ts +2 -0
  147. package/dist/core/executors/python/datastore.js +4 -0
  148. package/dist/core/executors/python-execution-task.d.ts +11 -0
  149. package/dist/core/executors/python-execution-task.js +173 -0
  150. package/dist/core/executors/source-code-sanitizer.d.ts +4 -0
  151. package/dist/core/executors/source-code-sanitizer.js +45 -0
  152. package/dist/core/resource-merger.d.ts +14 -0
  153. package/dist/core/resource-merger.js +155 -0
  154. package/dist/core/resource-pusher.d.ts +12 -0
  155. package/dist/core/resource-pusher.js +133 -0
  156. package/dist/core/resource-repository.d.ts +8 -0
  157. package/dist/core/resource-repository.js +2 -0
  158. package/dist/core/types.d.ts +290 -0
  159. package/dist/core/types.js +238 -0
  160. package/dist/core/utils/dependencies.d.ts +5 -0
  161. package/dist/core/utils/dependencies.js +82 -0
  162. package/dist/core/utils/variables.d.ts +4 -0
  163. package/dist/core/utils/variables.js +10 -0
  164. package/dist/hooks/init/auth.d.ts +3 -0
  165. package/dist/hooks/init/auth.js +28 -0
  166. package/dist/hooks/init/update.d.ts +3 -0
  167. package/dist/hooks/init/update.js +42 -0
  168. package/dist/index.d.ts +1 -0
  169. package/dist/index.js +4 -0
  170. package/dist/repositories/process.d.ts +36 -0
  171. package/dist/repositories/process.js +339 -0
  172. package/dist/repositories/programming-language-manifest.d.ts +17 -0
  173. package/dist/repositories/programming-language-manifest.js +95 -0
  174. package/dist/repositories/resource.d.ts +29 -0
  175. package/dist/repositories/resource.js +79 -0
  176. package/dist/repositories/script-library.d.ts +28 -0
  177. package/dist/repositories/script-library.js +164 -0
  178. package/dist/repositories/team.d.ts +23 -0
  179. package/dist/repositories/team.js +74 -0
  180. package/dist/repositories/variable.d.ts +26 -0
  181. package/dist/repositories/variable.js +174 -0
  182. package/dist/runtime/executor.js +87 -0
  183. package/dist/runtime/executor.py +81 -0
  184. package/dist/runtime/libs/node/fcode/index.js +1 -0
  185. package/dist/runtime/libs/python/fcode/__init__.py +75 -0
  186. package/dist/runtime/libs/python/fcode/context.py +98 -0
  187. package/dist/runtime/libs/python/fcode/datastore.py +35 -0
  188. package/dist/runtime/libs/python/fcode/schedule.py +45 -0
  189. package/dist/runtime/libs/python/fcode/storage.py +271 -0
  190. package/dist/runtime/libs/python/fcode/variables.py +102 -0
  191. package/dist/services/auth-service.d.ts +12 -0
  192. package/dist/services/auth-service.js +114 -0
  193. package/dist/services/credential-prompter.d.ts +6 -0
  194. package/dist/services/credential-prompter.js +60 -0
  195. package/dist/services/fcode-graphql-client.d.ts +45 -0
  196. package/dist/services/fcode-graphql-client.js +721 -0
  197. package/dist/services/http-server.d.ts +3 -0
  198. package/dist/services/http-server.js +17 -0
  199. package/dist/services/oauth-browser-service.d.ts +9 -0
  200. package/dist/services/oauth-browser-service.js +164 -0
  201. package/dist/services/process-parameters-sampler.d.ts +2 -0
  202. package/dist/services/process-parameters-sampler.js +41 -0
  203. package/dist/services/process-runner.d.ts +22 -0
  204. package/dist/services/process-runner.js +97 -0
  205. package/dist/services/resource-checker.d.ts +8 -0
  206. package/dist/services/resource-checker.js +82 -0
  207. package/dist/services/test-runner.d.ts +17 -0
  208. package/dist/services/test-runner.js +228 -0
  209. package/dist/utils/canonical-hash.d.ts +9 -0
  210. package/dist/utils/canonical-hash.js +30 -0
  211. package/dist/utils/cli/index.d.ts +14 -0
  212. package/dist/utils/cli/index.js +50 -0
  213. package/dist/utils/cli/screen.d.ts +2 -0
  214. package/dist/utils/cli/screen.js +25 -0
  215. package/dist/utils/cli/styled/table.d.ts +23 -0
  216. package/dist/utils/cli/styled/table.js +272 -0
  217. package/dist/utils/colorize-resource.d.ts +1 -0
  218. package/dist/utils/colorize-resource.js +7 -0
  219. package/dist/utils/env-utils.d.ts +2 -0
  220. package/dist/utils/env-utils.js +16 -0
  221. package/dist/utils/file-utils.d.ts +11 -0
  222. package/dist/utils/file-utils.js +33 -0
  223. package/dist/utils/filenamify.d.ts +4 -0
  224. package/dist/utils/filenamify.js +73 -0
  225. package/dist/utils/gitignore.d.ts +17 -0
  226. package/dist/utils/gitignore.js +60 -0
  227. package/dist/utils/promise.d.ts +4 -0
  228. package/dist/utils/promise.js +38 -0
  229. package/dist/utils/url-utils.d.ts +2 -0
  230. package/dist/utils/url-utils.js +10 -0
  231. package/dist/utils/variable-warnings.d.ts +8 -0
  232. package/dist/utils/variable-warnings.js +38 -0
  233. package/oclif.manifest.json +1783 -0
  234. package/package.json +129 -0
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const path = require("node:path");
4
+ const fs = require("fs-extra");
5
+ const node_crypto_1 = require("node:crypto");
6
+ const hash = function (remote) {
7
+ return (0, node_crypto_1.createHash)('md5').update(remote).digest('hex');
8
+ };
9
+ class RemoteConfig {
10
+ static save(hash, team, configPath = process.cwd()) {
11
+ const sortedTeam = this.sortDeeply(team);
12
+ fs.writeJsonSync(RemoteConfig.configPath(hash, configPath), sortedTeam, { spaces: 2 });
13
+ }
14
+ static get(hash, configPath = process.cwd()) {
15
+ const path = RemoteConfig.configPath(hash, configPath);
16
+ if (fs.pathExistsSync(path)) {
17
+ return fs.readJsonSync(path);
18
+ }
19
+ }
20
+ static sortDeeply(config) {
21
+ for (let [key, value] of Object.entries(config)) {
22
+ if (Array.isArray(value)) {
23
+ config[key] = value.map((item) => (typeof item === 'object' && item !== null ? this.sortDeeply(item) : item));
24
+ }
25
+ else if (typeof value === 'object' && value !== null) {
26
+ config[key] = this.sortDeeply(value);
27
+ }
28
+ }
29
+ return this.sort(config);
30
+ }
31
+ static sort(config) {
32
+ if (Array.isArray(config)) {
33
+ return config;
34
+ }
35
+ return Object.keys(config)
36
+ .sort()
37
+ .reduce((obj, key) => {
38
+ obj[key] = config[key];
39
+ return obj;
40
+ }, {});
41
+ }
42
+ constructor(remote, configPath = process.cwd()) {
43
+ this.remote = remote;
44
+ this.hash = hash(remote);
45
+ this.configPath = RemoteConfig.configPath(this.hash, configPath);
46
+ this.createDir(this.configPath);
47
+ return this;
48
+ }
49
+ init() {
50
+ fs.writeJsonSync(this.configPath, { slug: this.remote, modules: {}, processes: {}, variables: {}, dependencies: {}, team: {} }, { spaces: 2 });
51
+ }
52
+ createDir(configPath) {
53
+ if (!fs.pathExistsSync(configPath)) {
54
+ fs.mkdirpSync(path.dirname(configPath));
55
+ }
56
+ }
57
+ }
58
+ RemoteConfig.FCODE_REMOTE_CONFIG_FILENAME = 'remote.<hash>.json';
59
+ RemoteConfig.configPath = (hash, configPath = process.cwd()) => path.join(configPath, RemoteConfig.FCODE_REMOTE_CONFIG_FILENAME.replace('<hash>', hash));
60
+ exports.default = RemoteConfig;
@@ -0,0 +1,16 @@
1
+ export interface SettingDefinition {
2
+ key: string;
3
+ default: string;
4
+ description?: string;
5
+ }
6
+ export declare enum SettingKeys {
7
+ DISABLE_UPDATE_NOTIFIER = "disableUpdateNotifier",
8
+ IGNORE_PROCESS_VERSIONS = "ignoreProcessVersions",
9
+ IGNORE_WORKSPACE_NOT_EMPTY = "ignoreWorkspaceNotEmpty",
10
+ IGNORE_FCODE_RUN_PROCESSES = "ignoreFcodeRunProcesses",
11
+ LOCAL_VARIABLES_FILE_NAME = "localVariablesFileName",
12
+ SKIP_SKILLS_SETUP = "skipSkillsSetup",
13
+ VARIABLES_FILE_NAME = "variablesFileName"
14
+ }
15
+ export declare const SETTINGS_DEFINITIONS: SettingDefinition[];
16
+ export declare function getSettingDefault(key: string): string | undefined;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SETTINGS_DEFINITIONS = exports.SettingKeys = void 0;
4
+ exports.getSettingDefault = getSettingDefault;
5
+ var SettingKeys;
6
+ (function (SettingKeys) {
7
+ SettingKeys["DISABLE_UPDATE_NOTIFIER"] = "disableUpdateNotifier";
8
+ SettingKeys["IGNORE_PROCESS_VERSIONS"] = "ignoreProcessVersions";
9
+ SettingKeys["IGNORE_WORKSPACE_NOT_EMPTY"] = "ignoreWorkspaceNotEmpty";
10
+ SettingKeys["IGNORE_FCODE_RUN_PROCESSES"] = "ignoreFcodeRunProcesses";
11
+ SettingKeys["LOCAL_VARIABLES_FILE_NAME"] = "localVariablesFileName";
12
+ SettingKeys["SKIP_SKILLS_SETUP"] = "skipSkillsSetup";
13
+ SettingKeys["VARIABLES_FILE_NAME"] = "variablesFileName";
14
+ })(SettingKeys || (exports.SettingKeys = SettingKeys = {}));
15
+ exports.SETTINGS_DEFINITIONS = [
16
+ {
17
+ key: SettingKeys.IGNORE_WORKSPACE_NOT_EMPTY,
18
+ default: 'false',
19
+ description: 'Ignore workspace not empty error',
20
+ },
21
+ {
22
+ key: SettingKeys.DISABLE_UPDATE_NOTIFIER,
23
+ default: 'false',
24
+ description: 'Disable update notifier',
25
+ },
26
+ {
27
+ key: SettingKeys.SKIP_SKILLS_SETUP,
28
+ default: 'false',
29
+ description: 'Skip Factorial Code agent skills install on clone',
30
+ },
31
+ {
32
+ key: SettingKeys.IGNORE_FCODE_RUN_PROCESSES,
33
+ default: 'false',
34
+ description: 'Ignore Factorial Code run processes',
35
+ },
36
+ {
37
+ key: SettingKeys.IGNORE_PROCESS_VERSIONS,
38
+ default: 'false',
39
+ description: 'Ignore process versions',
40
+ },
41
+ {
42
+ key: SettingKeys.VARIABLES_FILE_NAME,
43
+ default: 'variables.env',
44
+ description: 'Variables file name',
45
+ },
46
+ {
47
+ key: SettingKeys.LOCAL_VARIABLES_FILE_NAME,
48
+ default: 'variables.local.env',
49
+ description: 'Local variables file name',
50
+ },
51
+ ];
52
+ function getSettingDefault(key) {
53
+ return exports.SETTINGS_DEFINITIONS.find((def) => def.key === key)?.default;
54
+ }
@@ -0,0 +1,28 @@
1
+ import { ProgrammingLanguage, ResourceMetadata, TeamOrigin, type Resource, type TeamMetadata } from '../core/types';
2
+ import Config from './index';
3
+ export declare function unparseTeamOrigin({ url, slug }: TeamOrigin): string;
4
+ declare class WorkspaceConfig extends Config {
5
+ private static CONFIG_PATH;
6
+ private static CONFIG_FILENAME;
7
+ constructor(configPath?: string);
8
+ init(origin: TeamOrigin): Promise<void>;
9
+ getTeamOrigin(): Promise<TeamOrigin>;
10
+ getActiveTeamSlug(): Promise<string>;
11
+ getActiveTeam(): Promise<TeamMetadata>;
12
+ getTeam(slug: string): Promise<TeamMetadata>;
13
+ getAllTeams(): Promise<TeamMetadata[]>;
14
+ private setTeam;
15
+ getAddedTeams(): Promise<string[]>;
16
+ setActiveTeam(slug: string): Promise<void>;
17
+ private getCollectionByType;
18
+ private getCollectionByClass;
19
+ exists(resourceType: string, slug: string): Promise<boolean>;
20
+ getInAnyTeam(resourceType: string, slug: string): Promise<Resource | null>;
21
+ getStoredHash(resource: Resource): Promise<string>;
22
+ getTeamStoredHash(): Promise<string | undefined>;
23
+ setTeamStoredHash(contentHash: string): Promise<void>;
24
+ add(resourceType: string, resourceMetadata: ResourceMetadata): Promise<void>;
25
+ remove(resourceType: string, slug: string): Promise<void>;
26
+ }
27
+ export default WorkspaceConfig;
28
+ export declare const baseDependenciesPath: (programmingLanguage: ProgrammingLanguage) => string;
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.baseDependenciesPath = void 0;
4
+ exports.unparseTeamOrigin = unparseTeamOrigin;
5
+ const path = require("node:path");
6
+ const types_1 = require("../core/types");
7
+ const remote_1 = require("./remote");
8
+ const errors_1 = require("../core/errors");
9
+ const index_1 = require("./index");
10
+ const cli_1 = require("../utils/cli");
11
+ const color_1 = require("@oclif/color");
12
+ const global_1 = require("./global");
13
+ function unparseTeamOrigin({ url, slug }) {
14
+ return url === global_1.FCODE_CLOUD_URL ? slug : `${url}/${slug}`;
15
+ }
16
+ class WorkspaceConfig extends index_1.default {
17
+ constructor(configPath = process.cwd()) {
18
+ super(path.join(configPath, WorkspaceConfig.CONFIG_PATH), WorkspaceConfig.CONFIG_FILENAME);
19
+ }
20
+ async init(origin) {
21
+ const team = unparseTeamOrigin(origin);
22
+ const remoteConfig = new remote_1.default(team, this.configDir);
23
+ await remoteConfig.init();
24
+ await index_1.default.initConfig(this.configPath, {
25
+ activeTeam: team,
26
+ teams: { [team]: remoteConfig.hash },
27
+ });
28
+ }
29
+ async getTeamOrigin() {
30
+ const team = await this.getActiveTeam();
31
+ return (0, global_1.parseTeamOrigin)(team.slug);
32
+ }
33
+ async getActiveTeamSlug() {
34
+ return (await this.get('activeTeam')) || '';
35
+ }
36
+ async getActiveTeam() {
37
+ const slug = await this.getActiveTeamSlug();
38
+ return this.getTeam(slug);
39
+ }
40
+ async getTeam(slug) {
41
+ if (!slug) {
42
+ throw new errors_1.NotFcodeWorkspace();
43
+ }
44
+ const config = await this.getAll();
45
+ const team = remote_1.default.get(config.teams[slug], this.configDir);
46
+ if (team) {
47
+ return team;
48
+ }
49
+ throw new errors_1.NotFcodeWorkspace();
50
+ }
51
+ async getAllTeams() {
52
+ const config = await this.getAll();
53
+ return Promise.all(Object.keys(config.teams).map(async (slug) => this.getTeam(slug)));
54
+ }
55
+ async setTeam(team) {
56
+ const config = await this.getAll();
57
+ const activeTeam = config.activeTeam;
58
+ if (!activeTeam) {
59
+ throw new errors_1.NotFcodeWorkspace();
60
+ }
61
+ const hash = config.teams[activeTeam];
62
+ await remote_1.default.save(hash, team, this.configDir);
63
+ }
64
+ async getAddedTeams() {
65
+ const config = await this.getAll();
66
+ return Object.keys(config.teams);
67
+ }
68
+ async setActiveTeam(slug) {
69
+ await this.set('activeTeam', slug);
70
+ const teams = (await this.get('teams')) || {};
71
+ if (!teams[slug]) {
72
+ const remoteConfig = new remote_1.default(slug, this.configDir);
73
+ await remoteConfig.init();
74
+ teams[slug] = remoteConfig.hash;
75
+ await this.set('teams', teams);
76
+ }
77
+ }
78
+ async getCollectionByType(team, resourceType) {
79
+ if (resourceType === 'processes') {
80
+ return team.processes;
81
+ }
82
+ else if (resourceType === 'modules') {
83
+ return team.modules;
84
+ }
85
+ else if (resourceType === 'variables') {
86
+ return team.variables;
87
+ }
88
+ else if (resourceType === 'dependencies') {
89
+ return team.dependencies;
90
+ }
91
+ throw new Error('Unknow resource type');
92
+ }
93
+ async getCollectionByClass(team, resource) {
94
+ if (resource instanceof types_1.Process) {
95
+ return team.processes;
96
+ }
97
+ else if (resource instanceof types_1.ScriptLibrary) {
98
+ return team.modules;
99
+ }
100
+ else if (resource instanceof types_1.Variable) {
101
+ return team.variables;
102
+ }
103
+ else if (resource instanceof types_1.ProgrammingLanguageManifest) {
104
+ return team.dependencies;
105
+ }
106
+ throw new Error('Unknow resource type');
107
+ }
108
+ async exists(resourceType, slug) {
109
+ return (await this.getCollectionByType(await this.getActiveTeam(), resourceType))[slug];
110
+ }
111
+ async getInAnyTeam(resourceType, slug) {
112
+ const teams = await this.getAllTeams();
113
+ for (const team of teams) {
114
+ const resource = (await this.getCollectionByType(team, resourceType))[slug];
115
+ if (resource) {
116
+ return resource;
117
+ }
118
+ }
119
+ return null;
120
+ }
121
+ async getStoredHash(resource) {
122
+ const metadata = (await this.getCollectionByClass(await this.getActiveTeam(), resource))[resource.slug];
123
+ return metadata?.contentHash;
124
+ }
125
+ async getTeamStoredHash() {
126
+ return (await this.getActiveTeam()).team?.contentHash;
127
+ }
128
+ async setTeamStoredHash(contentHash) {
129
+ const team = await this.getActiveTeam();
130
+ await this.setTeam({ ...team, team: { contentHash } });
131
+ }
132
+ async add(resourceType, resourceMetadata) {
133
+ const team = await this.getActiveTeam();
134
+ await this.setTeam({
135
+ ...team,
136
+ [resourceType]: {
137
+ ...team[resourceType],
138
+ [resourceMetadata.slug]: resourceMetadata,
139
+ },
140
+ });
141
+ }
142
+ async remove(resourceType, slug) {
143
+ const team = await this.getActiveTeam();
144
+ if (!team[resourceType][slug]) {
145
+ cli_1.default.log(color_1.default.red(`🧐 ${resourceType} not found for slug '${slug}'`));
146
+ return;
147
+ }
148
+ delete team[resourceType][slug];
149
+ await this.setTeam(team);
150
+ }
151
+ }
152
+ WorkspaceConfig.CONFIG_PATH = '.fcode';
153
+ WorkspaceConfig.CONFIG_FILENAME = 'workspace.json';
154
+ exports.default = WorkspaceConfig;
155
+ const baseDependenciesPath = (programmingLanguage) => {
156
+ return path.join(path.join(index_1.default.FCODE_CONFIG_PATH, index_1.default.FCODE_DEPENDENCIES_FOLDER, programmingLanguage === 'JAVASCRIPT' ? 'node' : programmingLanguage.toLowerCase()));
157
+ };
158
+ exports.baseDependenciesPath = baseDependenciesPath;
@@ -0,0 +1,6 @@
1
+ import BaseCommand from './base-command';
2
+ import FcodeGraphQLClient from '../../services/fcode-graphql-client';
3
+ export default abstract class ApiClientCommand extends BaseCommand {
4
+ _fcodeGraphQLClient: FcodeGraphQLClient;
5
+ init(): Promise<void>;
6
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const base_command_1 = require("./base-command");
4
+ const errors_1 = require("../errors");
5
+ const fcode_graphql_client_1 = require("../../services/fcode-graphql-client");
6
+ class ApiClientCommand extends base_command_1.default {
7
+ async init() {
8
+ await super.init();
9
+ try {
10
+ const { url, slug } = await this.workspaceConfig.getTeamOrigin();
11
+ const { token: { access_token: accessToken }, } = await this.globalConfig.getAuthInfo(url);
12
+ this._fcodeGraphQLClient = new fcode_graphql_client_1.default({
13
+ url,
14
+ accessToken,
15
+ teamSlug: slug,
16
+ });
17
+ }
18
+ catch (error) {
19
+ if (error instanceof errors_1.NotAuthenticated) {
20
+ this.error(error.message, {
21
+ code: 'ERR_NOT_AUTHENTICATED',
22
+ exit: 1,
23
+ suggestions: ['fcode login'],
24
+ });
25
+ }
26
+ throw error;
27
+ }
28
+ }
29
+ }
30
+ exports.default = ApiClientCommand;
@@ -0,0 +1,11 @@
1
+ import { Command } from '@oclif/core';
2
+ import GlobalConfig from '../../config/global';
3
+ import WorkspaceConfig from '../../config/workspace';
4
+ export default abstract class BaseCommand extends Command {
5
+ url?: string;
6
+ globalConfig: GlobalConfig;
7
+ workspaceConfig: WorkspaceConfig;
8
+ catch(error: any): Promise<any>;
9
+ init(url?: string): Promise<void>;
10
+ protected logActiveTeam(): Promise<void>;
11
+ }
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@oclif/core");
4
+ const global_1 = require("../../config/global");
5
+ const workspace_1 = require("../../config/workspace");
6
+ const color_1 = require("@oclif/color");
7
+ const errors_1 = require("../errors");
8
+ const cli_1 = require("../../utils/cli");
9
+ const url_utils_1 = require("../../utils/url-utils");
10
+ class BaseCommand extends core_1.Command {
11
+ async catch(error) {
12
+ // do any extra work with error
13
+ if (error && error.response && error.response.status === 401) {
14
+ cli_1.default.error(`User authentication is invalid for current team.`);
15
+ return;
16
+ }
17
+ if (error instanceof errors_1.NotAuthenticated) {
18
+ let errorMessage = 'No session active. Logging you in';
19
+ const loginArgs = [];
20
+ let url = error.getUrl() || this.url;
21
+ if (!url || url === global_1.FCODE_CLOUD_URL) {
22
+ url = undefined;
23
+ }
24
+ else {
25
+ loginArgs.push('--url', url);
26
+ errorMessage += ` to ${url}`;
27
+ const { authUrl } = await new global_1.default().getAuthInfo(url);
28
+ if (!(0, url_utils_1.isDefaultAuthUrl)(authUrl, url)) {
29
+ loginArgs.push('--authUrl', authUrl);
30
+ if (authUrl) {
31
+ errorMessage += ` (with authUrl ${authUrl})`;
32
+ }
33
+ }
34
+ }
35
+ cli_1.default.error(`${errorMessage}...`);
36
+ await this.config.runCommand('login', loginArgs).catch((e) => cli_1.default.error(e.message));
37
+ cli_1.default.log('');
38
+ cli_1.default.log('🔁 Retrying command after login...');
39
+ cli_1.default.log('');
40
+ return this.run();
41
+ }
42
+ if (error instanceof errors_1.CLIError) {
43
+ cli_1.default.error(error);
44
+ return;
45
+ }
46
+ cli_1.default.error(error.message);
47
+ }
48
+ async init(url) {
49
+ this.url = url;
50
+ this.globalConfig = new global_1.default();
51
+ this.workspaceConfig = new workspace_1.default();
52
+ const workspaceUrl = url || (await this.workspaceConfig.getTeamOrigin()).url;
53
+ const { authUrl } = await this.globalConfig.getAuthInfo(workspaceUrl);
54
+ await this.config.runHook('auth', { argv: [workspaceUrl, authUrl], id: 'init' });
55
+ }
56
+ async logActiveTeam() {
57
+ const { slug, url } = await this.workspaceConfig.getTeamOrigin();
58
+ cli_1.default.log(color_1.default.magenta(`💻 Working on Factorial Code team '${slug}${url !== global_1.FCODE_CLOUD_URL ? ` (${url})` : ''}'.`));
59
+ }
60
+ }
61
+ exports.default = BaseCommand;
@@ -0,0 +1,5 @@
1
+ import { ProgrammingLanguageManifest } from '../types';
2
+ import ResourceCommand from './resource-command';
3
+ export default abstract class DependencyCommand extends ResourceCommand<ProgrammingLanguageManifest> {
4
+ init(): Promise<void>;
5
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const programming_language_manifest_1 = require("../../repositories/programming-language-manifest");
4
+ const resource_merger_1 = require("../resource-merger");
5
+ const resource_pusher_1 = require("../resource-pusher");
6
+ const resource_command_1 = require("./resource-command");
7
+ class DependencyCommand extends resource_command_1.default {
8
+ async init() {
9
+ await super.init();
10
+ this._resourceRepository = new programming_language_manifest_1.default();
11
+ this._resourceMerger = new resource_merger_1.default(this._resourceRepository);
12
+ this._resourcePusher = new resource_pusher_1.default(this._resourceRepository, this._fcodeGraphQLClient);
13
+ this._resourceQuery = () => this._fcodeGraphQLClient.allProgrammingLanguageManifest.bind(this._fcodeGraphQLClient)();
14
+ }
15
+ }
16
+ exports.default = DependencyCommand;
@@ -0,0 +1,7 @@
1
+ import { ScriptLibrary, VersionedScriptLibrary } from '../types';
2
+ import ResourceCommand from './resource-command';
3
+ export default abstract class ModulesCommand extends ResourceCommand<ScriptLibrary> {
4
+ _versionedResourceQuery: (id: string) => Promise<Array<VersionedScriptLibrary>>;
5
+ _pushVersionedResourceMutation: (versionedProcess: VersionedScriptLibrary) => Promise<void>;
6
+ init(): Promise<void>;
7
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const script_library_1 = require("../../repositories/script-library");
4
+ const resource_merger_1 = require("../resource-merger");
5
+ const resource_pusher_1 = require("../resource-pusher");
6
+ const resource_command_1 = require("./resource-command");
7
+ class ModulesCommand extends resource_command_1.default {
8
+ async init() {
9
+ await super.init();
10
+ this._resourceRepository = new script_library_1.default();
11
+ this._resourceMerger = new resource_merger_1.default(this._resourceRepository);
12
+ this._resourcePusher = new resource_pusher_1.default(this._resourceRepository, this._fcodeGraphQLClient);
13
+ this._resourceQuery = () => this._fcodeGraphQLClient.allScriptLibraries.bind(this._fcodeGraphQLClient)();
14
+ this._versionedResourceQuery = (id) => this._fcodeGraphQLClient.allVersionedScriptLibraries.bind(this._fcodeGraphQLClient)(id);
15
+ this._pushVersionedResourceMutation = (versionedScriptLibrary) => this._fcodeGraphQLClient.createVersionedScriptLibrary.bind(this._fcodeGraphQLClient)(versionedScriptLibrary);
16
+ }
17
+ }
18
+ exports.default = ModulesCommand;
@@ -0,0 +1,8 @@
1
+ import { Process, VersionedProcess } from '../types';
2
+ import ResourceCommand from './resource-command';
3
+ export default abstract class ProcessesCommand extends ResourceCommand<Process> {
4
+ _versionedResourceQuery: (id: string) => Promise<Array<VersionedProcess>>;
5
+ _pushVersionedResourceMutation: (versionedProcess: VersionedProcess) => Promise<void>;
6
+ init(): Promise<void>;
7
+ getRemoteResources(): Promise<Array<Process>>;
8
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const settings_1 = require("../../config/settings");
4
+ const process_1 = require("../../repositories/process");
5
+ const resource_merger_1 = require("../resource-merger");
6
+ const resource_pusher_1 = require("../resource-pusher");
7
+ const resource_command_1 = require("./resource-command");
8
+ class ProcessesCommand extends resource_command_1.default {
9
+ async init() {
10
+ await super.init();
11
+ this._resourceRepository = new process_1.default();
12
+ this._resourceMerger = new resource_merger_1.default(this._resourceRepository);
13
+ this._resourcePusher = new resource_pusher_1.default(this._resourceRepository, this._fcodeGraphQLClient);
14
+ this._resourceQuery = () => this._fcodeGraphQLClient.allProcesses.bind(this._fcodeGraphQLClient)();
15
+ this._versionedResourceQuery = (id) => this._fcodeGraphQLClient.allVersionedProcesses.bind(this._fcodeGraphQLClient)(id);
16
+ this._pushVersionedResourceMutation = (versionedProcess) => this._fcodeGraphQLClient.createVersionedProcesses.bind(this._fcodeGraphQLClient)(versionedProcess);
17
+ }
18
+ async getRemoteResources() {
19
+ const processes = await super.getRemoteResources();
20
+ const ignoreFcodeRunProcesses = (await this.globalConfig.getSetting(settings_1.SettingKeys.IGNORE_FCODE_RUN_PROCESSES)) === 'true';
21
+ if (ignoreFcodeRunProcesses) {
22
+ return processes.filter((process) => !process.tags?.includes('fc-run'));
23
+ }
24
+ return processes;
25
+ }
26
+ }
27
+ exports.default = ProcessesCommand;
@@ -0,0 +1,24 @@
1
+ import type { AddResourceOptions, MergedResource, Resource } from '../types';
2
+ import ResourceRepositoryBase from '../../repositories/resource';
3
+ import ResourceMerger from '../resource-merger';
4
+ import ResourcePusher from '../resource-pusher';
5
+ import ApiClientCommand from './api-client-command';
6
+ export default abstract class ResourceCommand<R extends Resource> extends ApiClientCommand {
7
+ _resourceMerger: ResourceMerger<R>;
8
+ _resourcePusher: ResourcePusher<R>;
9
+ _resourceQuery: () => Promise<Array<R>>;
10
+ _resourceRepository: ResourceRepositoryBase<R>;
11
+ protected resourceSlug: string;
12
+ protected filterResource: (slug: string) => boolean;
13
+ getLocalResources(): Promise<Array<R>>;
14
+ getRemoteResources(): Promise<Array<R>>;
15
+ findSlugsNotAdded(): Promise<Array<string>>;
16
+ init(): Promise<void>;
17
+ pullResources(): Promise<void>;
18
+ resetResources(): Promise<void>;
19
+ addResources(opts?: AddResourceOptions): Promise<void>;
20
+ removeResource(slug: string): Promise<void>;
21
+ pushResources(): Promise<void>;
22
+ resourcesLog(): Promise<void>;
23
+ resourcesTableLog(resources: Array<MergedResource>): Promise<void>;
24
+ }
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const color_1 = require("@oclif/color");
4
+ const cli_1 = require("../../utils/cli");
5
+ const api_client_command_1 = require("./api-client-command");
6
+ const colorize_resource_1 = require("../../utils/colorize-resource");
7
+ class ResourceCommand extends api_client_command_1.default {
8
+ constructor() {
9
+ super(...arguments);
10
+ this.filterResource = (slug) => !this.resourceSlug || slug === this.resourceSlug;
11
+ }
12
+ async getLocalResources() {
13
+ const resources = await this._resourceRepository.findAll();
14
+ return resources.filter((resource) => this.filterResource(resource.slug));
15
+ }
16
+ async getRemoteResources() {
17
+ const resources = await this._resourceQuery();
18
+ return resources.filter((resource) => this.filterResource(resource.slug));
19
+ }
20
+ async findSlugsNotAdded() {
21
+ const slugsNotAdded = await this._resourceRepository.findSlugsNotAdded();
22
+ return slugsNotAdded.filter((slug) => this.filterResource(slug));
23
+ }
24
+ async init() {
25
+ await super.init();
26
+ const { argv: [resourceSlug], } = await this.parse(this.ctor);
27
+ this.resourceSlug = resourceSlug;
28
+ }
29
+ async pullResources() {
30
+ const { flags: { force }, } = await this.parse(this.ctor);
31
+ cli_1.default.log(color_1.default.cyan(`\n🗄️ pulling ${this._resourceRepository._repositoryName}...`));
32
+ await this._resourceMerger.mergeForPull(await this.getRemoteResources(), await this.getLocalResources(), force);
33
+ }
34
+ async resetResources() {
35
+ cli_1.default.log(color_1.default.cyan(`\n🧹 reseting ${this._resourceRepository._repositoryName}...`));
36
+ await this._resourceMerger.reset(await this.getRemoteResources(), await this.getLocalResources());
37
+ }
38
+ async addResources(opts) {
39
+ const slugsNotAdded = await this.findSlugsNotAdded();
40
+ if (!slugsNotAdded.length) {
41
+ cli_1.default.log(color_1.default.cyan(`🧐 no local ${this._resourceRepository._repositoryName} found to be added`));
42
+ return;
43
+ }
44
+ for (const slug of slugsNotAdded) {
45
+ cli_1.default.log(color_1.default.cyan(`✨ adding ${this._resourceRepository._repositoryName} '${slug}'...`));
46
+ if (this._resourceRepository._repositoryName === 'processes') {
47
+ this._resourceRepository.ensureAllFilesExist(slug);
48
+ }
49
+ await this.workspaceConfig.add(this._resourceRepository._repositoryName, await this._resourceRepository.metadataFromFiles(slug, opts));
50
+ }
51
+ }
52
+ async removeResource(slug) {
53
+ await this.workspaceConfig.remove(this._resourceRepository._repositoryName, slug);
54
+ cli_1.default.log(`\n🗑️ '${slug}' successfully removed from ${this._resourceRepository._repositoryName}`);
55
+ }
56
+ async pushResources() {
57
+ const { flags: { force }, } = await this.parse(this.ctor);
58
+ await this._resourcePusher.push(await this.getRemoteResources(), await this.getLocalResources(), force);
59
+ }
60
+ async resourcesLog() {
61
+ cli_1.default.log(color_1.default.cyan(`\n${this._resourceRepository._repositoryName} status`));
62
+ const mergedResources = await this._resourceMerger.mergeStatus(await this.getRemoteResources(), await this.getLocalResources());
63
+ if (mergedResources.length > 0) {
64
+ await this.resourcesTableLog(mergedResources);
65
+ }
66
+ else {
67
+ cli_1.default.log(`No ${this._resourceRepository._repositoryName} found`);
68
+ }
69
+ const slugsNotAdded = await this.findSlugsNotAdded();
70
+ if (slugsNotAdded.length > 0) {
71
+ const warningText = `\nℹ️ ${slugsNotAdded.length} ${this._resourceRepository._repositoryName} only existing in local: ${slugsNotAdded.join(', ')}\n Use command 'fcode ${this._resourceRepository._repositoryName}:add' to keep track of these resources`;
72
+ cli_1.default.log(color_1.default.yellow(warningText));
73
+ }
74
+ }
75
+ async resourcesTableLog(resources) {
76
+ cli_1.default.table(resources, {
77
+ name: {
78
+ get({ slug, status }) {
79
+ return (0, colorize_resource_1.colorizeByStatus)(slug, status);
80
+ },
81
+ header: 'name',
82
+ },
83
+ status: {
84
+ get({ status }) {
85
+ return (0, colorize_resource_1.colorizeByStatus)(status, status);
86
+ },
87
+ header: 'status',
88
+ },
89
+ }, { sort: 'name' });
90
+ }
91
+ }
92
+ exports.default = ResourceCommand;
@@ -0,0 +1,5 @@
1
+ import { Variable } from '../types';
2
+ import ResourceCommand from './resource-command';
3
+ export default abstract class VariablesCommand extends ResourceCommand<Variable> {
4
+ init(): Promise<void>;
5
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const variable_1 = require("../../repositories/variable");
4
+ const resource_merger_1 = require("../resource-merger");
5
+ const resource_pusher_1 = require("../resource-pusher");
6
+ const resource_command_1 = require("./resource-command");
7
+ class VariablesCommand extends resource_command_1.default {
8
+ async init() {
9
+ await super.init();
10
+ this._resourceRepository = new variable_1.default();
11
+ this._resourceMerger = new resource_merger_1.default(this._resourceRepository);
12
+ this._resourcePusher = new resource_pusher_1.default(this._resourceRepository, this._fcodeGraphQLClient);
13
+ this._resourceQuery = () => this._fcodeGraphQLClient.allVariables.bind(this._fcodeGraphQLClient)();
14
+ }
15
+ }
16
+ exports.default = VariablesCommand;