1const generateSourceFiles = ({targetActorId, actorName, inputSchema, readme}) => {
2 const mainJs = `// This is the main Node.js source code file of your actor.
3
4 // Import Apify SDK. For more information, see https://sdk.apify.com/
5 const { Actor } = require('apify');
6
7 Actor.main(async () => {
8 // Get input of the actor (here only for demonstration purposes).
9 const input = await Actor.getInput();
10 // TODO: Transform the input properly
11 await Actor.metamorph('${targetActorId}', {...input});
12 });
13 `;
14
15 const dockerfile = `FROM apify/actor-node:16
16 COPY package*.json ./
17
18 RUN npm --quiet set progress=false \
19 && npm install --only=prod --no-optional \
20 && echo "Installed NPM packages:" \
21 && (npm list --only=prod --no-optional --all || true) \
22 && echo "Node.js version:" \
23 && node --version \
24 && echo "NPM version:" \
25 && npm --version
26
27 COPY . ./
28 `;
29
30 const packageJson = {
31 "name": actorName,
32 "version": "0.0.1",
33 "description": "This is a boilerplate of an Apify actor.",
34 "dependencies": {
35 "apify": "^3.0.1"
36 },
37 "devDependencies": {
38 "@apify/eslint-config": "^0.3.1",
39 "eslint": "^8.20.0"
40 },
41 "scripts": {
42 "start": "node main.js",
43 "lint": "./node_modules/.bin/eslint ./src --ext .js,.jsx",
44 "lint:fix": "./node_modules/.bin/eslint ./src --ext .js,.jsx --fix",
45 "test": "echo \"Error: oops, the actor has no tests yet, sad!\" && exit 1"
46 },
47 "author": "It's not you it's me",
48 "license": "ISC"
49 };
50
51 const files = [
52 {
53 name: 'main.js',
54 format: 'TEXT',
55 content: mainJs,
56 },
57 {
58 name: 'Dockerfile',
59 format: 'TEXT',
60 content: dockerfile,
61 },
62 {
63 name: 'package.json',
64 format: 'TEXT',
65 content: JSON.stringify(packageJson, null, 2),
66 },
67 {
68 name: 'INPUT_SCHEMA.json',
69 format: 'TEXT',
70 content: inputSchema,
71 },
72 {
73 name: 'README.md',
74 format: 'TEXT',
75 content: readme,
76 }
77 ];
78 return files;
79}
80
81module.exports = {
82 generateSourceFiles,
83}