Skip to content

feat(create): support apify create . or --here to scaffold in current directory#1250

Draft
DaveHanns wants to merge 1 commit into
masterfrom
create-support-here-shorthand
Draft

feat(create): support apify create . or --here to scaffold in current directory#1250
DaveHanns wants to merge 1 commit into
masterfrom
create-support-here-shorthand

Conversation

@DaveHanns

Copy link
Copy Markdown
Contributor

Summary

apify create <name> always creates a subdirectory. Agents (and humans) often
want to scaffold INTO the current directory instead — e.g. a workflow that
already mkdired and cded, an actor container, or a CI job that clones an
empty repo. Today, that requires apify create foo && mv foo/* . && rmdir foo
gymnastics.

This PR adds a first-class way to do it, either by passing . as the positional
argument or by using a new --here flag. Refs finding F32.

What changes

  • New flag --here: scaffold the Actor into the current working directory,
    no wrapper subdirectory. Actor name defaults to sanitizeActorName(basename(cwd))
    unless one is provided explicitly.
  • apify create .: passing a bare . positional is treated as --here,
    so users can rely on the familiar git init . / npm init . idiom.
  • New flag --force: allow scaffolding into a non-empty cwd (a warning is
    emitted; existing files are not removed, but template files may overwrite them).
    Without --force, a non-empty cwd is refused with a clear error that points at
    apify init for the "add scaffolding to an existing project" workflow.
  • Success message: when scaffolded into cwd, drops the cd "<actorName>"
    hint (you're already there). Git-init behavior is unchanged — the command
    still respects an existing .git in the cwd.
  • Backward-compatible: apify create <name> with a real name continues to
    create the subdirectory as before. No existing invocation changes behavior.

Two new examples entries and updated help text document the modes.

Files touched

  • src/commands/create.ts — new flag definitions, examples, and the branch in
    run() that picks between subdir mode and cwd mode.
  • src/lib/create-utils.tsformatCreateSuccessMessage gained a
    scaffoldedIntoCwd option so the "Next steps" block reads correctly in
    both modes.

Test plan

  • apify create . in an empty dir scaffolds template files at cwd,
    derives the actor name from the dir basename, no wrapper subdir created.
  • apify create --here --template js-crawlee-cheerio behaves the same.
  • apify create --here my-actor uses my-actor as the actor name
    but still scaffolds into cwd.
  • apify create . in a non-empty dir errors with a clear message
    referencing --force and apify init.
  • apify create . --force in a non-empty dir warns, then proceeds.
  • apify create foo continues to create ./foo/ (backward compat).
  • Success message omits the cd hint when scaffolded into cwd, and keeps
    it in the classic subdir mode.
  • Git init is skipped if .git already exists in cwd (existing behavior).

Notes

  • Reference: finding F32.
  • Related area: apify init (which is the "add Actor scaffolding to an
    existing project" workflow). This PR is complementary — --here/. is for
    the "template-driven scaffolding, but at cwd" case; init is for the
    "already have code, add Actor metadata" case.

…nt directory

Today `apify create <name>` always creates a subdirectory named after the
positional argument. When you want to scaffold INTO an existing empty
directory (which is common when the containing dir has already been
created by `git clone`, an agent, or a task runner), users have to run
`apify create foo && mv foo/* . && rmdir foo`, which is awkward and
error-prone.

This change adds two ways to scaffold into the current working directory:

- Pass `.` as the positional argument: `apify create .`
- Pass `--here` explicitly (name still optional):
  `apify create --here --template js-crawlee-cheerio`

In both cases:
- The Actor name is derived from the current directory basename (sanitized
  via `sanitizeActorName`) unless a non-`.` name is provided.
- If the current directory is not empty, the command exits with a clear
  error unless `--force` is set.
- The success message drops the `cd "<name>"` hint since you are already
  there.
- The existing "don't clobber a nested .git" behavior is preserved.

Backward-compatible: named-path invocations behave exactly as before.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants