apify-cli 1.0.0-beta.9 → 1.0.0-beta.90
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/CHANGELOG.md +200 -0
- package/README.md +82 -75
- package/bin/dev.js +7 -2
- package/bin/dev.sh +4 -0
- package/bin/run.js +7 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/commands/actor/push-data.js +2 -2
- package/dist/commands/actor/set-value.js +3 -3
- package/dist/commands/actor/set-value.js.map +1 -1
- package/dist/commands/call.d.ts +1 -0
- package/dist/commands/call.d.ts.map +1 -1
- package/dist/commands/call.js +49 -20
- package/dist/commands/call.js.map +1 -1
- package/dist/commands/create.d.ts +1 -0
- package/dist/commands/create.d.ts.map +1 -1
- package/dist/commands/create.js +12 -3
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/login.d.ts +1 -0
- package/dist/commands/login.d.ts.map +1 -1
- package/dist/commands/login.js +143 -12
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/push.d.ts.map +1 -1
- package/dist/commands/push.js +35 -8
- package/dist/commands/push.js.map +1 -1
- package/dist/commands/run.d.ts +1 -0
- package/dist/commands/run.d.ts.map +1 -1
- package/dist/commands/run.js +76 -20
- package/dist/commands/run.js.map +1 -1
- package/dist/commands/secrets/index.js +1 -1
- package/dist/commands/{vis.d.ts → validate-schema.d.ts} +2 -1
- package/dist/commands/validate-schema.d.ts.map +1 -0
- package/dist/commands/{vis.js → validate-schema.js} +7 -1
- package/dist/commands/validate-schema.js.map +1 -0
- package/dist/hooks/deprecations.d.ts +4 -0
- package/dist/hooks/deprecations.d.ts.map +1 -0
- package/dist/hooks/deprecations.js +18 -0
- package/dist/hooks/deprecations.js.map +1 -0
- package/dist/lib/actor.d.ts +1 -1
- package/dist/lib/actor.js +2 -2
- package/dist/lib/actor.js.map +1 -1
- package/dist/lib/consts.d.ts +8 -0
- package/dist/lib/consts.d.ts.map +1 -1
- package/dist/lib/consts.js +10 -0
- package/dist/lib/consts.js.map +1 -1
- package/dist/lib/exec.d.ts.map +1 -1
- package/dist/lib/exec.js +6 -1
- package/dist/lib/exec.js.map +1 -1
- package/dist/lib/input_schema.d.ts +1 -1
- package/dist/lib/input_schema.d.ts.map +1 -1
- package/dist/lib/secrets.js +3 -3
- package/dist/lib/telemetry.d.ts.map +1 -1
- package/dist/lib/utils.d.ts +6 -7
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/utils.js +29 -9
- package/dist/lib/utils.js.map +1 -1
- package/oclif.manifest.json +40 -37
- package/package.json +148 -141
- package/dist/commands/login-new.d.ts +0 -10
- package/dist/commands/login-new.d.ts.map +0 -1
- package/dist/commands/login-new.js +0 -166
- package/dist/commands/login-new.js.map +0 -1
- package/dist/commands/vis.d.ts.map +0 -1
- package/dist/commands/vis.js.map +0 -1
|
@@ -38,9 +38,9 @@ Object.defineProperty(PushDataCommand, "description", {
|
|
|
38
38
|
value: 'Stores an object or an array of objects to the default dataset of the Actor run.\n'
|
|
39
39
|
+ 'It is possible to pass data using item argument or stdin.\n'
|
|
40
40
|
+ 'Passing data using argument:\n'
|
|
41
|
-
+ '$ apify actor
|
|
41
|
+
+ '$ apify actor push-data {"foo": "bar"}\n'
|
|
42
42
|
+ 'Passing data using stdin with pipe:\n'
|
|
43
|
-
+ '$ cat ./test.json | apify actor
|
|
43
|
+
+ '$ cat ./test.json | apify actor push-data\n'
|
|
44
44
|
});
|
|
45
45
|
Object.defineProperty(PushDataCommand, "args", {
|
|
46
46
|
enumerable: true,
|
|
@@ -24,7 +24,7 @@ export class SetValueCommand extends ApifyCommand {
|
|
|
24
24
|
const recordValue = value || stdin;
|
|
25
25
|
const apifyClient = await getApifyStorageClient();
|
|
26
26
|
const storeClient = apifyClient.keyValueStore(getDefaultStorageId(APIFY_STORAGE_TYPES.KEY_VALUE_STORE));
|
|
27
|
-
if (recordValue === undefined || recordValue === null) {
|
|
27
|
+
if (recordValue === undefined || recordValue === null || recordValue === '' || recordValue === 'null' || recordValue === 'undefined') {
|
|
28
28
|
await storeClient.deleteRecord(key);
|
|
29
29
|
}
|
|
30
30
|
else {
|
|
@@ -39,9 +39,9 @@ Object.defineProperty(SetValueCommand, "description", {
|
|
|
39
39
|
value: 'Sets or removes record into the default KeyValueStore associated with the Actor run.\n'
|
|
40
40
|
+ 'It is possible to pass data using argument or stdin.\n'
|
|
41
41
|
+ 'Passing data using argument:\n'
|
|
42
|
-
+ '$ apify actor
|
|
42
|
+
+ '$ apify actor set-value KEY my-value\n'
|
|
43
43
|
+ 'Passing data using stdin with pipe:\n'
|
|
44
|
-
+ '$ cat ./my-text-file.txt | apify actor
|
|
44
|
+
+ '$ cat ./my-text-file.txt | apify actor set-value KEY --contentType text/plain\n'
|
|
45
45
|
});
|
|
46
46
|
Object.defineProperty(SetValueCommand, "args", {
|
|
47
47
|
enumerable: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"set-value.js","sourceRoot":"","sources":["../../../src/commands/actor/set-value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACrG,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,MAAM,OAAO,eAAgB,SAAQ,YAAoC;IAAzE;;QA8BY;;;;;WAA6B;IAwBzC,CAAC;IAtBY,KAAK,CAAC,IAAI;QACf,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;QACnB,sCAAsC;QACtC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,GAAG;QACL,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QACvB,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC;QACjC,MAAM,EAAE,WAAW,GAAG,iC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B,CAAC,eAAe,CAAC,CAAC,CAAC;QAExG,IAAI,WAAW,KAAK,SAAS,IAAI,WAAW,KAAK,IAAI,IAAI,WAAW,KAAK,EAAE,IAAI,WAAW,KAAK,MAAM,IAAI,WAAW,KAAK,WAAW,EAAE,CAAC;YACnI,MAAM,WAAW,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;QACxC,CAAC;aAAM,CAAC;YACJ,MAAM,WAAW,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC,CAAC;QAC1E,CAAC;IACL,CAAC;;AApDe;;;;WAAc,wFAAwF;UAChH,wDAAwD;UACxD,gCAAgC;UAChC,wCAAwC;UACxC,uCAAuC;UACvC,iFAAiF;EAL5D,CAK6D;AAExE;;;;WAAO;QACnB,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC;YACb,QAAQ,EAAE,IAAI;YACd,WAAW,EAAE,uCAAuC;SACvD,CAAC;QACF,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC;YACf,QAAQ,EAAE,KAAK;YACf,WAAW,EAAE,0DAA0D;kBACrE,6DAA6D;kBAC7D,2FAA2F;kBAC3F,wDAAwD;SAC7D,CAAC;KACL;EAZmB,CAYlB;AAEc;;;;WAAQ;QACpB,WAAW,EAAE,KAAK,CAAC,MAAM,CAAC;YACtB,IAAI,EAAE,GAAG;YACT,WAAW,EAAE,4FAA4F;YACzG,QAAQ,EAAE,KAAK;SAClB,CAAC;KACL;EANoB,CAMnB"}
|
package/dist/commands/call.d.ts
CHANGED
|
@@ -11,5 +11,6 @@ export declare class CallCommand extends ApifyCommand<typeof CallCommand> {
|
|
|
11
11
|
actorId: import("@oclif/core/lib/interfaces/parser.js").Arg<string | undefined, Record<string, unknown>>;
|
|
12
12
|
};
|
|
13
13
|
run(): Promise<void>;
|
|
14
|
+
private resolveActorId;
|
|
14
15
|
}
|
|
15
16
|
//# sourceMappingURL=call.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"call.d.ts","sourceRoot":"","sources":["../../src/commands/call.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAKvD,qBAAa,WAAY,SAAQ,YAAY,CAAC,OAAO,WAAW,CAAC;IAC7D,OAAgB,WAAW,SAEyD;IAEpF,OAAgB,KAAK;;;;;MAqBnB;IAEF,OAAgB,IAAI;;MAMlB;IAEI,GAAG;
|
|
1
|
+
{"version":3,"file":"call.d.ts","sourceRoot":"","sources":["../../src/commands/call.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAKvD,qBAAa,WAAY,SAAQ,YAAY,CAAC,OAAO,WAAW,CAAC;IAC7D,OAAgB,WAAW,SAEyD;IAEpF,OAAgB,KAAK;;;;;MAqBnB;IAEF,OAAgB,IAAI;;MAMlB;IAEI,GAAG;YAgFK,cAAc;CA4C/B"}
|
package/dist/commands/call.js
CHANGED
|
@@ -7,7 +7,7 @@ import { ACTOR_JOB_STATUSES } from '@apify/consts';
|
|
|
7
7
|
import { Args, Flags } from '@oclif/core';
|
|
8
8
|
import mime from 'mime';
|
|
9
9
|
import { ApifyCommand } from '../lib/apify_command.js';
|
|
10
|
-
import { LOCAL_CONFIG_PATH } from '../lib/consts.js';
|
|
10
|
+
import { CommandExitCodes, LOCAL_CONFIG_PATH } from '../lib/consts.js';
|
|
11
11
|
import { error, link, run as runLog, success, warning } from '../lib/outputs.js';
|
|
12
12
|
import { getLocalConfig, getLocalInput, getLocalUserInfo, getLoggedClientOrThrow, outputJobLog } from '../lib/utils.js';
|
|
13
13
|
export class CallCommand extends ApifyCommand {
|
|
@@ -17,22 +17,10 @@ export class CallCommand extends ApifyCommand {
|
|
|
17
17
|
const apifyClient = await getLoggedClientOrThrow();
|
|
18
18
|
const userInfo = await getLocalUserInfo();
|
|
19
19
|
const usernameOrId = userInfo.username || userInfo.id;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (forceActorId) {
|
|
23
|
-
const actor = await apifyClient.actor(forceActorId).get();
|
|
24
|
-
if (!actor)
|
|
25
|
-
throw new Error(`Cannot find Actor with ID '${forceActorId}' in your account.`);
|
|
26
|
-
actorId = actor.username ? `${actor.username}/${actor.name}` : actor.id;
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
actorId = `${usernameOrId}/${localConfig.name}`;
|
|
30
|
-
const actor = await apifyClient.actor(actorId).get();
|
|
31
|
-
if (!actor) {
|
|
32
|
-
throw new Error(`Cannot find Actor with ID '${actorId}' `
|
|
33
|
-
+ 'in your account. Call "apify push" to push this Actor to Apify platform.');
|
|
34
|
-
}
|
|
20
|
+
if (!usernameOrId) {
|
|
21
|
+
throw new Error('Corrupted local user info was found. Please run "apify login" to fix it, then re-run this command.');
|
|
35
22
|
}
|
|
23
|
+
const { id: actorId, userFriendlyId } = await this.resolveActorId(apifyClient, localConfig.name, usernameOrId);
|
|
36
24
|
const runOpts = {
|
|
37
25
|
waitForFinish: 2, // NOTE: We need to wait some time to Apify open stream and we can create connection
|
|
38
26
|
};
|
|
@@ -50,13 +38,13 @@ export class CallCommand extends ApifyCommand {
|
|
|
50
38
|
}
|
|
51
39
|
// Get input for act
|
|
52
40
|
const localInput = getLocalInput(cwd);
|
|
53
|
-
runLog(`Calling Actor ${actorId}`);
|
|
41
|
+
runLog(`Calling Actor ${userFriendlyId} (${actorId})`);
|
|
54
42
|
let run;
|
|
55
43
|
try {
|
|
56
44
|
if (localInput) {
|
|
57
45
|
// TODO: For some reason we cannot pass json as buffer with right contentType into apify-client.
|
|
58
46
|
// It will save malformed JSON which looks like buffer as INPUT.
|
|
59
|
-
// We need to fix this in v1 during removing call under
|
|
47
|
+
// We need to fix this in v1 during removing call under Actor namespace.
|
|
60
48
|
const input = mime.getExtension(localInput.contentType) === 'json' ? JSON.parse(localInput.body.toString('utf-8')) : localInput.body;
|
|
61
49
|
run = await apifyClient.actor(actorId).start(input, { ...runOpts, contentType: localInput.contentType });
|
|
62
50
|
}
|
|
@@ -68,7 +56,7 @@ export class CallCommand extends ApifyCommand {
|
|
|
68
56
|
catch (err) {
|
|
69
57
|
// TODO: Better error message in apify-client-js
|
|
70
58
|
if (err.type === 'record-not-found')
|
|
71
|
-
throw new Error(`Actor ${actorId} not found!`);
|
|
59
|
+
throw new Error(`Actor ${userFriendlyId} (${actorId}) not found!`);
|
|
72
60
|
else
|
|
73
61
|
throw err;
|
|
74
62
|
}
|
|
@@ -87,9 +75,50 @@ export class CallCommand extends ApifyCommand {
|
|
|
87
75
|
else if (run.status === ACTOR_JOB_STATUSES.RUNNING) {
|
|
88
76
|
warning('Actor is still running!');
|
|
89
77
|
}
|
|
78
|
+
else if (run.status === ACTOR_JOB_STATUSES.ABORTED || run.status === ACTOR_JOB_STATUSES.ABORTING) {
|
|
79
|
+
warning('Actor was aborted!');
|
|
80
|
+
process.exitCode = CommandExitCodes.RunAborted;
|
|
81
|
+
}
|
|
90
82
|
else {
|
|
91
83
|
error('Actor failed!');
|
|
84
|
+
process.exitCode = CommandExitCodes.RunFailed;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async resolveActorId(client, localActorName, usernameOrId) {
|
|
88
|
+
const { actorId } = this.args;
|
|
89
|
+
// Full ID
|
|
90
|
+
if (actorId?.includes('/')) {
|
|
91
|
+
const actor = await client.actor(actorId).get();
|
|
92
|
+
if (!actor)
|
|
93
|
+
throw new Error(`Cannot find Actor with ID '${actorId}' in your account.`);
|
|
94
|
+
return {
|
|
95
|
+
userFriendlyId: `${actor.username}/${actor.name}`,
|
|
96
|
+
id: actor.id,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
// Try fetching Actor directly by name
|
|
100
|
+
if (actorId) {
|
|
101
|
+
const actor = await client.actor(`${usernameOrId}/${actorId.toLowerCase()}`).get();
|
|
102
|
+
if (!actor) {
|
|
103
|
+
throw new Error(`Cannot find Actor with name '${actorId}' in your account.`);
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
userFriendlyId: `${actor.username}/${actor.name}`,
|
|
107
|
+
id: actor.id,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
if (localActorName) {
|
|
111
|
+
const actor = await client.actor(`${usernameOrId}/${localActorName}`).get();
|
|
112
|
+
if (!actor) {
|
|
113
|
+
throw new Error(`Cannot find Actor with ID '${usernameOrId}/${localActorName}' `
|
|
114
|
+
+ 'in your account. Call "apify push" to push this Actor to Apify platform.');
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
userFriendlyId: `${actor.username}/${actor.name}`,
|
|
118
|
+
id: actor.id,
|
|
119
|
+
};
|
|
92
120
|
}
|
|
121
|
+
throw new Error('Please provide an Actor ID or name, or run this command from a directory with a valid Apify Actor.');
|
|
93
122
|
}
|
|
94
123
|
}
|
|
95
124
|
Object.defineProperty(CallCommand, "description", {
|
|
@@ -134,7 +163,7 @@ Object.defineProperty(CallCommand, "args", {
|
|
|
134
163
|
value: {
|
|
135
164
|
actorId: Args.string({
|
|
136
165
|
required: false,
|
|
137
|
-
description: 'Name or ID of the Actor to run (e.g. "apify/hello-world" or "E2jjCZBezvAZnX8Rb"). '
|
|
166
|
+
description: 'Name or ID of the Actor to run (e.g. "my-actor", "apify/hello-world" or "E2jjCZBezvAZnX8Rb"). '
|
|
138
167
|
+ `If not provided, the command runs the remote Actor specified in the "${LOCAL_CONFIG_PATH}" file.`,
|
|
139
168
|
}),
|
|
140
169
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"call.js","sourceRoot":"","sources":["../../src/commands/call.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,6BAA6B;AAC7B,2BAA2B;AAC3B,4BAA4B;AAE5B,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;A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,KAAK;SAClB,CAAC;KACL;GAAC;AAEc;;;;WAAO;QACnB,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC;YACjB,QAAQ,EAAE,KAAK;YACf,WAAW,EAAE,gGAAgG;kBAC3G,wEAAwE,iBAAiB,SAAS;SACvG,CAAC;KACL;GAAC"}
|
|
@@ -5,6 +5,7 @@ export declare class CreateCommand extends ApifyCommand<typeof CreateCommand> {
|
|
|
5
5
|
template: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
6
6
|
'skip-dependency-install': import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
|
|
7
7
|
'template-archive-url': import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
8
|
+
'omit-optional-deps': import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
|
|
8
9
|
};
|
|
9
10
|
static args: {
|
|
10
11
|
actorName: import("@oclif/core/lib/interfaces/parser.js").Arg<string | undefined, Record<string, unknown>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/commands/create.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAqBvD,qBAAa,aAAc,SAAQ,YAAY,CAAC,OAAO,aAAa,CAAC;IACjE,OAAgB,WAAW,SAAiF;IAE5G,OAAgB,KAAK
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/commands/create.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAqBvD,qBAAa,aAAc,SAAQ,YAAY,CAAC,OAAO,aAAa,CAAC;IACjE,OAAgB,WAAW,SAAiF;IAE5G,OAAgB,KAAK;;;;;MAqBnB;IAEF,OAAgB,IAAI;;MAKlB;IAEI,GAAG;CA+JZ"}
|
package/dist/commands/create.js
CHANGED
|
@@ -40,7 +40,7 @@ export class CreateCommand extends ApifyCommand {
|
|
|
40
40
|
actFolderDir = join(cwd, actorName);
|
|
41
41
|
continue;
|
|
42
42
|
}
|
|
43
|
-
// Create
|
|
43
|
+
// Create Actor directory structure
|
|
44
44
|
if (!folderExists) {
|
|
45
45
|
mkdirSync(actFolderDir);
|
|
46
46
|
}
|
|
@@ -59,6 +59,10 @@ export class CreateCommand extends ApifyCommand {
|
|
|
59
59
|
skipOptionalDeps = templateDefinition.skipOptionalDeps;
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
+
// Set this _after_ the template is resolved, so that the flag takes precedence
|
|
63
|
+
if (this.flags.omitOptionalDeps) {
|
|
64
|
+
skipOptionalDeps = true;
|
|
65
|
+
}
|
|
62
66
|
await downloadAndUnzip({ url: templateArchiveUrl, pathTo: actFolderDir });
|
|
63
67
|
// There may be .actor/actor.json file in used template - let's try to load it and change the name prop value to actorName
|
|
64
68
|
const localConfig = getJsonFileContent(join(actFolderDir, LOCAL_CONFIG_PATH));
|
|
@@ -82,9 +86,9 @@ export class CreateCommand extends ApifyCommand {
|
|
|
82
86
|
warning(`You are running Node.js version ${currentNodeVersion}, which is no longer supported. `
|
|
83
87
|
+ `Please upgrade to Node.js version ${minimumSupportedNodeVersion} or later.`);
|
|
84
88
|
}
|
|
85
|
-
// If the
|
|
89
|
+
// If the Actor is a Node.js Actor (has package.json), run `npm install`
|
|
86
90
|
await updateLocalJson(packageJsonPath, { name: actorName });
|
|
87
|
-
// Run npm install in
|
|
91
|
+
// Run npm install in Actor dir.
|
|
88
92
|
// For efficiency, don't install Puppeteer for templates that don't use it
|
|
89
93
|
const cmdArgs = ['install'];
|
|
90
94
|
if (skipOptionalDeps) {
|
|
@@ -170,6 +174,11 @@ Object.defineProperty(CreateCommand, "flags", {
|
|
|
170
174
|
required: false,
|
|
171
175
|
hidden: true,
|
|
172
176
|
}),
|
|
177
|
+
'omit-optional-deps': Flags.boolean({
|
|
178
|
+
aliases: ['no-optional'],
|
|
179
|
+
description: 'Skip installing optional dependencies.',
|
|
180
|
+
required: false,
|
|
181
|
+
}),
|
|
173
182
|
}
|
|
174
183
|
});
|
|
175
184
|
Object.defineProperty(CreateCommand, "args", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../src/commands/create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEzC,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AACrH,OAAO,EAAE,4BAA4B,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AACnH,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,uCAAuC,EAAE,MAAM,wBAAwB,CAAC;AACjF,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EACH,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,SAAS,EACT,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YAClD,QAAQ,EAAE,KAAK;SAClB,CAAC;QACF,sBAAsB,EAAE,KAAK,CAAC,MAAM,CAAC;YACjC,WAAW,EAAE,kEAAkE;YAC/E,QAAQ,EAAE,KAAK;YACf,MAAM,EAAE,IAAI;SACf,CAAC;QACF,oBAAoB,EAAE,KAAK,CAAC,OAAO,CAAC;YAChC,OAAO,EAAE,CAAC,aAAa,CAAC;YACxB,WAAW,EAAE,wCAAwC;YACrD,QAAQ,EAAE,KAAK;SAClB,CAAC;KACL;GAAC;AAEc;;;;WAAO;QACnB,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC;YACnB,QAAQ,EAAE,KAAK;YACf,WAAW,EAAE,qCAAqC;SACrD,CAAC;KACL;GAAC"}
|
package/dist/commands/login.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export declare class LoginCommand extends ApifyCommand<typeof LoginCommand> {
|
|
|
3
3
|
static description: string;
|
|
4
4
|
static flags: {
|
|
5
5
|
token: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
6
|
+
method: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
6
7
|
};
|
|
7
8
|
run(): Promise<void>;
|
|
8
9
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../src/commands/login.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../src/commands/login.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AA0BvD,qBAAa,YAAa,SAAQ,YAAY,CAAC,OAAO,YAAY,CAAC;IAC/D,OAAgB,WAAW,SAEU;IAErC,OAAgB,KAAK;;;MAYnB;IAEI,GAAG;CA6HZ"}
|
package/dist/commands/login.js
CHANGED
|
@@ -1,30 +1,155 @@
|
|
|
1
|
+
import { cryptoRandomObjectId } from '@apify/utilities';
|
|
1
2
|
import { Flags } from '@oclif/core';
|
|
3
|
+
import computerName from 'computer-name';
|
|
4
|
+
import cors from 'cors';
|
|
5
|
+
import express from 'express';
|
|
2
6
|
import inquirer from 'inquirer';
|
|
7
|
+
import open from 'open';
|
|
3
8
|
import { ApifyCommand } from '../lib/apify_command.js';
|
|
4
|
-
import { error, success } from '../lib/outputs.js';
|
|
9
|
+
import { error, info, success } from '../lib/outputs.js';
|
|
5
10
|
import { useApifyIdentity } from '../lib/telemetry.js';
|
|
6
11
|
import { getLocalUserInfo, getLoggedClient } from '../lib/utils.js';
|
|
12
|
+
const CONSOLE_BASE_URL = 'https://console.apify.com/account?tab=integrations';
|
|
13
|
+
// const CONSOLE_BASE_URL = 'http://localhost:3000/account?tab=integrations';
|
|
14
|
+
const CONSOLE_URL_ORIGIN = new URL(CONSOLE_BASE_URL).origin;
|
|
15
|
+
const API_BASE_URL = CONSOLE_BASE_URL.includes('localhost') ? 'http://localhost:3333' : undefined;
|
|
16
|
+
// Not really checked right now, but it might come useful if we ever need to do some breaking changes
|
|
17
|
+
const API_VERSION = 'v1';
|
|
18
|
+
const tryToLogin = async (token) => {
|
|
19
|
+
const isUserLogged = await getLoggedClient(token, API_BASE_URL);
|
|
20
|
+
const userInfo = await getLocalUserInfo();
|
|
21
|
+
if (isUserLogged) {
|
|
22
|
+
await useApifyIdentity(userInfo.id);
|
|
23
|
+
success(`You are logged in to Apify as ${userInfo.username || userInfo.id}!`);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
error('Login to Apify failed, the provided API token is not valid.');
|
|
27
|
+
}
|
|
28
|
+
return isUserLogged;
|
|
29
|
+
};
|
|
7
30
|
export class LoginCommand extends ApifyCommand {
|
|
8
31
|
async run() {
|
|
9
|
-
|
|
10
|
-
if (
|
|
32
|
+
const { token, method } = this.flags;
|
|
33
|
+
if (token) {
|
|
34
|
+
await tryToLogin(token);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
let selectedMethod = method;
|
|
38
|
+
if (!method) {
|
|
39
|
+
const answer = await inquirer.prompt([{
|
|
40
|
+
type: 'list',
|
|
41
|
+
name: 'loginMethod',
|
|
42
|
+
message: 'Choose how you want to log in to Apify',
|
|
43
|
+
choices: [
|
|
44
|
+
{
|
|
45
|
+
value: 'console',
|
|
46
|
+
name: 'Through Apify Console in your default browser',
|
|
47
|
+
short: 'Through Apify Console',
|
|
48
|
+
},
|
|
49
|
+
{ value: 'manual', name: 'Enter API token manually', short: 'Manually' },
|
|
50
|
+
],
|
|
51
|
+
loop: true,
|
|
52
|
+
}]);
|
|
53
|
+
selectedMethod = answer.loginMethod;
|
|
54
|
+
}
|
|
55
|
+
if (selectedMethod === 'console') {
|
|
56
|
+
let server;
|
|
57
|
+
const app = express();
|
|
58
|
+
// To send requests from browser to localhost, CORS has to be configured properly
|
|
59
|
+
app.use(cors({
|
|
60
|
+
origin: CONSOLE_URL_ORIGIN,
|
|
61
|
+
allowedHeaders: ['Content-Type', 'Authorization'],
|
|
62
|
+
}));
|
|
63
|
+
// Turn off keepalive, otherwise closing the server when command is finished is lagging
|
|
64
|
+
app.use((_, res, next) => {
|
|
65
|
+
res.set('Connection', 'close');
|
|
66
|
+
next();
|
|
67
|
+
});
|
|
68
|
+
app.use(express.json());
|
|
69
|
+
// Basic authorization via a random token, which is passed to the Apify Console,
|
|
70
|
+
// and that sends it back via the `token` query param, or `Authorization` header
|
|
71
|
+
const authToken = cryptoRandomObjectId();
|
|
72
|
+
app.use((req, res, next) => {
|
|
73
|
+
let { token: serverToken } = req.query;
|
|
74
|
+
if (!serverToken) {
|
|
75
|
+
const authorizationHeader = req.get('Authorization');
|
|
76
|
+
if (authorizationHeader) {
|
|
77
|
+
const [schema, tokenFromHeader, ...extra] = authorizationHeader.trim().split(/\s+/);
|
|
78
|
+
if (schema.toLowerCase() === 'bearer' && tokenFromHeader && extra.length === 0) {
|
|
79
|
+
serverToken = tokenFromHeader;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (serverToken !== authToken) {
|
|
84
|
+
res.status(401);
|
|
85
|
+
res.send('Authorization failed');
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
next();
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
const apiRouter = express.Router();
|
|
92
|
+
app.use(`/api/${API_VERSION}`, apiRouter);
|
|
93
|
+
apiRouter.post('/login-token', async (req, res) => {
|
|
94
|
+
try {
|
|
95
|
+
if (req.body.apiToken) {
|
|
96
|
+
await tryToLogin(req.body.apiToken);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
throw new Error('Request did not contain API token');
|
|
100
|
+
}
|
|
101
|
+
res.end();
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
const errorMessage = `Login to Apify failed with error: ${err.message}`;
|
|
105
|
+
error(errorMessage);
|
|
106
|
+
res.status(500);
|
|
107
|
+
res.send(errorMessage);
|
|
108
|
+
}
|
|
109
|
+
server.close();
|
|
110
|
+
});
|
|
111
|
+
apiRouter.post('/exit', (req, res) => {
|
|
112
|
+
if (req.body.isWindowClosed) {
|
|
113
|
+
error('Login to Apify failed, the console window was closed.');
|
|
114
|
+
}
|
|
115
|
+
else if (req.body.actionCanceled) {
|
|
116
|
+
error('Login to Apify failed, the action was canceled in the Apify Console.');
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
error('Login to Apify failed.');
|
|
120
|
+
}
|
|
121
|
+
res.end();
|
|
122
|
+
server.close();
|
|
123
|
+
});
|
|
124
|
+
// Listening on port 0 will assign a random available port
|
|
125
|
+
server = app.listen(0);
|
|
126
|
+
const { port } = server.address();
|
|
127
|
+
const consoleUrl = new URL(CONSOLE_BASE_URL);
|
|
128
|
+
consoleUrl.searchParams.set('localCliCommand', 'login');
|
|
129
|
+
consoleUrl.searchParams.set('localCliPort', `${port}`);
|
|
130
|
+
consoleUrl.searchParams.set('localCliToken', authToken);
|
|
131
|
+
consoleUrl.searchParams.set('localCliApiVersion', API_VERSION);
|
|
132
|
+
try {
|
|
133
|
+
consoleUrl.searchParams.set('localCliComputerName', encodeURIComponent(computerName()));
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
// Ignore errors from fetching computer name as it's not critical
|
|
137
|
+
}
|
|
138
|
+
info(`Opening Apify Console at "${consoleUrl.href}"...`);
|
|
139
|
+
await open(consoleUrl.href);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
11
142
|
console.log('Enter your Apify API token. You can find it at https://console.apify.com/account#/integrations');
|
|
12
|
-
const
|
|
13
|
-
(
|
|
143
|
+
const tokenAnswer = await inquirer.prompt([{ name: 'token', message: 'token:', type: 'password' }]);
|
|
144
|
+
await tryToLogin(tokenAnswer.token);
|
|
14
145
|
}
|
|
15
|
-
const isUserLogged = await getLoggedClient(token);
|
|
16
|
-
const userInfo = await getLocalUserInfo();
|
|
17
|
-
await useApifyIdentity(userInfo.id);
|
|
18
|
-
return isUserLogged
|
|
19
|
-
? success(`You are logged in to Apify as ${userInfo.username || userInfo.id}!`)
|
|
20
|
-
: error('Login to Apify failed, the provided API token is not valid.');
|
|
21
146
|
}
|
|
22
147
|
}
|
|
23
148
|
Object.defineProperty(LoginCommand, "description", {
|
|
24
149
|
enumerable: true,
|
|
25
150
|
configurable: true,
|
|
26
151
|
writable: true,
|
|
27
|
-
value: 'Logs in to your Apify account
|
|
152
|
+
value: 'Logs in to your Apify account.\nThe API token and other account '
|
|
28
153
|
+ 'information is stored in the ~/.apify directory, from where it is read by all other "apify" commands. '
|
|
29
154
|
+ 'To log out, call "apify logout".'
|
|
30
155
|
});
|
|
@@ -38,6 +163,12 @@ Object.defineProperty(LoginCommand, "flags", {
|
|
|
38
163
|
description: '[Optional] Apify API token',
|
|
39
164
|
required: false,
|
|
40
165
|
}),
|
|
166
|
+
method: Flags.string({
|
|
167
|
+
char: 'm',
|
|
168
|
+
description: '[Optional] Method of logging in to Apify',
|
|
169
|
+
options: ['console', 'manual'],
|
|
170
|
+
required: false,
|
|
171
|
+
}),
|
|
41
172
|
}
|
|
42
173
|
});
|
|
43
174
|
//# sourceMappingURL=login.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login.js","sourceRoot":"","sources":["../../src/commands/login.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"login.js","sourceRoot":"","sources":["../../src/commands/login.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,YAAY,MAAM,eAAe,CAAC;AACzC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEpE,MAAM,gBAAgB,GAAG,oDAAoD,CAAC;AAC9E,6EAA6E;AAC7E,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,gBAAgB,CAAC,CAAC,MAAM,CAAC;AAE5D,MAAM,YAAY,GAAG,gBAAgB,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,SAAS,CAAC;AAElG,qGAAqG;AACrG,MAAM,WAAW,GAAG,IAAI,CAAC;AAEzB,MAAM,UAAU,GAAG,KAAK,EAAE,KAAa,EAAE,EAAE;IACvC,MAAM,YAAY,GAAG,MAAM,eAAe,C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AAC;QACxC,CAAC;IACL,CAAC;;AA9Ie;;;;WAAc,kEAAkE;UAC9F,wGAAwG;UACxG,kCAAkC;GAAC;AAErB;;;;WAAQ;QACpB,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC;YAChB,IAAI,EAAE,GAAG;YACT,WAAW,EAAE,4BAA4B;YACzC,QAAQ,EAAE,KAAK;SAClB,CAAC;QACF,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC;YACjB,IAAI,EAAE,GAAG;YACT,WAAW,EAAE,0CAA0C;YACvD,OAAO,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC;YAC9B,QAAQ,EAAE,KAAK;SAClB,CAAC;KACL;GAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"push.d.ts","sourceRoot":"","sources":["../../src/commands/push.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AA6BvD,qBAAa,WAAY,SAAQ,YAAY,CAAC,OAAO,WAAW,CAAC;IAC7D,OAAgB,WAAW,SAI4H;IAEvJ,OAAgB,KAAK;;;;;;;MAgCnB;IAEF,OAAgB,IAAI;;MAMlB;IAGa,KAAK,CAAC,WAAW,EAAE,KAAK;IAIjC,GAAG;
|
|
1
|
+
{"version":3,"file":"push.d.ts","sourceRoot":"","sources":["../../src/commands/push.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AA6BvD,qBAAa,WAAY,SAAQ,YAAY,CAAC,OAAO,WAAW,CAAC;IAC7D,OAAgB,WAAW,SAI4H;IAEvJ,OAAgB,KAAK;;;;;;;MAgCnB;IAEF,OAAgB,IAAI;;MAMlB;IAGa,KAAK,CAAC,WAAW,EAAE,KAAK;IAIjC,GAAG;CA8NZ"}
|
package/dist/commands/push.js
CHANGED
|
@@ -8,7 +8,7 @@ import inquirer from 'inquirer';
|
|
|
8
8
|
import isCI from 'is-ci';
|
|
9
9
|
import open from 'open';
|
|
10
10
|
import { ApifyCommand } from '../lib/apify_command.js';
|
|
11
|
-
import { LOCAL_CONFIG_PATH, UPLOADS_STORE_NAME } from '../lib/consts.js';
|
|
11
|
+
import { CommandExitCodes, DEPRECATED_LOCAL_CONFIG_NAME, LOCAL_CONFIG_PATH, UPLOADS_STORE_NAME } from '../lib/consts.js';
|
|
12
12
|
import { sumFilesSizeInBytes } from '../lib/files.js';
|
|
13
13
|
import { error, info, link, run, success, warning } from '../lib/outputs.js';
|
|
14
14
|
import { transformEnvToEnvVars } from '../lib/secrets.js';
|
|
@@ -22,7 +22,7 @@ const DEFAULT_RUN_OPTIONS = {
|
|
|
22
22
|
const DEFAULT_ACTOR_VERSION_NUMBER = '0.0';
|
|
23
23
|
// It would be better to use `version-0.0` or similar,
|
|
24
24
|
// or even have no default tag, but the platform complains when
|
|
25
|
-
//
|
|
25
|
+
// Actor does not have a build with a `latest` tag, so until
|
|
26
26
|
// that changes, we have to add it.
|
|
27
27
|
const DEFAULT_BUILD_TAG = 'latest';
|
|
28
28
|
export class PushCommand extends ApifyCommand {
|
|
@@ -32,6 +32,31 @@ export class PushCommand extends ApifyCommand {
|
|
|
32
32
|
}
|
|
33
33
|
async run() {
|
|
34
34
|
const cwd = process.cwd();
|
|
35
|
+
// Validate there are files before rest of the logic
|
|
36
|
+
const filePathsToPush = await getActorLocalFilePaths(cwd);
|
|
37
|
+
if (!filePathsToPush.length) {
|
|
38
|
+
error('You need to call this command from a folder that has an Actor in it!');
|
|
39
|
+
process.exitCode = CommandExitCodes.NoFilesToPush;
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (
|
|
43
|
+
// Check that some of these files exist, cuz otherwise we cannot do much
|
|
44
|
+
![
|
|
45
|
+
// old apify project
|
|
46
|
+
DEPRECATED_LOCAL_CONFIG_NAME,
|
|
47
|
+
// new apify project
|
|
48
|
+
'actor.json',
|
|
49
|
+
'.actor/actor.json',
|
|
50
|
+
// The .actor folder existing in general
|
|
51
|
+
'.actor',
|
|
52
|
+
].some((filePath) => filePathsToPush.some((fp) => fp === filePath || fp.startsWith(filePath)))) {
|
|
53
|
+
error([
|
|
54
|
+
'A valid Actor could not be found in the current directory. Please make sure you are in the correct directory.',
|
|
55
|
+
'You can also turn this directory into an Actor by running `apify init`.',
|
|
56
|
+
].join('\n'));
|
|
57
|
+
process.exitCode = CommandExitCodes.NoFilesToPush;
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
35
60
|
const apifyClient = await getLoggedClientOrThrow();
|
|
36
61
|
const localConfig = await getLocalConfigOrThrow(cwd);
|
|
37
62
|
const userInfo = await getLocalUserInfo();
|
|
@@ -40,7 +65,7 @@ export class PushCommand extends ApifyCommand {
|
|
|
40
65
|
let actorId;
|
|
41
66
|
let actor;
|
|
42
67
|
let isActorCreatedNow = false;
|
|
43
|
-
// User can override
|
|
68
|
+
// User can override Actor version and build tag, attributes in localConfig will remain same.
|
|
44
69
|
const version = this.flags.version || this.flags.versionNumber || localConfig?.version || DEFAULT_ACTOR_VERSION_NUMBER;
|
|
45
70
|
let buildTag = this.flags.buildTag || localConfig.buildTag;
|
|
46
71
|
// We can't add the default build tag to everything. If a user creates a new
|
|
@@ -53,8 +78,8 @@ export class PushCommand extends ApifyCommand {
|
|
|
53
78
|
const waitForFinishMillis = Number.isNaN(this.flags.waitForFinish)
|
|
54
79
|
? undefined
|
|
55
80
|
: Number.parseInt(this.flags.waitForFinish, 10) * 1000;
|
|
56
|
-
// User can override actorId of pushing
|
|
57
|
-
// It causes that we push
|
|
81
|
+
// User can override actorId of pushing Actor.
|
|
82
|
+
// It causes that we push Actor to this id but attributes in localConfig will remain same.
|
|
58
83
|
const forceActorId = this.args.actorId;
|
|
59
84
|
if (forceActorId) {
|
|
60
85
|
actor = (await apifyClient.actor(forceActorId).get());
|
|
@@ -90,7 +115,6 @@ export class PushCommand extends ApifyCommand {
|
|
|
90
115
|
}
|
|
91
116
|
}
|
|
92
117
|
info(`Deploying Actor '${localConfig.name}' to Apify.`);
|
|
93
|
-
const filePathsToPush = await getActorLocalFilePaths(cwd);
|
|
94
118
|
const filesSize = await sumFilesSizeInBytes(filePathsToPush, cwd);
|
|
95
119
|
const actorClient = apifyClient.actor(actorId);
|
|
96
120
|
let sourceType;
|
|
@@ -133,7 +157,7 @@ Skipping push. Use --force to override.`);
|
|
|
133
157
|
tarballUrl = `${apifyClient.baseUrl}/key-value-stores/${store.id}/records/${key}?disableRedirect=true`;
|
|
134
158
|
sourceType = ACTOR_SOURCE_TYPES.TARBALL;
|
|
135
159
|
}
|
|
136
|
-
// Update
|
|
160
|
+
// Update Actor version
|
|
137
161
|
const actorCurrentVersion = await actorClient.version(version).get();
|
|
138
162
|
const envVars = localConfig.environmentVariables
|
|
139
163
|
? transformEnvToEnvVars(localConfig.environmentVariables)
|
|
@@ -158,7 +182,7 @@ Skipping push. Use --force to override.`);
|
|
|
158
182
|
});
|
|
159
183
|
run(`Created version ${version} for Actor ${actor.name}.`);
|
|
160
184
|
}
|
|
161
|
-
// Build
|
|
185
|
+
// Build Actor on Apify and wait for build to finish
|
|
162
186
|
run(`Building Actor ${actor.name}`);
|
|
163
187
|
let build = await actorClient.build(version, {
|
|
164
188
|
useCache: true,
|
|
@@ -196,13 +220,16 @@ Skipping push. Use --force to override.`);
|
|
|
196
220
|
}
|
|
197
221
|
else if (build.status === ACTOR_JOB_STATUSES.ABORTED || build.status === ACTOR_JOB_STATUSES.ABORTING) {
|
|
198
222
|
warning('Build was aborted!');
|
|
223
|
+
process.exitCode = CommandExitCodes.BuildAborted;
|
|
199
224
|
// @ts-expect-error FIX THESE TYPES 😢
|
|
200
225
|
}
|
|
201
226
|
else if (build.status === ACTOR_JOB_STATUSES.TIMED_OUT || build.status === ACTOR_JOB_STATUSES.TIMING_OUT) {
|
|
202
227
|
warning('Build timed out!');
|
|
228
|
+
process.exitCode = CommandExitCodes.BuildTimedOut;
|
|
203
229
|
}
|
|
204
230
|
else {
|
|
205
231
|
error('Build failed!');
|
|
232
|
+
process.exitCode = CommandExitCodes.BuildFailed;
|
|
206
233
|
}
|
|
207
234
|
}
|
|
208
235
|
}
|