Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@
},
"volta": {
"node": "22.19.0",
"yarn": "4.10.0"
"yarn": "4.10.3"
},
"packageManager": "[email protected].0",
"packageManager": "[email protected].3",
"devEngines": {
"runtime": [
{
Expand Down
33 changes: 32 additions & 1 deletion src/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ export class CreateCommand extends ApifyCommand<typeof CreateCommand> {
description: 'Skip installing optional dependencies.',
required: false,
}),
'skip-git-init': Flags.boolean({
description: 'Skip initializing a git repository in the Actor directory.',
required: false,
}),
};

static override args = {
Expand All @@ -68,7 +72,7 @@ export class CreateCommand extends ApifyCommand<typeof CreateCommand> {

async run() {
let { actorName } = this.args;
const { template: templateName, skipDependencyInstall } = this.flags;
const { template: templateName, skipDependencyInstall, skipGitInit } = this.flags;

// --template-archive-url is an internal, undocumented flag that's used
// for testing of templates that are not yet published in the manifest
Expand Down Expand Up @@ -308,6 +312,20 @@ export class CreateCommand extends ApifyCommand<typeof CreateCommand> {
});
}

// Initialize git repository before reporting success, but store result for later
let gitInitResult: { success: boolean; error?: Error } = { success: true };
if (!skipGitInit) {
try {
await execWithLog({
cmd: 'git',
args: ['init'],
opts: { cwd: actFolderDir },
});
} catch (err) {
gitInitResult = { success: false, error: err as Error };
}
}

if (dependenciesInstalled) {
success({ message: `Actor '${actorName}' was created. To run it, run "cd ${actorName}" and "apify run".` });
info({ message: 'To run your code in the cloud, run "apify push" and deploy your code to Apify Console.' });
Expand All @@ -319,5 +337,18 @@ export class CreateCommand extends ApifyCommand<typeof CreateCommand> {
message: `Actor '${actorName}' was created. Please install its dependencies to be able to run it using "apify run".`,
});
}

// Report git initialization result after actor creation success
if (!skipGitInit) {
if (gitInitResult.success) {
info({
message: `Git repository initialized in '${actorName}'. You can now commit and push your Actor to Git.`,
});
} else {
// Git init is not critical, so we just warn if it fails
warning({ message: `Failed to initialize git repository: ${gitInitResult.error!.message}` });
warning({ message: 'You can manually run "git init" in the Actor directory if needed.' });
}
}
}
}
32 changes: 32 additions & 0 deletions test/local/commands/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,36 @@ describe('apify create', () => {
expect(existsSync(joinPath('node_modules', 'cheerio'))).toBeTruthy();
expect(existsSync(joinPath('node_modules', 'playwright'))).toBeFalsy();
});

it('should initialize git repository by default', async () => {
const ACT_TEMPLATE = 'project_empty';

await testRunCommand(CreateCommand, {
args_actorName: actName,
flags_template: ACT_TEMPLATE,
flags_skipDependencyInstall: true,
});

toggleCwdBetweenFullAndParentPath();

// Check that .git directory exists
expect(existsSync(joinPath('.git'))).toBeTruthy();
expect(existsSync(joinPath('.git', 'config'))).toBeTruthy();
});

it('should skip git initialization when --skip-git-init flag is used', async () => {
const ACT_TEMPLATE = 'project_empty';

await testRunCommand(CreateCommand, {
args_actorName: actName,
flags_template: ACT_TEMPLATE,
flags_skipDependencyInstall: true,
flags_skipGitInit: true,
});

toggleCwdBetweenFullAndParentPath();

// Check that .git directory does not exist
expect(existsSync(joinPath('.git'))).toBeFalsy();
});
});
Loading