Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
40 changes: 40 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Tests

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup Deno
uses: denoland/setup-deno@v2
with:
deno-version: v2.x

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 22

- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- name: Configure Git
run: |
git config --global user.email "you@example.com"
git config --global user.name "Your Name"

- name: Build
run: deno task build

- name: Run Tests
run: deno test -A tests/
55 changes: 55 additions & 0 deletions PLAN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Refactoring Plan: setup-sda

The goal is to transform the monolithic `setup-sda.mjs` into a modular,
testable, and maintainable TypeScript project while preserving its
"zero-install" capability for `npx`, `deno run`, and `bunx`.

## Phase 1: Baseline Integration Testing (CRITICAL)
Establish a "green" state by verifying the current CLI behavior across all major
runtimes.

- [x] **`tests/helpers.ts`**: Define `runCLI` and assertion logic.
- [x] **Modular Test Suites (Running on Deno, Node, Bun)**:
- [x] `tests/base_test.ts`: Base setup, `--git`, `--env`, `--scrape`.
- [x] `tests/agents_test.ts`: `--claude`, `--gemini`, `--copilot`.
- [x] `tests/svelte_test.ts`: `--svelte`, `--pages`, `--example` combinations.
- [x] `tests/combinations_test.ts`: "Kitchen sink" and edge-case flag
combinations.
- [x] **Refinement**: Implement a lightweight verification mode in tests that
skips heavy installations (if possible) while still checking file
generation.

## Phase 2: Project Infrastructure & Build Pipeline
Set up the modern TypeScript structure and automated bundling.

- [x] **Directories**: Create `src/main.ts`, `src/helpers/`, `src/templates/`,
`src/actions/`.
- [x] **Bundling Config**:
- [x] Add `build` task to `deno.json`: `deno bundle src/main.ts -o setup-sda.mjs`.
- [x] Create `scripts/build.ts` to wrap `deno bundle` and prepend the
`#!/usr/bin/env node` shebang.
- [x] **Module Discovery**: Ensure all runtime-specific modules are correctly
imported and bundled.

## Phase 3: Template Extraction & New Features
Move large template strings into dedicated files and add the new feature.

- [x] **CSS Templates**: `src/templates/css.ts` (style, highlight-theme).
- [x] **Svelte Templates**: `src/templates/svelte.ts` (components, pages,
layouts).
- [x] **Config Templates**: `src/templates/configs.ts` (vite, tsconfig,
deno/package.json).
- [x] **New Feature**: Add `--agent` flag support to generate `AGENTS.md`.
- [x] **Validation**: Run modular integration tests against a bundled version
containing extracted templates and the new `--agent` flag.

## Phase 4: Logic Modularization & Final Polish
Break down the core logic into testable units.

- [x] **Action Modules**: `src/actions/` (git, env, scrape, agents, svelte).
- [x] **Refinement**: Move core setup logic into standalone functions in
`src/actions/`.
- [x] **Cross-Runtime Check**: Final test run on Deno, Node, and Bun.
- [x] **Zero-Install Verification**: Simulate remote execution (`npx`,
`deno run -A ./...`).
- [x] **Cleanup**: Remove legacy monolith and temporary build artifacts.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ bunx --bun setup-sda

Here are the different options:

- `--claude` or `--gemini` or `--copilot`: Adds a `CLAUDE.md` or `GEMINI.md` or
`.github/copilot-instructions.md` file and extra documentation in `./docs` to
work efficiently with AI agents.
- `--claude` or `--gemini` or `--copilot` or `--agent`: Adds a `CLAUDE.md` or
`GEMINI.md` or `.github/copilot-instructions.md` or `AGENTS.md` file and extra
documentation in `./docs` to work efficiently with AI agents.
- `--example`: Adds example files.
- `--scrape`: Adds web scraping dependencies.
- `--svelte`: Adds a Svelte project.
Expand Down
1 change: 1 addition & 0 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.14.15",
"exports": "./setup-sda.mjs",
"tasks": {
"build": "deno run -A scripts/build.ts",
"patch": "deno run -A incrementVersion.js patch && npm publish",
"minor": "deno run -A incrementVersion.js minor && npm publish",
"major": "deno run -A incrementVersion.js major && npm publish"
Expand Down
37 changes: 36 additions & 1 deletion deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions scripts/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const bundleCommand = new Deno.Command("deno", {
args: ["bundle", "src/main.ts", "-o", "setup-sda.mjs"],
});

const { success, stderr } = await bundleCommand.output();

if (!success) {
console.error(new TextDecoder().decode(stderr));
Deno.exit(1);
}

const content = await Deno.readTextFile("setup-sda.mjs");
await Deno.writeTextFile("setup-sda.mjs", `#!/usr/bin/env node

${content}`);

const chmodCommand = new Deno.Command("chmod", {
args: ["+x", "setup-sda.mjs"],
});
await chmodCommand.output();

console.log("Build complete!");
Loading