Compare commits
7 Commits
fix/update
...
feat/make.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8c91520356 | ||
|
|
54f50a4dc8 | ||
|
|
122a0465d8 | ||
|
|
cf2c06697a | ||
|
|
727f1ec4eb | ||
|
|
648353794e | ||
|
|
a2a3229fd0 |
5
.changeset/icy-dryers-hunt.md
Normal file
5
.changeset/icy-dryers-hunt.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"task-master-ai": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Call rules interactive setup during init
|
||||||
5
.changeset/nasty-berries-tan.md
Normal file
5
.changeset/nasty-berries-tan.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"task-master-ai": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix issues with task creation/update where subtasks are being created like id: <parent_task>.<subtask> instead if just id: <subtask>
|
||||||
10
.changeset/petite-friends-arrive.md
Normal file
10
.changeset/petite-friends-arrive.md
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
"task-master-ai": minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Make task-master more compatible with the "o" family models of OpenAI
|
||||||
|
|
||||||
|
Now works well with:
|
||||||
|
- o3
|
||||||
|
- o3-mini
|
||||||
|
- etc.
|
||||||
23
.changeset/pre.json
Normal file
23
.changeset/pre.json
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"mode": "exit",
|
||||||
|
"tag": "rc",
|
||||||
|
"initialVersions": {
|
||||||
|
"task-master-ai": "0.17.1"
|
||||||
|
},
|
||||||
|
"changesets": [
|
||||||
|
"bright-llamas-enter",
|
||||||
|
"huge-moose-prove",
|
||||||
|
"icy-dryers-hunt",
|
||||||
|
"lemon-deer-hide",
|
||||||
|
"modern-cats-pick",
|
||||||
|
"nasty-berries-tan",
|
||||||
|
"shy-groups-fly",
|
||||||
|
"sour-lions-check",
|
||||||
|
"spicy-teams-travel",
|
||||||
|
"stale-cameras-sin",
|
||||||
|
"swift-squids-sip",
|
||||||
|
"tiny-dogs-change",
|
||||||
|
"vast-plants-exist",
|
||||||
|
"wet-berries-dress"
|
||||||
|
]
|
||||||
|
}
|
||||||
5
.changeset/sour-lions-check.md
Normal file
5
.changeset/sour-lions-check.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"task-master-ai": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Store tasks in Git by default
|
||||||
22
.changeset/vast-plants-exist.md
Normal file
22
.changeset/vast-plants-exist.md
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
---
|
||||||
|
"task-master-ai": minor
|
||||||
|
---
|
||||||
|
|
||||||
|
- **Git Worktree Detection:**
|
||||||
|
- Now properly skips Git initialization when inside existing Git worktree
|
||||||
|
- Prevents accidental nested repository creation
|
||||||
|
- **Flag System Overhaul:**
|
||||||
|
- `--git`/`--no-git` controls repository initialization
|
||||||
|
- `--aliases`/`--no-aliases` consistently manages shell alias creation
|
||||||
|
- `--git-tasks`/`--no-git-tasks` controls whether task files are stored in Git
|
||||||
|
- `--dry-run` accurately previews all initialization behaviors
|
||||||
|
- **GitTasks Functionality:**
|
||||||
|
- New `--git-tasks` flag includes task files in Git (comments them out in .gitignore)
|
||||||
|
- New `--no-git-tasks` flag excludes task files from Git (default behavior)
|
||||||
|
- Supports both CLI and MCP interfaces with proper parameter passing
|
||||||
|
|
||||||
|
**Implementation Details:**
|
||||||
|
- Added explicit Git worktree detection before initialization
|
||||||
|
- Refactored flag processing to ensure consistent behavior
|
||||||
|
|
||||||
|
- Fixes #734
|
||||||
@@ -26,6 +26,7 @@ This document provides a detailed reference for interacting with Taskmaster, cov
|
|||||||
* `--name <name>`: `Set the name for your project in Taskmaster's configuration.`
|
* `--name <name>`: `Set the name for your project in Taskmaster's configuration.`
|
||||||
* `--description <text>`: `Provide a brief description for your project.`
|
* `--description <text>`: `Provide a brief description for your project.`
|
||||||
* `--version <version>`: `Set the initial version for your project, e.g., '0.1.0'.`
|
* `--version <version>`: `Set the initial version for your project, e.g., '0.1.0'.`
|
||||||
|
* `--no-git`: `Skip initializing a Git repository entirely.`
|
||||||
* `-y, --yes`: `Initialize Taskmaster quickly using default settings without interactive prompts.`
|
* `-y, --yes`: `Initialize Taskmaster quickly using default settings without interactive prompts.`
|
||||||
* **Usage:** Run this once at the beginning of a new project.
|
* **Usage:** Run this once at the beginning of a new project.
|
||||||
* **MCP Variant Description:** `Set up the basic Taskmaster file structure and configuration in the current directory for a new project by running the 'task-master init' command.`
|
* **MCP Variant Description:** `Set up the basic Taskmaster file structure and configuration in the current directory for a new project by running the 'task-master init' command.`
|
||||||
@@ -36,6 +37,7 @@ This document provides a detailed reference for interacting with Taskmaster, cov
|
|||||||
* `authorName`: `Author name.` (CLI: `--author <author>`)
|
* `authorName`: `Author name.` (CLI: `--author <author>`)
|
||||||
* `skipInstall`: `Skip installing dependencies. Default is false.` (CLI: `--skip-install`)
|
* `skipInstall`: `Skip installing dependencies. Default is false.` (CLI: `--skip-install`)
|
||||||
* `addAliases`: `Add shell aliases tm and taskmaster. Default is false.` (CLI: `--aliases`)
|
* `addAliases`: `Add shell aliases tm and taskmaster. Default is false.` (CLI: `--aliases`)
|
||||||
|
* `noGit`: `Skip initializing a Git repository entirely. Default is false.` (CLI: `--no-git`)
|
||||||
* `yes`: `Skip prompts and use defaults/provided arguments. Default is false.` (CLI: `-y, --yes`)
|
* `yes`: `Skip prompts and use defaults/provided arguments. Default is false.` (CLI: `-y, --yes`)
|
||||||
* **Usage:** Run this once at the beginning of a new project, typically via an integrated tool like Cursor. Operates on the current working directory of the MCP server.
|
* **Usage:** Run this once at the beginning of a new project, typically via an integrated tool like Cursor. Operates on the current working directory of the MCP server.
|
||||||
* **Important:** Once complete, you *MUST* parse a prd in order to generate tasks. There will be no tasks files until then. The next step after initializing should be to create a PRD using the example PRD in .taskmaster/templates/example_prd.txt.
|
* **Important:** Once complete, you *MUST* parse a prd in order to generate tasks. There will be no tasks files until then. The next step after initializing should be to create a PRD using the example PRD in .taskmaster/templates/example_prd.txt.
|
||||||
|
|||||||
98
CHANGELOG.md
98
CHANGELOG.md
@@ -1,5 +1,103 @@
|
|||||||
# task-master-ai
|
# task-master-ai
|
||||||
|
|
||||||
|
## 0.18.0-rc.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- [#830](https://github.com/eyaltoledano/claude-task-master/pull/830) [`e9d1bc2`](https://github.com/eyaltoledano/claude-task-master/commit/e9d1bc2385521c08374a85eba7899e878a51066c) Thanks [@Crunchyman-ralph](https://github.com/Crunchyman-ralph)! - Can now configure baseURL of provider with `<PROVIDER>_BASE_URL`
|
||||||
|
|
||||||
|
- For example:
|
||||||
|
- `OPENAI_BASE_URL`
|
||||||
|
|
||||||
|
- [#460](https://github.com/eyaltoledano/claude-task-master/pull/460) [`a09a2d0`](https://github.com/eyaltoledano/claude-task-master/commit/a09a2d0967a10276623e3f3ead3ed577c15ce62f) Thanks [@joedanz](https://github.com/joedanz)! - Added comprehensive rule profile management:
|
||||||
|
|
||||||
|
**New Profile Support**: Added comprehensive IDE profile support with eight specialized profiles: Claude Code, Cline, Codex, Cursor, Roo, Trae, VS Code, and Windsurf. Each profile is optimized for its respective IDE with appropriate mappings and configuration.
|
||||||
|
**Initialization**: You can now specify which rule profiles to include at project initialization using `--rules <profiles>` or `-r <profiles>` (e.g., `task-master init -r cursor,roo`). Only the selected profiles and configuration are included.
|
||||||
|
**Add/Remove Commands**: `task-master rules add <profiles>` and `task-master rules remove <profiles>` let you manage specific rule profiles and MCP config after initialization, supporting multiple profiles at once.
|
||||||
|
**Interactive Setup**: `task-master rules setup` launches an interactive prompt to select which rule profiles to add to your project. This does **not** re-initialize your project or affect shell aliases; it only manages rules.
|
||||||
|
**Selective Removal**: Rules removal intelligently preserves existing non-Task Master rules and files and only removes Task Master-specific rules. Profile directories are only removed when completely empty and all conditions are met (no existing rules, no other files/folders, MCP config completely removed).
|
||||||
|
**Safety Features**: Confirmation messages clearly explain that only Task Master-specific rules and MCP configurations will be removed, while preserving existing custom rules and other files.
|
||||||
|
**Robust Validation**: Includes comprehensive checks for array types in MCP config processing and error handling throughout the rules management system.
|
||||||
|
|
||||||
|
This enables more flexible, rule-specific project setups with intelligent cleanup that preserves user customizations while safely managing Task Master components.
|
||||||
|
|
||||||
|
- Resolves #338
|
||||||
|
|
||||||
|
- [#804](https://github.com/eyaltoledano/claude-task-master/pull/804) [`1b8c320`](https://github.com/eyaltoledano/claude-task-master/commit/1b8c320c570473082f1eb4bf9628bff66e799092) Thanks [@ejones40](https://github.com/ejones40)! - Add better support for python projects by adding `pyproject.toml` as a projectRoot marker
|
||||||
|
|
||||||
|
- [#743](https://github.com/eyaltoledano/claude-task-master/pull/743) [`a2a3229`](https://github.com/eyaltoledano/claude-task-master/commit/a2a3229fd01e24a5838f11a3938a77250101e184) Thanks [@joedanz](https://github.com/joedanz)! - - **Git Worktree Detection:**
|
||||||
|
|
||||||
|
- Now properly skips Git initialization when inside existing Git worktree
|
||||||
|
- Prevents accidental nested repository creation
|
||||||
|
- **Flag System Overhaul:**
|
||||||
|
- `--git`/`--no-git` controls repository initialization
|
||||||
|
- `--aliases`/`--no-aliases` consistently manages shell alias creation
|
||||||
|
- `--git-tasks`/`--no-git-tasks` controls whether task files are stored in Git
|
||||||
|
- `--dry-run` accurately previews all initialization behaviors
|
||||||
|
- **GitTasks Functionality:**
|
||||||
|
- New `--git-tasks` flag includes task files in Git (comments them out in .gitignore)
|
||||||
|
- New `--no-git-tasks` flag excludes task files from Git (default behavior)
|
||||||
|
- Supports both CLI and MCP interfaces with proper parameter passing
|
||||||
|
|
||||||
|
**Implementation Details:**
|
||||||
|
|
||||||
|
- Added explicit Git worktree detection before initialization
|
||||||
|
- Refactored flag processing to ensure consistent behavior
|
||||||
|
- Fixes #734
|
||||||
|
|
||||||
|
- [#829](https://github.com/eyaltoledano/claude-task-master/pull/829) [`4b0c9d9`](https://github.com/eyaltoledano/claude-task-master/commit/4b0c9d9af62d00359fca3f43283cf33223d410bc) Thanks [@Crunchyman-ralph](https://github.com/Crunchyman-ralph)! - Add Claude Code provider support
|
||||||
|
|
||||||
|
Introduces a new provider that enables using Claude models (Opus and Sonnet) through the Claude Code CLI without requiring an API key.
|
||||||
|
|
||||||
|
Key features:
|
||||||
|
|
||||||
|
- New claude-code provider with support for opus and sonnet models
|
||||||
|
- No API key required - uses local Claude Code CLI installation
|
||||||
|
- Optional dependency - won't affect users who don't need Claude Code
|
||||||
|
- Lazy loading ensures the provider only loads when requested
|
||||||
|
- Full integration with existing Task Master commands and workflows
|
||||||
|
- Comprehensive test coverage for reliability
|
||||||
|
- New --claude-code flag for the models command
|
||||||
|
|
||||||
|
Users can now configure Claude Code models with:
|
||||||
|
task-master models --set-main sonnet --claude-code
|
||||||
|
task-master models --set-research opus --claude-code
|
||||||
|
|
||||||
|
The @anthropic-ai/claude-code package is optional and won't be installed unless explicitly needed.
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#827](https://github.com/eyaltoledano/claude-task-master/pull/827) [`5da5b59`](https://github.com/eyaltoledano/claude-task-master/commit/5da5b59bdeeb634dcb3adc7a9bc0fc37e004fa0c) Thanks [@Crunchyman-ralph](https://github.com/Crunchyman-ralph)! - Fix expand command preserving tagged task structure and preventing data corruption
|
||||||
|
|
||||||
|
- Enhance E2E tests with comprehensive tag-aware expand testing to verify tag corruption fix
|
||||||
|
- Add new test section for feature-expand tag creation and testing during expand operations
|
||||||
|
- Verify tag preservation during expand, force expand, and expand --all operations
|
||||||
|
- Test that master tag remains intact while feature-expand tag receives subtasks correctly
|
||||||
|
- Fix file path references to use correct .taskmaster/config.json and .taskmaster/tasks/tasks.json locations
|
||||||
|
- All tag corruption verification tests pass successfully, confirming the expand command tag corruption bug fix works as expected
|
||||||
|
|
||||||
|
- [#833](https://github.com/eyaltoledano/claude-task-master/pull/833) [`cf2c066`](https://github.com/eyaltoledano/claude-task-master/commit/cf2c06697a0b5b952fb6ca4b3c923e9892604d08) Thanks [@joedanz](https://github.com/joedanz)! - Call rules interactive setup during init
|
||||||
|
|
||||||
|
- [#826](https://github.com/eyaltoledano/claude-task-master/pull/826) [`7811227`](https://github.com/eyaltoledano/claude-task-master/commit/78112277b3caa4539e6e29805341a944799fb0e7) Thanks [@Crunchyman-ralph](https://github.com/Crunchyman-ralph)! - Improves Amazon Bedrock support
|
||||||
|
|
||||||
|
- [#834](https://github.com/eyaltoledano/claude-task-master/pull/834) [`6483537`](https://github.com/eyaltoledano/claude-task-master/commit/648353794eb60d11ffceda87370a321ad310fbd7) Thanks [@Crunchyman-ralph](https://github.com/Crunchyman-ralph)! - Fix issues with task creation/update where subtasks are being created like id: <parent_task>.<subtask> instead if just id: <subtask>
|
||||||
|
|
||||||
|
- [#835](https://github.com/eyaltoledano/claude-task-master/pull/835) [`727f1ec`](https://github.com/eyaltoledano/claude-task-master/commit/727f1ec4ebcbdd82547784c4c113b666af7e122e) Thanks [@joedanz](https://github.com/joedanz)! - Store tasks in Git by default
|
||||||
|
|
||||||
|
- [#822](https://github.com/eyaltoledano/claude-task-master/pull/822) [`1bd6d4f`](https://github.com/eyaltoledano/claude-task-master/commit/1bd6d4f2468070690e152e6e63e15a57bc550d90) Thanks [@Crunchyman-ralph](https://github.com/Crunchyman-ralph)! - Improve provider validation system with clean constants structure
|
||||||
|
|
||||||
|
- **Fixed "Invalid provider hint" errors**: Resolved validation failures for Azure, Vertex, and Bedrock providers
|
||||||
|
- **Improved search UX**: Integrated search for better model discovery with real-time filtering
|
||||||
|
- **Better organization**: Moved custom provider options to bottom of model selection with clear section separators
|
||||||
|
|
||||||
|
This change ensures all custom providers (Azure, Vertex, Bedrock, OpenRouter, Ollama) work correctly in `task-master models --setup`
|
||||||
|
|
||||||
|
- [#633](https://github.com/eyaltoledano/claude-task-master/pull/633) [`3a2325a`](https://github.com/eyaltoledano/claude-task-master/commit/3a2325a963fed82377ab52546eedcbfebf507a7e) Thanks [@nmarley](https://github.com/nmarley)! - Fix weird `task-master init` bug when using in certain environments
|
||||||
|
|
||||||
|
- [#831](https://github.com/eyaltoledano/claude-task-master/pull/831) [`b592dff`](https://github.com/eyaltoledano/claude-task-master/commit/b592dff8bc5c5d7966843fceaa0adf4570934336) Thanks [@joedanz](https://github.com/joedanz)! - Rename Roo Code Boomerang role to Orchestrator
|
||||||
|
|
||||||
|
- [#830](https://github.com/eyaltoledano/claude-task-master/pull/830) [`e9d1bc2`](https://github.com/eyaltoledano/claude-task-master/commit/e9d1bc2385521c08374a85eba7899e878a51066c) Thanks [@Crunchyman-ralph](https://github.com/Crunchyman-ralph)! - Improve mcp keys check in cursor
|
||||||
|
|
||||||
## 0.17.1
|
## 0.17.1
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
".changeset",
|
".changeset",
|
||||||
"tasks",
|
"tasks",
|
||||||
"package-lock.json",
|
"package-lock.json",
|
||||||
"tests/fixture/*.json"
|
"tests/fixture/*.json",
|
||||||
|
"dist"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"formatter": {
|
"formatter": {
|
||||||
|
|||||||
5
index.js
5
index.js
@@ -83,6 +83,11 @@ if (import.meta.url === `file://${process.argv[1]}`) {
|
|||||||
.option('--skip-install', 'Skip installing dependencies')
|
.option('--skip-install', 'Skip installing dependencies')
|
||||||
.option('--dry-run', 'Show what would be done without making changes')
|
.option('--dry-run', 'Show what would be done without making changes')
|
||||||
.option('--aliases', 'Add shell aliases (tm, taskmaster)')
|
.option('--aliases', 'Add shell aliases (tm, taskmaster)')
|
||||||
|
.option('--no-aliases', 'Skip shell aliases (tm, taskmaster)')
|
||||||
|
.option('--git', 'Initialize Git repository')
|
||||||
|
.option('--no-git', 'Skip Git repository initialization')
|
||||||
|
.option('--git-tasks', 'Store tasks in Git')
|
||||||
|
.option('--no-git-tasks', 'No Git storage of tasks')
|
||||||
.action(async (cmdOptions) => {
|
.action(async (cmdOptions) => {
|
||||||
try {
|
try {
|
||||||
await runInitCLI(cmdOptions);
|
await runInitCLI(cmdOptions);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import { convertAllRulesToProfileRules } from '../../../../src/utils/rule-transf
|
|||||||
/**
|
/**
|
||||||
* Direct function wrapper for initializing a project.
|
* Direct function wrapper for initializing a project.
|
||||||
* Derives target directory from session, sets CWD, and calls core init logic.
|
* Derives target directory from session, sets CWD, and calls core init logic.
|
||||||
* @param {object} args - Arguments containing initialization options (addAliases, skipInstall, yes, projectRoot, rules)
|
* @param {object} args - Arguments containing initialization options (addAliases, initGit, storeTasksInGit, skipInstall, yes, projectRoot, rules)
|
||||||
* @param {object} log - The FastMCP logger instance.
|
* @param {object} log - The FastMCP logger instance.
|
||||||
* @param {object} context - The context object, must contain { session }.
|
* @param {object} context - The context object, must contain { session }.
|
||||||
* @returns {Promise<{success: boolean, data?: any, error?: {code: string, message: string}}>} - Standard result object.
|
* @returns {Promise<{success: boolean, data?: any, error?: {code: string, message: string}}>} - Standard result object.
|
||||||
@@ -65,7 +65,9 @@ export async function initializeProjectDirect(args, log, context = {}) {
|
|||||||
// Construct options ONLY from the relevant flags in args
|
// Construct options ONLY from the relevant flags in args
|
||||||
// The core initializeProject operates in the current CWD, which we just set
|
// The core initializeProject operates in the current CWD, which we just set
|
||||||
const options = {
|
const options = {
|
||||||
aliases: args.addAliases,
|
addAliases: args.addAliases,
|
||||||
|
initGit: args.initGit,
|
||||||
|
storeTasksInGit: args.storeTasksInGit,
|
||||||
skipInstall: args.skipInstall,
|
skipInstall: args.skipInstall,
|
||||||
yes: true // Force yes mode
|
yes: true // Force yes mode
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -23,8 +23,18 @@ export function registerInitializeProjectTool(server) {
|
|||||||
addAliases: z
|
addAliases: z
|
||||||
.boolean()
|
.boolean()
|
||||||
.optional()
|
.optional()
|
||||||
.default(false)
|
.default(true)
|
||||||
.describe('Add shell aliases (tm, taskmaster) to shell config file.'),
|
.describe('Add shell aliases (tm, taskmaster) to shell config file.'),
|
||||||
|
initGit: z
|
||||||
|
.boolean()
|
||||||
|
.optional()
|
||||||
|
.default(true)
|
||||||
|
.describe('Initialize Git repository in project root.'),
|
||||||
|
storeTasksInGit: z
|
||||||
|
.boolean()
|
||||||
|
.optional()
|
||||||
|
.default(true)
|
||||||
|
.describe('Store tasks in Git (tasks.json and tasks/ directory).'),
|
||||||
yes: z
|
yes: z
|
||||||
.boolean()
|
.boolean()
|
||||||
.optional()
|
.optional()
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "task-master-ai",
|
"name": "task-master-ai",
|
||||||
"version": "0.17.1",
|
"version": "0.18.0-rc.0",
|
||||||
"description": "A task management system for ambitious AI-driven development that doesn't overwhelm and confuse Cursor.",
|
"description": "A task management system for ambitious AI-driven development that doesn't overwhelm and confuse Cursor.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|||||||
294
scripts/init.js
294
scripts/init.js
@@ -23,6 +23,8 @@ import figlet from 'figlet';
|
|||||||
import boxen from 'boxen';
|
import boxen from 'boxen';
|
||||||
import gradient from 'gradient-string';
|
import gradient from 'gradient-string';
|
||||||
import { isSilentMode } from './modules/utils.js';
|
import { isSilentMode } from './modules/utils.js';
|
||||||
|
import { insideGitWorkTree } from './modules/utils/git-utils.js';
|
||||||
|
import { manageGitignoreFile } from '../src/utils/manage-gitignore.js';
|
||||||
import { RULE_PROFILES } from '../src/constants/profiles.js';
|
import { RULE_PROFILES } from '../src/constants/profiles.js';
|
||||||
import {
|
import {
|
||||||
convertAllRulesToProfileRules,
|
convertAllRulesToProfileRules,
|
||||||
@@ -320,16 +322,60 @@ async function initializeProject(options = {}) {
|
|||||||
// console.log('==================================================');
|
// console.log('==================================================');
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
// Handle boolean aliases flags
|
||||||
|
if (options.aliases === true) {
|
||||||
|
options.addAliases = true; // --aliases flag provided
|
||||||
|
} else if (options.aliases === false) {
|
||||||
|
options.addAliases = false; // --no-aliases flag provided
|
||||||
|
}
|
||||||
|
// If options.aliases and options.noAliases are undefined, we'll prompt for it
|
||||||
|
|
||||||
|
// Handle boolean git flags
|
||||||
|
if (options.git === true) {
|
||||||
|
options.initGit = true; // --git flag provided
|
||||||
|
} else if (options.git === false) {
|
||||||
|
options.initGit = false; // --no-git flag provided
|
||||||
|
}
|
||||||
|
// If options.git and options.noGit are undefined, we'll prompt for it
|
||||||
|
|
||||||
|
// Handle boolean gitTasks flags
|
||||||
|
if (options.gitTasks === true) {
|
||||||
|
options.storeTasksInGit = true; // --git-tasks flag provided
|
||||||
|
} else if (options.gitTasks === false) {
|
||||||
|
options.storeTasksInGit = false; // --no-git-tasks flag provided
|
||||||
|
}
|
||||||
|
// If options.gitTasks and options.noGitTasks are undefined, we'll prompt for it
|
||||||
|
|
||||||
const skipPrompts = options.yes || (options.name && options.description);
|
const skipPrompts = options.yes || (options.name && options.description);
|
||||||
|
|
||||||
// if (!isSilentMode()) {
|
// if (!isSilentMode()) {
|
||||||
// console.log('Skip prompts determined:', skipPrompts);
|
// console.log('Skip prompts determined:', skipPrompts);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
const selectedRuleProfiles =
|
let selectedRuleProfiles;
|
||||||
options.rules && Array.isArray(options.rules) && options.rules.length > 0
|
if (options.rulesExplicitlyProvided) {
|
||||||
? options.rules
|
// If --rules flag was used, always respect it.
|
||||||
: RULE_PROFILES; // Default to all profiles
|
log(
|
||||||
|
'info',
|
||||||
|
`Using rule profiles provided via command line: ${options.rules.join(', ')}`
|
||||||
|
);
|
||||||
|
selectedRuleProfiles = options.rules;
|
||||||
|
} else if (skipPrompts) {
|
||||||
|
// If non-interactive (e.g., --yes) and no rules specified, default to ALL.
|
||||||
|
log(
|
||||||
|
'info',
|
||||||
|
`No rules specified in non-interactive mode, defaulting to all profiles.`
|
||||||
|
);
|
||||||
|
selectedRuleProfiles = RULE_PROFILES;
|
||||||
|
} else {
|
||||||
|
// If interactive and no rules specified, default to NONE.
|
||||||
|
// The 'rules --setup' wizard will handle selection.
|
||||||
|
log(
|
||||||
|
'info',
|
||||||
|
'No rules specified; interactive setup will be launched to select profiles.'
|
||||||
|
);
|
||||||
|
selectedRuleProfiles = [];
|
||||||
|
}
|
||||||
|
|
||||||
if (skipPrompts) {
|
if (skipPrompts) {
|
||||||
if (!isSilentMode()) {
|
if (!isSilentMode()) {
|
||||||
@@ -343,21 +389,44 @@ async function initializeProject(options = {}) {
|
|||||||
const projectVersion = options.version || '0.1.0';
|
const projectVersion = options.version || '0.1.0';
|
||||||
const authorName = options.author || 'Vibe coder';
|
const authorName = options.author || 'Vibe coder';
|
||||||
const dryRun = options.dryRun || false;
|
const dryRun = options.dryRun || false;
|
||||||
const addAliases = options.aliases || false;
|
const addAliases =
|
||||||
|
options.addAliases !== undefined ? options.addAliases : true; // Default to true if not specified
|
||||||
|
const initGit = options.initGit !== undefined ? options.initGit : true; // Default to true if not specified
|
||||||
|
const storeTasksInGit =
|
||||||
|
options.storeTasksInGit !== undefined ? options.storeTasksInGit : true; // Default to true if not specified
|
||||||
|
|
||||||
if (dryRun) {
|
if (dryRun) {
|
||||||
log('info', 'DRY RUN MODE: No files will be modified');
|
log('info', 'DRY RUN MODE: No files will be modified');
|
||||||
log('info', 'Would initialize Task Master project');
|
log('info', 'Would initialize Task Master project');
|
||||||
log('info', 'Would create/update necessary project files');
|
log('info', 'Would create/update necessary project files');
|
||||||
if (addAliases) {
|
|
||||||
log('info', 'Would add shell aliases for task-master');
|
// Show flag-specific behavior
|
||||||
}
|
log(
|
||||||
|
'info',
|
||||||
|
`${addAliases ? 'Would add shell aliases (tm, taskmaster)' : 'Would skip shell aliases'}`
|
||||||
|
);
|
||||||
|
log(
|
||||||
|
'info',
|
||||||
|
`${initGit ? 'Would initialize Git repository' : 'Would skip Git initialization'}`
|
||||||
|
);
|
||||||
|
log(
|
||||||
|
'info',
|
||||||
|
`${storeTasksInGit ? 'Would store tasks in Git' : 'Would exclude tasks from Git'}`
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
dryRun: true
|
dryRun: true
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
createProjectStructure(addAliases, dryRun, options, selectedRuleProfiles);
|
createProjectStructure(
|
||||||
|
addAliases,
|
||||||
|
initGit,
|
||||||
|
storeTasksInGit,
|
||||||
|
dryRun,
|
||||||
|
options,
|
||||||
|
selectedRuleProfiles
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
// Interactive logic
|
// Interactive logic
|
||||||
log('info', 'Required options not provided, proceeding with prompts.');
|
log('info', 'Required options not provided, proceeding with prompts.');
|
||||||
@@ -367,14 +436,45 @@ async function initializeProject(options = {}) {
|
|||||||
input: process.stdin,
|
input: process.stdin,
|
||||||
output: process.stdout
|
output: process.stdout
|
||||||
});
|
});
|
||||||
// Only prompt for shell aliases
|
// Prompt for shell aliases (skip if --aliases or --no-aliases flag was provided)
|
||||||
const addAliasesInput = await promptQuestion(
|
let addAliasesPrompted = true; // Default to true
|
||||||
rl,
|
if (options.addAliases !== undefined) {
|
||||||
chalk.cyan(
|
addAliasesPrompted = options.addAliases; // Use flag value if provided
|
||||||
'Add shell aliases for task-master? This lets you type "tm" instead of "task-master" (Y/n): '
|
} else {
|
||||||
)
|
const addAliasesInput = await promptQuestion(
|
||||||
);
|
rl,
|
||||||
const addAliasesPrompted = addAliasesInput.trim().toLowerCase() !== 'n';
|
chalk.cyan(
|
||||||
|
'Add shell aliases for task-master? This lets you type "tm" instead of "task-master" (Y/n): '
|
||||||
|
)
|
||||||
|
);
|
||||||
|
addAliasesPrompted = addAliasesInput.trim().toLowerCase() !== 'n';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prompt for Git initialization (skip if --git or --no-git flag was provided)
|
||||||
|
let initGitPrompted = true; // Default to true
|
||||||
|
if (options.initGit !== undefined) {
|
||||||
|
initGitPrompted = options.initGit; // Use flag value if provided
|
||||||
|
} else {
|
||||||
|
const gitInitInput = await promptQuestion(
|
||||||
|
rl,
|
||||||
|
chalk.cyan('Initialize a Git repository in project root? (Y/n): ')
|
||||||
|
);
|
||||||
|
initGitPrompted = gitInitInput.trim().toLowerCase() !== 'n';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prompt for Git tasks storage (skip if --git-tasks or --no-git-tasks flag was provided)
|
||||||
|
let storeGitPrompted = true; // Default to true
|
||||||
|
if (options.storeTasksInGit !== undefined) {
|
||||||
|
storeGitPrompted = options.storeTasksInGit; // Use flag value if provided
|
||||||
|
} else {
|
||||||
|
const gitTasksInput = await promptQuestion(
|
||||||
|
rl,
|
||||||
|
chalk.cyan(
|
||||||
|
'Store tasks in Git (tasks.json and tasks/ directory)? (Y/n): '
|
||||||
|
)
|
||||||
|
);
|
||||||
|
storeGitPrompted = gitTasksInput.trim().toLowerCase() !== 'n';
|
||||||
|
}
|
||||||
|
|
||||||
// Confirm settings...
|
// Confirm settings...
|
||||||
console.log('\nTask Master Project settings:');
|
console.log('\nTask Master Project settings:');
|
||||||
@@ -384,6 +484,14 @@ async function initializeProject(options = {}) {
|
|||||||
),
|
),
|
||||||
chalk.white(addAliasesPrompted ? 'Yes' : 'No')
|
chalk.white(addAliasesPrompted ? 'Yes' : 'No')
|
||||||
);
|
);
|
||||||
|
console.log(
|
||||||
|
chalk.blue('Initialize Git repository in project root:'),
|
||||||
|
chalk.white(initGitPrompted ? 'Yes' : 'No')
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
chalk.blue('Store tasks in Git (tasks.json and tasks/ directory):'),
|
||||||
|
chalk.white(storeGitPrompted ? 'Yes' : 'No')
|
||||||
|
);
|
||||||
|
|
||||||
const confirmInput = await promptQuestion(
|
const confirmInput = await promptQuestion(
|
||||||
rl,
|
rl,
|
||||||
@@ -404,16 +512,6 @@ async function initializeProject(options = {}) {
|
|||||||
'info',
|
'info',
|
||||||
`Using rule profiles provided via command line: ${selectedRuleProfiles.join(', ')}`
|
`Using rule profiles provided via command line: ${selectedRuleProfiles.join(', ')}`
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
const targetDir = process.cwd();
|
|
||||||
execSync('npx task-master rules setup', {
|
|
||||||
stdio: 'inherit',
|
|
||||||
cwd: targetDir
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
log('error', 'Failed to run interactive rules setup:', error.message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const dryRun = options.dryRun || false;
|
const dryRun = options.dryRun || false;
|
||||||
@@ -422,9 +520,21 @@ async function initializeProject(options = {}) {
|
|||||||
log('info', 'DRY RUN MODE: No files will be modified');
|
log('info', 'DRY RUN MODE: No files will be modified');
|
||||||
log('info', 'Would initialize Task Master project');
|
log('info', 'Would initialize Task Master project');
|
||||||
log('info', 'Would create/update necessary project files');
|
log('info', 'Would create/update necessary project files');
|
||||||
if (addAliasesPrompted) {
|
|
||||||
log('info', 'Would add shell aliases for task-master');
|
// Show flag-specific behavior
|
||||||
}
|
log(
|
||||||
|
'info',
|
||||||
|
`${addAliasesPrompted ? 'Would add shell aliases (tm, taskmaster)' : 'Would skip shell aliases'}`
|
||||||
|
);
|
||||||
|
log(
|
||||||
|
'info',
|
||||||
|
`${initGitPrompted ? 'Would initialize Git repository' : 'Would skip Git initialization'}`
|
||||||
|
);
|
||||||
|
log(
|
||||||
|
'info',
|
||||||
|
`${storeGitPrompted ? 'Would store tasks in Git' : 'Would exclude tasks from Git'}`
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
dryRun: true
|
dryRun: true
|
||||||
};
|
};
|
||||||
@@ -433,13 +543,17 @@ async function initializeProject(options = {}) {
|
|||||||
// Create structure using only necessary values
|
// Create structure using only necessary values
|
||||||
createProjectStructure(
|
createProjectStructure(
|
||||||
addAliasesPrompted,
|
addAliasesPrompted,
|
||||||
|
initGitPrompted,
|
||||||
|
storeGitPrompted,
|
||||||
dryRun,
|
dryRun,
|
||||||
options,
|
options,
|
||||||
selectedRuleProfiles
|
selectedRuleProfiles
|
||||||
);
|
);
|
||||||
rl.close();
|
rl.close();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
rl.close();
|
if (rl) {
|
||||||
|
rl.close();
|
||||||
|
}
|
||||||
log('error', `Error during initialization process: ${error.message}`);
|
log('error', `Error during initialization process: ${error.message}`);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
@@ -458,9 +572,11 @@ function promptQuestion(rl, question) {
|
|||||||
// Function to create the project structure
|
// Function to create the project structure
|
||||||
function createProjectStructure(
|
function createProjectStructure(
|
||||||
addAliases,
|
addAliases,
|
||||||
|
initGit,
|
||||||
|
storeTasksInGit,
|
||||||
dryRun,
|
dryRun,
|
||||||
options,
|
options,
|
||||||
selectedRuleProfiles = RULE_PROFILES // Default to all rule profiles
|
selectedRuleProfiles = RULE_PROFILES
|
||||||
) {
|
) {
|
||||||
const targetDir = process.cwd();
|
const targetDir = process.cwd();
|
||||||
log('info', `Initializing project in ${targetDir}`);
|
log('info', `Initializing project in ${targetDir}`);
|
||||||
@@ -507,27 +623,67 @@ function createProjectStructure(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// Copy .gitignore
|
// Copy .gitignore with GitTasks preference
|
||||||
copyTemplateFile('gitignore', path.join(targetDir, GITIGNORE_FILE));
|
try {
|
||||||
|
const gitignoreTemplatePath = path.join(
|
||||||
|
__dirname,
|
||||||
|
'..',
|
||||||
|
'assets',
|
||||||
|
'gitignore'
|
||||||
|
);
|
||||||
|
const templateContent = fs.readFileSync(gitignoreTemplatePath, 'utf8');
|
||||||
|
manageGitignoreFile(
|
||||||
|
path.join(targetDir, GITIGNORE_FILE),
|
||||||
|
templateContent,
|
||||||
|
storeTasksInGit,
|
||||||
|
log
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
log('error', `Failed to create .gitignore: ${error.message}`);
|
||||||
|
}
|
||||||
|
|
||||||
// Copy example_prd.txt to NEW location
|
// Copy example_prd.txt to NEW location
|
||||||
copyTemplateFile('example_prd.txt', path.join(targetDir, EXAMPLE_PRD_FILE));
|
copyTemplateFile('example_prd.txt', path.join(targetDir, EXAMPLE_PRD_FILE));
|
||||||
|
|
||||||
// Initialize git repository if git is available
|
// Initialize git repository if git is available
|
||||||
try {
|
try {
|
||||||
if (!fs.existsSync(path.join(targetDir, '.git'))) {
|
if (initGit === false) {
|
||||||
log('info', 'Initializing git repository...');
|
log('info', 'Git initialization skipped due to --no-git flag.');
|
||||||
execSync('git init', { stdio: 'ignore' });
|
} else if (initGit === true) {
|
||||||
log('success', 'Git repository initialized');
|
if (insideGitWorkTree()) {
|
||||||
|
log(
|
||||||
|
'info',
|
||||||
|
'Existing Git repository detected – skipping git init despite --git flag.'
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
log('info', 'Initializing Git repository due to --git flag...');
|
||||||
|
execSync('git init', { cwd: targetDir, stdio: 'ignore' });
|
||||||
|
log('success', 'Git repository initialized');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Default behavior when no flag is provided (from interactive prompt)
|
||||||
|
if (insideGitWorkTree()) {
|
||||||
|
log('info', 'Existing Git repository detected – skipping git init.');
|
||||||
|
} else {
|
||||||
|
log(
|
||||||
|
'info',
|
||||||
|
'No Git repository detected. Initializing one in project root...'
|
||||||
|
);
|
||||||
|
execSync('git init', { cwd: targetDir, stdio: 'ignore' });
|
||||||
|
log('success', 'Git repository initialized');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log('warn', 'Git not available, skipping repository initialization');
|
log('warn', 'Git not available, skipping repository initialization');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate profile rules from assets/rules
|
// Only run the manual transformer if rules were provided via flags.
|
||||||
log('info', 'Generating profile rules from assets/rules...');
|
// The interactive `rules --setup` wizard handles its own installation.
|
||||||
for (const profileName of selectedRuleProfiles) {
|
if (options.rulesExplicitlyProvided || options.yes) {
|
||||||
_processSingleProfile(profileName);
|
log('info', 'Generating profile rules from command-line flags...');
|
||||||
|
for (const profileName of selectedRuleProfiles) {
|
||||||
|
_processSingleProfile(profileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add shell aliases if requested
|
// Add shell aliases if requested
|
||||||
@@ -558,6 +714,49 @@ function createProjectStructure(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// === Add Rule Profiles Setup Step ===
|
||||||
|
if (
|
||||||
|
!isSilentMode() &&
|
||||||
|
!dryRun &&
|
||||||
|
!options?.yes &&
|
||||||
|
!options.rulesExplicitlyProvided
|
||||||
|
) {
|
||||||
|
console.log(
|
||||||
|
boxen(chalk.cyan('Configuring Rule Profiles...'), {
|
||||||
|
padding: 0.5,
|
||||||
|
margin: { top: 1, bottom: 0.5 },
|
||||||
|
borderStyle: 'round',
|
||||||
|
borderColor: 'blue'
|
||||||
|
})
|
||||||
|
);
|
||||||
|
log(
|
||||||
|
'info',
|
||||||
|
'Running interactive rules setup. Please select which rule profiles to include.'
|
||||||
|
);
|
||||||
|
try {
|
||||||
|
// Correct command confirmed by you.
|
||||||
|
execSync('npx task-master rules --setup', {
|
||||||
|
stdio: 'inherit',
|
||||||
|
cwd: targetDir
|
||||||
|
});
|
||||||
|
log('success', 'Rule profiles configured.');
|
||||||
|
} catch (error) {
|
||||||
|
log('error', 'Failed to configure rule profiles:', error.message);
|
||||||
|
log('warn', 'You may need to run "task-master rules --setup" manually.');
|
||||||
|
}
|
||||||
|
} else if (isSilentMode() || dryRun || options?.yes) {
|
||||||
|
// This branch can log why setup was skipped, similar to the model setup logic.
|
||||||
|
if (options.rulesExplicitlyProvided) {
|
||||||
|
log(
|
||||||
|
'info',
|
||||||
|
'Skipping interactive rules setup because --rules flag was used.'
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
log('info', 'Skipping interactive rules setup in non-interactive mode.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// =====================================
|
||||||
|
|
||||||
// === Add Model Configuration Step ===
|
// === Add Model Configuration Step ===
|
||||||
if (!isSilentMode() && !dryRun && !options?.yes) {
|
if (!isSilentMode() && !dryRun && !options?.yes) {
|
||||||
console.log(
|
console.log(
|
||||||
@@ -599,6 +798,17 @@ function createProjectStructure(
|
|||||||
}
|
}
|
||||||
// ====================================
|
// ====================================
|
||||||
|
|
||||||
|
// Add shell aliases if requested
|
||||||
|
if (addAliases && !dryRun) {
|
||||||
|
log('info', 'Adding shell aliases...');
|
||||||
|
const aliasResult = addShellAliases();
|
||||||
|
if (aliasResult) {
|
||||||
|
log('success', 'Shell aliases added successfully');
|
||||||
|
}
|
||||||
|
} else if (addAliases && dryRun) {
|
||||||
|
log('info', 'DRY RUN: Would add shell aliases (tm, taskmaster)');
|
||||||
|
}
|
||||||
|
|
||||||
// Display success message
|
// Display success message
|
||||||
if (!isSilentMode()) {
|
if (!isSilentMode()) {
|
||||||
console.log(
|
console.log(
|
||||||
|
|||||||
@@ -3342,6 +3342,11 @@ ${result.result}
|
|||||||
.option('--skip-install', 'Skip installing dependencies')
|
.option('--skip-install', 'Skip installing dependencies')
|
||||||
.option('--dry-run', 'Show what would be done without making changes')
|
.option('--dry-run', 'Show what would be done without making changes')
|
||||||
.option('--aliases', 'Add shell aliases (tm, taskmaster)')
|
.option('--aliases', 'Add shell aliases (tm, taskmaster)')
|
||||||
|
.option('--no-aliases', 'Skip shell aliases (tm, taskmaster)')
|
||||||
|
.option('--git', 'Initialize Git repository')
|
||||||
|
.option('--no-git', 'Skip Git repository initialization')
|
||||||
|
.option('--git-tasks', 'Store tasks in Git')
|
||||||
|
.option('--no-git-tasks', 'No Git storage of tasks')
|
||||||
.action(async (cmdOptions) => {
|
.action(async (cmdOptions) => {
|
||||||
// cmdOptions contains parsed arguments
|
// cmdOptions contains parsed arguments
|
||||||
// Parse rules: accept space or comma separated, default to all available rules
|
// Parse rules: accept space or comma separated, default to all available rules
|
||||||
@@ -3823,7 +3828,26 @@ Examples:
|
|||||||
if (options[RULES_SETUP_ACTION]) {
|
if (options[RULES_SETUP_ACTION]) {
|
||||||
// Run interactive rules setup ONLY (no project init)
|
// Run interactive rules setup ONLY (no project init)
|
||||||
const selectedRuleProfiles = await runInteractiveProfilesSetup();
|
const selectedRuleProfiles = await runInteractiveProfilesSetup();
|
||||||
for (const profile of selectedRuleProfiles) {
|
|
||||||
|
if (!selectedRuleProfiles || selectedRuleProfiles.length === 0) {
|
||||||
|
console.log(chalk.yellow('No profiles selected. Exiting.'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
chalk.blue(
|
||||||
|
`Installing ${selectedRuleProfiles.length} selected profile(s)...`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
for (let i = 0; i < selectedRuleProfiles.length; i++) {
|
||||||
|
const profile = selectedRuleProfiles[i];
|
||||||
|
console.log(
|
||||||
|
chalk.blue(
|
||||||
|
`Processing profile ${i + 1}/${selectedRuleProfiles.length}: ${profile}...`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
if (!isValidProfile(profile)) {
|
if (!isValidProfile(profile)) {
|
||||||
console.warn(
|
console.warn(
|
||||||
`Rule profile for "${profile}" not found. Valid profiles: ${RULE_PROFILES.join(', ')}. Skipping.`
|
`Rule profile for "${profile}" not found. Valid profiles: ${RULE_PROFILES.join(', ')}. Skipping.`
|
||||||
@@ -3831,16 +3855,20 @@ Examples:
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const profileConfig = getRulesProfile(profile);
|
const profileConfig = getRulesProfile(profile);
|
||||||
|
|
||||||
const addResult = convertAllRulesToProfileRules(
|
const addResult = convertAllRulesToProfileRules(
|
||||||
projectDir,
|
projectDir,
|
||||||
profileConfig
|
profileConfig
|
||||||
);
|
);
|
||||||
if (typeof profileConfig.onAddRulesProfile === 'function') {
|
|
||||||
profileConfig.onAddRulesProfile(projectDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(chalk.green(generateProfileSummary(profile, addResult)));
|
console.log(chalk.green(generateProfileSummary(profile, addResult)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
chalk.green(
|
||||||
|
`\nCompleted installation of all ${selectedRuleProfiles.length} profile(s).`
|
||||||
|
)
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ const DEFAULTS = {
|
|||||||
// No default fallback provider/model initially
|
// No default fallback provider/model initially
|
||||||
provider: 'anthropic',
|
provider: 'anthropic',
|
||||||
modelId: 'claude-3-5-sonnet',
|
modelId: 'claude-3-5-sonnet',
|
||||||
maxTokens: 64000, // Default parameters if fallback IS configured
|
maxTokens: 8192, // Default parameters if fallback IS configured
|
||||||
temperature: 0.2
|
temperature: 0.2
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -54,7 +54,7 @@
|
|||||||
"output": 15.0
|
"output": 15.0
|
||||||
},
|
},
|
||||||
"allowed_roles": ["main", "fallback"],
|
"allowed_roles": ["main", "fallback"],
|
||||||
"max_tokens": 64000
|
"max_tokens": 8192
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"openai": [
|
"openai": [
|
||||||
@@ -84,7 +84,8 @@
|
|||||||
"input": 2.0,
|
"input": 2.0,
|
||||||
"output": 8.0
|
"output": 8.0
|
||||||
},
|
},
|
||||||
"allowed_roles": ["main", "fallback"]
|
"allowed_roles": ["main", "fallback"],
|
||||||
|
"max_tokens": 100000
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "o3-mini",
|
"id": "o3-mini",
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import {
|
|||||||
} from '../utils.js';
|
} from '../utils.js';
|
||||||
import { generateObjectService } from '../ai-services-unified.js';
|
import { generateObjectService } from '../ai-services-unified.js';
|
||||||
import { getDefaultPriority } from '../config-manager.js';
|
import { getDefaultPriority } from '../config-manager.js';
|
||||||
import generateTaskFiles from './generate-task-files.js';
|
|
||||||
import ContextGatherer from '../utils/contextGatherer.js';
|
import ContextGatherer from '../utils/contextGatherer.js';
|
||||||
|
|
||||||
// Define Zod schema for the expected AI output object
|
// Define Zod schema for the expected AI output object
|
||||||
@@ -44,7 +43,7 @@ const AiTaskDataSchema = z.object({
|
|||||||
.describe('Detailed approach for verifying task completion'),
|
.describe('Detailed approach for verifying task completion'),
|
||||||
dependencies: z
|
dependencies: z
|
||||||
.array(z.number())
|
.array(z.number())
|
||||||
.optional()
|
.nullable()
|
||||||
.describe(
|
.describe(
|
||||||
'Array of task IDs that this task depends on (must be completed before this task can start)'
|
'Array of task IDs that this task depends on (must be completed before this task can start)'
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -43,8 +43,9 @@ const subtaskSchema = z
|
|||||||
),
|
),
|
||||||
testStrategy: z
|
testStrategy: z
|
||||||
.string()
|
.string()
|
||||||
.optional()
|
.nullable()
|
||||||
.describe('Approach for testing this subtask')
|
.describe('Approach for testing this subtask')
|
||||||
|
.default('')
|
||||||
})
|
})
|
||||||
.strict();
|
.strict();
|
||||||
const subtaskArraySchema = z.array(subtaskSchema);
|
const subtaskArraySchema = z.array(subtaskSchema);
|
||||||
|
|||||||
@@ -26,11 +26,11 @@ const prdSingleTaskSchema = z.object({
|
|||||||
id: z.number().int().positive(),
|
id: z.number().int().positive(),
|
||||||
title: z.string().min(1),
|
title: z.string().min(1),
|
||||||
description: z.string().min(1),
|
description: z.string().min(1),
|
||||||
details: z.string().optional().default(''),
|
details: z.string().nullable(),
|
||||||
testStrategy: z.string().optional().default(''),
|
testStrategy: z.string().nullable(),
|
||||||
priority: z.enum(['high', 'medium', 'low']).default('medium'),
|
priority: z.enum(['high', 'medium', 'low']).nullable(),
|
||||||
dependencies: z.array(z.number().int().positive()).optional().default([]),
|
dependencies: z.array(z.number().int().positive()).nullable(),
|
||||||
status: z.string().optional().default('pending')
|
status: z.string().nullable()
|
||||||
});
|
});
|
||||||
|
|
||||||
// Define the Zod schema for the ENTIRE expected AI response object
|
// Define the Zod schema for the ENTIRE expected AI response object
|
||||||
|
|||||||
@@ -36,10 +36,27 @@ const updatedTaskSchema = z
|
|||||||
description: z.string(),
|
description: z.string(),
|
||||||
status: z.string(),
|
status: z.string(),
|
||||||
dependencies: z.array(z.union([z.number().int(), z.string()])),
|
dependencies: z.array(z.union([z.number().int(), z.string()])),
|
||||||
priority: z.string().optional(),
|
priority: z.string().nullable().default('medium'),
|
||||||
details: z.string().optional(),
|
details: z.string().nullable().default(''),
|
||||||
testStrategy: z.string().optional(),
|
testStrategy: z.string().nullable().default(''),
|
||||||
subtasks: z.array(z.any()).optional()
|
subtasks: z
|
||||||
|
.array(
|
||||||
|
z.object({
|
||||||
|
id: z
|
||||||
|
.number()
|
||||||
|
.int()
|
||||||
|
.positive()
|
||||||
|
.describe('Sequential subtask ID starting from 1'),
|
||||||
|
title: z.string(),
|
||||||
|
description: z.string(),
|
||||||
|
status: z.string(),
|
||||||
|
dependencies: z.array(z.number().int()).nullable().default([]),
|
||||||
|
details: z.string().nullable().default(''),
|
||||||
|
testStrategy: z.string().nullable().default('')
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.nullable()
|
||||||
|
.default([])
|
||||||
})
|
})
|
||||||
.strip(); // Allows parsing even if AI adds extra fields, but validation focuses on schema
|
.strip(); // Allows parsing even if AI adds extra fields, but validation focuses on schema
|
||||||
|
|
||||||
@@ -441,6 +458,8 @@ Guidelines:
|
|||||||
9. Instead, add a new subtask that clearly indicates what needs to be changed or replaced
|
9. Instead, add a new subtask that clearly indicates what needs to be changed or replaced
|
||||||
10. Use the existence of completed subtasks as an opportunity to make new subtasks more specific and targeted
|
10. Use the existence of completed subtasks as an opportunity to make new subtasks more specific and targeted
|
||||||
11. Ensure any new subtasks have unique IDs that don't conflict with existing ones
|
11. Ensure any new subtasks have unique IDs that don't conflict with existing ones
|
||||||
|
12. CRITICAL: For subtask IDs, use ONLY numeric values (1, 2, 3, etc.) NOT strings ("1", "2", "3")
|
||||||
|
13. CRITICAL: Subtask IDs should start from 1 and increment sequentially (1, 2, 3...) - do NOT use parent task ID as prefix
|
||||||
|
|
||||||
The changes described in the prompt should be thoughtfully applied to make the task more accurate and actionable.`;
|
The changes described in the prompt should be thoughtfully applied to make the task more accurate and actionable.`;
|
||||||
|
|
||||||
@@ -573,6 +592,37 @@ The changes described in the prompt should be thoughtfully applied to make the t
|
|||||||
);
|
);
|
||||||
updatedTask.status = taskToUpdate.status;
|
updatedTask.status = taskToUpdate.status;
|
||||||
}
|
}
|
||||||
|
// Fix subtask IDs if they exist (ensure they are numeric and sequential)
|
||||||
|
if (updatedTask.subtasks && Array.isArray(updatedTask.subtasks)) {
|
||||||
|
let currentSubtaskId = 1;
|
||||||
|
updatedTask.subtasks = updatedTask.subtasks.map((subtask) => {
|
||||||
|
// Fix AI-generated subtask IDs that might be strings or use parent ID as prefix
|
||||||
|
const correctedSubtask = {
|
||||||
|
...subtask,
|
||||||
|
id: currentSubtaskId, // Override AI-generated ID with correct sequential ID
|
||||||
|
dependencies: Array.isArray(subtask.dependencies)
|
||||||
|
? subtask.dependencies
|
||||||
|
.map((dep) =>
|
||||||
|
typeof dep === 'string' ? parseInt(dep, 10) : dep
|
||||||
|
)
|
||||||
|
.filter(
|
||||||
|
(depId) =>
|
||||||
|
!Number.isNaN(depId) &&
|
||||||
|
depId >= 1 &&
|
||||||
|
depId < currentSubtaskId
|
||||||
|
)
|
||||||
|
: [],
|
||||||
|
status: subtask.status || 'pending'
|
||||||
|
};
|
||||||
|
currentSubtaskId++;
|
||||||
|
return correctedSubtask;
|
||||||
|
});
|
||||||
|
report(
|
||||||
|
'info',
|
||||||
|
`Fixed ${updatedTask.subtasks.length} subtask IDs to be sequential numeric IDs.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Preserve completed subtasks (Keep existing logic)
|
// Preserve completed subtasks (Keep existing logic)
|
||||||
if (taskToUpdate.subtasks?.length > 0) {
|
if (taskToUpdate.subtasks?.length > 0) {
|
||||||
if (!updatedTask.subtasks) {
|
if (!updatedTask.subtasks) {
|
||||||
|
|||||||
@@ -35,10 +35,10 @@ const updatedTaskSchema = z
|
|||||||
description: z.string(),
|
description: z.string(),
|
||||||
status: z.string(),
|
status: z.string(),
|
||||||
dependencies: z.array(z.union([z.number().int(), z.string()])),
|
dependencies: z.array(z.union([z.number().int(), z.string()])),
|
||||||
priority: z.string().optional(),
|
priority: z.string().nullable(),
|
||||||
details: z.string().optional(),
|
details: z.string().nullable(),
|
||||||
testStrategy: z.string().optional(),
|
testStrategy: z.string().nullable(),
|
||||||
subtasks: z.array(z.any()).optional() // Keep subtasks flexible for now
|
subtasks: z.array(z.any()).nullable() // Keep subtasks flexible for now
|
||||||
})
|
})
|
||||||
.strip(); // Allow potential extra fields during parsing if needed, then validate structure
|
.strip(); // Allow potential extra fields during parsing if needed, then validate structure
|
||||||
const updatedTaskArraySchema = z.array(updatedTaskSchema);
|
const updatedTaskArraySchema = z.array(updatedTaskSchema);
|
||||||
|
|||||||
@@ -349,6 +349,25 @@ function getCurrentBranchSync(projectRoot) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the current working directory is inside a Git work-tree.
|
||||||
|
* Uses `git rev-parse --is-inside-work-tree` which is more specific than --git-dir
|
||||||
|
* for detecting work-trees (excludes bare repos and .git directories).
|
||||||
|
* This is ideal for preventing accidental git init in existing work-trees.
|
||||||
|
* @returns {boolean} True if inside a Git work-tree, false otherwise.
|
||||||
|
*/
|
||||||
|
function insideGitWorkTree() {
|
||||||
|
try {
|
||||||
|
execSync('git rev-parse --is-inside-work-tree', {
|
||||||
|
stdio: 'ignore',
|
||||||
|
cwd: process.cwd()
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Export all functions
|
// Export all functions
|
||||||
export {
|
export {
|
||||||
isGitRepository,
|
isGitRepository,
|
||||||
@@ -366,5 +385,6 @@ export {
|
|||||||
checkAndAutoSwitchGitTag,
|
checkAndAutoSwitchGitTag,
|
||||||
checkAndAutoSwitchGitTagSync,
|
checkAndAutoSwitchGitTagSync,
|
||||||
isGitRepositorySync,
|
isGitRepositorySync,
|
||||||
getCurrentBranchSync
|
getCurrentBranchSync,
|
||||||
|
insideGitWorkTree
|
||||||
};
|
};
|
||||||
|
|||||||
293
src/utils/manage-gitignore.js
Normal file
293
src/utils/manage-gitignore.js
Normal file
@@ -0,0 +1,293 @@
|
|||||||
|
// Utility to manage .gitignore files with task file preferences and template merging
|
||||||
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
|
// Constants
|
||||||
|
const TASK_FILES_COMMENT = '# Task files';
|
||||||
|
const TASK_JSON_PATTERN = 'tasks.json';
|
||||||
|
const TASK_DIR_PATTERN = 'tasks/';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalizes a line by removing comments and trimming whitespace
|
||||||
|
* @param {string} line - Line to normalize
|
||||||
|
* @returns {string} Normalized line
|
||||||
|
*/
|
||||||
|
function normalizeLine(line) {
|
||||||
|
return line.trim().replace(/^#/, '').trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a line is task-related (tasks.json or tasks/)
|
||||||
|
* @param {string} line - Line to check
|
||||||
|
* @returns {boolean} True if line is task-related
|
||||||
|
*/
|
||||||
|
function isTaskLine(line) {
|
||||||
|
const normalized = normalizeLine(line);
|
||||||
|
return normalized === TASK_JSON_PATTERN || normalized === TASK_DIR_PATTERN;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adjusts task-related lines in template based on storage preference
|
||||||
|
* @param {string[]} templateLines - Array of template lines
|
||||||
|
* @param {boolean} storeTasksInGit - Whether to comment out task lines
|
||||||
|
* @returns {string[]} Adjusted template lines
|
||||||
|
*/
|
||||||
|
function adjustTaskLinesInTemplate(templateLines, storeTasksInGit) {
|
||||||
|
return templateLines.map((line) => {
|
||||||
|
if (isTaskLine(line)) {
|
||||||
|
const normalized = normalizeLine(line);
|
||||||
|
// Preserve original trailing whitespace from the line
|
||||||
|
const originalTrailingSpace = line.match(/\s*$/)[0];
|
||||||
|
return storeTasksInGit
|
||||||
|
? `# ${normalized}${originalTrailingSpace}`
|
||||||
|
: `${normalized}${originalTrailingSpace}`;
|
||||||
|
}
|
||||||
|
return line;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes existing task files section from content
|
||||||
|
* @param {string[]} existingLines - Existing file lines
|
||||||
|
* @returns {string[]} Lines with task section removed
|
||||||
|
*/
|
||||||
|
function removeExistingTaskSection(existingLines) {
|
||||||
|
const cleanedLines = [];
|
||||||
|
let inTaskSection = false;
|
||||||
|
|
||||||
|
for (const line of existingLines) {
|
||||||
|
// Start of task files section
|
||||||
|
if (line.trim() === TASK_FILES_COMMENT) {
|
||||||
|
inTaskSection = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Task lines (commented or not)
|
||||||
|
if (isTaskLine(line)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Empty lines within task section
|
||||||
|
if (inTaskSection && !line.trim()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// End of task section (any non-empty, non-task line)
|
||||||
|
if (inTaskSection && line.trim() && !isTaskLine(line)) {
|
||||||
|
inTaskSection = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keep all other lines
|
||||||
|
if (!inTaskSection) {
|
||||||
|
cleanedLines.push(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return cleanedLines;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters template lines to only include new content not already present
|
||||||
|
* @param {string[]} templateLines - Template lines
|
||||||
|
* @param {Set<string>} existingLinesSet - Set of existing trimmed lines
|
||||||
|
* @returns {string[]} New lines to add
|
||||||
|
*/
|
||||||
|
function filterNewTemplateLines(templateLines, existingLinesSet) {
|
||||||
|
return templateLines.filter((line) => {
|
||||||
|
const trimmed = line.trim();
|
||||||
|
if (!trimmed) return false;
|
||||||
|
|
||||||
|
// Skip task-related lines (handled separately)
|
||||||
|
if (isTaskLine(line) || trimmed === TASK_FILES_COMMENT) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Include only if not already present
|
||||||
|
return !existingLinesSet.has(trimmed);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the task files section based on storage preference
|
||||||
|
* @param {boolean} storeTasksInGit - Whether to comment out task lines
|
||||||
|
* @returns {string[]} Task files section lines
|
||||||
|
*/
|
||||||
|
function buildTaskFilesSection(storeTasksInGit) {
|
||||||
|
const section = [TASK_FILES_COMMENT];
|
||||||
|
|
||||||
|
if (storeTasksInGit) {
|
||||||
|
section.push(`# ${TASK_JSON_PATTERN}`, `# ${TASK_DIR_PATTERN} `);
|
||||||
|
} else {
|
||||||
|
section.push(TASK_JSON_PATTERN, `${TASK_DIR_PATTERN} `);
|
||||||
|
}
|
||||||
|
|
||||||
|
return section;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a separator line if needed (avoids double spacing)
|
||||||
|
* @param {string[]} lines - Current lines array
|
||||||
|
*/
|
||||||
|
function addSeparatorIfNeeded(lines) {
|
||||||
|
if (lines.some((line) => line.trim())) {
|
||||||
|
const lastLine = lines[lines.length - 1];
|
||||||
|
if (lastLine && lastLine.trim()) {
|
||||||
|
lines.push('');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates input parameters
|
||||||
|
* @param {string} targetPath - Path to .gitignore file
|
||||||
|
* @param {string} content - Template content
|
||||||
|
* @param {boolean} storeTasksInGit - Storage preference
|
||||||
|
* @throws {Error} If validation fails
|
||||||
|
*/
|
||||||
|
function validateInputs(targetPath, content, storeTasksInGit) {
|
||||||
|
if (!targetPath || typeof targetPath !== 'string') {
|
||||||
|
throw new Error('targetPath must be a non-empty string');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!targetPath.endsWith('.gitignore')) {
|
||||||
|
throw new Error('targetPath must end with .gitignore');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!content || typeof content !== 'string') {
|
||||||
|
throw new Error('content must be a non-empty string');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof storeTasksInGit !== 'boolean') {
|
||||||
|
throw new Error('storeTasksInGit must be a boolean');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new .gitignore file from template
|
||||||
|
* @param {string} targetPath - Path to create file at
|
||||||
|
* @param {string[]} templateLines - Adjusted template lines
|
||||||
|
* @param {function} log - Logging function
|
||||||
|
*/
|
||||||
|
function createNewGitignoreFile(targetPath, templateLines, log) {
|
||||||
|
try {
|
||||||
|
fs.writeFileSync(targetPath, templateLines.join('\n'));
|
||||||
|
if (typeof log === 'function') {
|
||||||
|
log('success', `Created ${targetPath} with full template`);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (typeof log === 'function') {
|
||||||
|
log('error', `Failed to create ${targetPath}: ${error.message}`);
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merges template content with existing .gitignore file
|
||||||
|
* @param {string} targetPath - Path to existing file
|
||||||
|
* @param {string[]} templateLines - Adjusted template lines
|
||||||
|
* @param {boolean} storeTasksInGit - Storage preference
|
||||||
|
* @param {function} log - Logging function
|
||||||
|
*/
|
||||||
|
function mergeWithExistingFile(
|
||||||
|
targetPath,
|
||||||
|
templateLines,
|
||||||
|
storeTasksInGit,
|
||||||
|
log
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
// Read and process existing file
|
||||||
|
const existingContent = fs.readFileSync(targetPath, 'utf8');
|
||||||
|
const existingLines = existingContent.split('\n');
|
||||||
|
|
||||||
|
// Remove existing task section
|
||||||
|
const cleanedExistingLines = removeExistingTaskSection(existingLines);
|
||||||
|
|
||||||
|
// Find new template lines to add
|
||||||
|
const existingLinesSet = new Set(
|
||||||
|
cleanedExistingLines.map((line) => line.trim()).filter((line) => line)
|
||||||
|
);
|
||||||
|
const newLines = filterNewTemplateLines(templateLines, existingLinesSet);
|
||||||
|
|
||||||
|
// Build final content
|
||||||
|
const finalLines = [...cleanedExistingLines];
|
||||||
|
|
||||||
|
// Add new template content
|
||||||
|
if (newLines.length > 0) {
|
||||||
|
addSeparatorIfNeeded(finalLines);
|
||||||
|
finalLines.push(...newLines);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add task files section
|
||||||
|
addSeparatorIfNeeded(finalLines);
|
||||||
|
finalLines.push(...buildTaskFilesSection(storeTasksInGit));
|
||||||
|
|
||||||
|
// Write result
|
||||||
|
fs.writeFileSync(targetPath, finalLines.join('\n'));
|
||||||
|
|
||||||
|
if (typeof log === 'function') {
|
||||||
|
const hasNewContent =
|
||||||
|
newLines.length > 0 ? ' and merged new content' : '';
|
||||||
|
log(
|
||||||
|
'success',
|
||||||
|
`Updated ${targetPath} according to user preference${hasNewContent}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (typeof log === 'function') {
|
||||||
|
log(
|
||||||
|
'error',
|
||||||
|
`Failed to merge content with ${targetPath}: ${error.message}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manages .gitignore file creation and updates with task file preferences
|
||||||
|
* @param {string} targetPath - Path to the .gitignore file
|
||||||
|
* @param {string} content - Template content for .gitignore
|
||||||
|
* @param {boolean} storeTasksInGit - Whether to store tasks in git or not
|
||||||
|
* @param {function} log - Logging function (level, message)
|
||||||
|
* @throws {Error} If validation or file operations fail
|
||||||
|
*/
|
||||||
|
function manageGitignoreFile(
|
||||||
|
targetPath,
|
||||||
|
content,
|
||||||
|
storeTasksInGit = true,
|
||||||
|
log = null
|
||||||
|
) {
|
||||||
|
// Validate inputs
|
||||||
|
validateInputs(targetPath, content, storeTasksInGit);
|
||||||
|
|
||||||
|
// Process template with task preference
|
||||||
|
const templateLines = content.split('\n');
|
||||||
|
const adjustedTemplateLines = adjustTaskLinesInTemplate(
|
||||||
|
templateLines,
|
||||||
|
storeTasksInGit
|
||||||
|
);
|
||||||
|
|
||||||
|
// Handle file creation or merging
|
||||||
|
if (!fs.existsSync(targetPath)) {
|
||||||
|
createNewGitignoreFile(targetPath, adjustedTemplateLines, log);
|
||||||
|
} else {
|
||||||
|
mergeWithExistingFile(
|
||||||
|
targetPath,
|
||||||
|
adjustedTemplateLines,
|
||||||
|
storeTasksInGit,
|
||||||
|
log
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default manageGitignoreFile;
|
||||||
|
export {
|
||||||
|
manageGitignoreFile,
|
||||||
|
normalizeLine,
|
||||||
|
isTaskLine,
|
||||||
|
buildTaskFilesSection,
|
||||||
|
TASK_FILES_COMMENT,
|
||||||
|
TASK_JSON_PATTERN,
|
||||||
|
TASK_DIR_PATTERN
|
||||||
|
};
|
||||||
@@ -206,6 +206,7 @@ export function convertAllRulesToProfileRules(projectDir, profile) {
|
|||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
const __dirname = path.dirname(__filename);
|
const __dirname = path.dirname(__filename);
|
||||||
const assetsDir = path.join(__dirname, '..', '..', 'assets');
|
const assetsDir = path.join(__dirname, '..', '..', 'assets');
|
||||||
|
|
||||||
if (typeof profile.onPostConvertRulesProfile === 'function') {
|
if (typeof profile.onPostConvertRulesProfile === 'function') {
|
||||||
profile.onPostConvertRulesProfile(projectDir, assetsDir);
|
profile.onPostConvertRulesProfile(projectDir, assetsDir);
|
||||||
}
|
}
|
||||||
|
|||||||
581
tests/integration/manage-gitignore.test.js
Normal file
581
tests/integration/manage-gitignore.test.js
Normal file
@@ -0,0 +1,581 @@
|
|||||||
|
/**
|
||||||
|
* Integration tests for manage-gitignore.js module
|
||||||
|
* Tests actual file system operations in a temporary directory
|
||||||
|
*/
|
||||||
|
|
||||||
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
import os from 'os';
|
||||||
|
import manageGitignoreFile from '../../src/utils/manage-gitignore.js';
|
||||||
|
|
||||||
|
describe('manage-gitignore.js Integration Tests', () => {
|
||||||
|
let tempDir;
|
||||||
|
let testGitignorePath;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
// Create a temporary directory for each test
|
||||||
|
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gitignore-test-'));
|
||||||
|
testGitignorePath = path.join(tempDir, '.gitignore');
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
// Clean up temporary directory after each test
|
||||||
|
if (fs.existsSync(tempDir)) {
|
||||||
|
fs.rmSync(tempDir, { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('New File Creation', () => {
|
||||||
|
const templateContent = `# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
|
||||||
|
# Dependencies
|
||||||
|
node_modules/
|
||||||
|
jspm_packages/
|
||||||
|
|
||||||
|
# Environment variables
|
||||||
|
.env
|
||||||
|
.env.local
|
||||||
|
|
||||||
|
# Task files
|
||||||
|
tasks.json
|
||||||
|
tasks/ `;
|
||||||
|
|
||||||
|
test('should create new .gitignore file with commented task lines (storeTasksInGit = true)', () => {
|
||||||
|
const logs = [];
|
||||||
|
const mockLog = (level, message) => logs.push({ level, message });
|
||||||
|
|
||||||
|
manageGitignoreFile(testGitignorePath, templateContent, true, mockLog);
|
||||||
|
|
||||||
|
// Verify file was created
|
||||||
|
expect(fs.existsSync(testGitignorePath)).toBe(true);
|
||||||
|
|
||||||
|
// Verify content
|
||||||
|
const content = fs.readFileSync(testGitignorePath, 'utf8');
|
||||||
|
expect(content).toContain('# Logs');
|
||||||
|
expect(content).toContain('logs');
|
||||||
|
expect(content).toContain('# Dependencies');
|
||||||
|
expect(content).toContain('node_modules/');
|
||||||
|
expect(content).toContain('# Task files');
|
||||||
|
expect(content).toContain('tasks.json');
|
||||||
|
expect(content).toContain('tasks/');
|
||||||
|
|
||||||
|
// Verify task lines are commented (storeTasksInGit = true)
|
||||||
|
expect(content).toMatch(
|
||||||
|
/# Task files\s*[\r\n]+# tasks\.json\s*[\r\n]+# tasks\/ /
|
||||||
|
);
|
||||||
|
|
||||||
|
// Verify log message
|
||||||
|
expect(logs).toContainEqual({
|
||||||
|
level: 'success',
|
||||||
|
message: expect.stringContaining('Created')
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should create new .gitignore file with uncommented task lines (storeTasksInGit = false)', () => {
|
||||||
|
const logs = [];
|
||||||
|
const mockLog = (level, message) => logs.push({ level, message });
|
||||||
|
|
||||||
|
manageGitignoreFile(testGitignorePath, templateContent, false, mockLog);
|
||||||
|
|
||||||
|
// Verify file was created
|
||||||
|
expect(fs.existsSync(testGitignorePath)).toBe(true);
|
||||||
|
|
||||||
|
// Verify content
|
||||||
|
const content = fs.readFileSync(testGitignorePath, 'utf8');
|
||||||
|
expect(content).toContain('# Task files');
|
||||||
|
|
||||||
|
// Verify task lines are uncommented (storeTasksInGit = false)
|
||||||
|
expect(content).toMatch(
|
||||||
|
/# Task files\s*[\r\n]+tasks\.json\s*[\r\n]+tasks\/ /
|
||||||
|
);
|
||||||
|
|
||||||
|
// Verify log message
|
||||||
|
expect(logs).toContainEqual({
|
||||||
|
level: 'success',
|
||||||
|
message: expect.stringContaining('Created')
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should work without log function', () => {
|
||||||
|
expect(() => {
|
||||||
|
manageGitignoreFile(testGitignorePath, templateContent, false);
|
||||||
|
}).not.toThrow();
|
||||||
|
|
||||||
|
expect(fs.existsSync(testGitignorePath)).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('File Merging', () => {
|
||||||
|
const templateContent = `# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# Dependencies
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Environment variables
|
||||||
|
.env
|
||||||
|
|
||||||
|
# Task files
|
||||||
|
tasks.json
|
||||||
|
tasks/ `;
|
||||||
|
|
||||||
|
test('should merge template with existing file content', () => {
|
||||||
|
// Create existing .gitignore file
|
||||||
|
const existingContent = `# Existing content
|
||||||
|
old-files.txt
|
||||||
|
*.backup
|
||||||
|
|
||||||
|
# Old task files (to be replaced)
|
||||||
|
# Task files
|
||||||
|
# tasks.json
|
||||||
|
# tasks/
|
||||||
|
|
||||||
|
# More existing content
|
||||||
|
cache/`;
|
||||||
|
|
||||||
|
fs.writeFileSync(testGitignorePath, existingContent);
|
||||||
|
|
||||||
|
const logs = [];
|
||||||
|
const mockLog = (level, message) => logs.push({ level, message });
|
||||||
|
|
||||||
|
manageGitignoreFile(testGitignorePath, templateContent, false, mockLog);
|
||||||
|
|
||||||
|
// Verify file still exists
|
||||||
|
expect(fs.existsSync(testGitignorePath)).toBe(true);
|
||||||
|
|
||||||
|
const content = fs.readFileSync(testGitignorePath, 'utf8');
|
||||||
|
|
||||||
|
// Should retain existing non-task content
|
||||||
|
expect(content).toContain('# Existing content');
|
||||||
|
expect(content).toContain('old-files.txt');
|
||||||
|
expect(content).toContain('*.backup');
|
||||||
|
expect(content).toContain('# More existing content');
|
||||||
|
expect(content).toContain('cache/');
|
||||||
|
|
||||||
|
// Should add new template content
|
||||||
|
expect(content).toContain('# Logs');
|
||||||
|
expect(content).toContain('logs');
|
||||||
|
expect(content).toContain('# Dependencies');
|
||||||
|
expect(content).toContain('node_modules/');
|
||||||
|
expect(content).toContain('# Environment variables');
|
||||||
|
expect(content).toContain('.env');
|
||||||
|
|
||||||
|
// Should replace task section with new preference (storeTasksInGit = false means uncommented)
|
||||||
|
expect(content).toMatch(
|
||||||
|
/# Task files\s*[\r\n]+tasks\.json\s*[\r\n]+tasks\/ /
|
||||||
|
);
|
||||||
|
|
||||||
|
// Verify log message
|
||||||
|
expect(logs).toContainEqual({
|
||||||
|
level: 'success',
|
||||||
|
message: expect.stringContaining('Updated')
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should handle switching task preferences from commented to uncommented', () => {
|
||||||
|
// Create existing file with commented task lines
|
||||||
|
const existingContent = `# Existing
|
||||||
|
existing.txt
|
||||||
|
|
||||||
|
# Task files
|
||||||
|
# tasks.json
|
||||||
|
# tasks/ `;
|
||||||
|
|
||||||
|
fs.writeFileSync(testGitignorePath, existingContent);
|
||||||
|
|
||||||
|
// Update with storeTasksInGit = true (commented)
|
||||||
|
manageGitignoreFile(testGitignorePath, templateContent, true);
|
||||||
|
|
||||||
|
const content = fs.readFileSync(testGitignorePath, 'utf8');
|
||||||
|
|
||||||
|
// Should retain existing content
|
||||||
|
expect(content).toContain('# Existing');
|
||||||
|
expect(content).toContain('existing.txt');
|
||||||
|
|
||||||
|
// Should have commented task lines (storeTasksInGit = true)
|
||||||
|
expect(content).toMatch(
|
||||||
|
/# Task files\s*[\r\n]+# tasks\.json\s*[\r\n]+# tasks\/ /
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should handle switching task preferences from uncommented to commented', () => {
|
||||||
|
// Create existing file with uncommented task lines
|
||||||
|
const existingContent = `# Existing
|
||||||
|
existing.txt
|
||||||
|
|
||||||
|
# Task files
|
||||||
|
tasks.json
|
||||||
|
tasks/ `;
|
||||||
|
|
||||||
|
fs.writeFileSync(testGitignorePath, existingContent);
|
||||||
|
|
||||||
|
// Update with storeTasksInGit = false (uncommented)
|
||||||
|
manageGitignoreFile(testGitignorePath, templateContent, false);
|
||||||
|
|
||||||
|
const content = fs.readFileSync(testGitignorePath, 'utf8');
|
||||||
|
|
||||||
|
// Should retain existing content
|
||||||
|
expect(content).toContain('# Existing');
|
||||||
|
expect(content).toContain('existing.txt');
|
||||||
|
|
||||||
|
// Should have uncommented task lines (storeTasksInGit = false)
|
||||||
|
expect(content).toMatch(
|
||||||
|
/# Task files\s*[\r\n]+tasks\.json\s*[\r\n]+tasks\/ /
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should not duplicate existing template content', () => {
|
||||||
|
// Create existing file that already has some template content
|
||||||
|
const existingContent = `# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# Dependencies
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Custom content
|
||||||
|
custom.txt
|
||||||
|
|
||||||
|
# Task files
|
||||||
|
# tasks.json
|
||||||
|
# tasks/ `;
|
||||||
|
|
||||||
|
fs.writeFileSync(testGitignorePath, existingContent);
|
||||||
|
|
||||||
|
manageGitignoreFile(testGitignorePath, templateContent, false);
|
||||||
|
|
||||||
|
const content = fs.readFileSync(testGitignorePath, 'utf8');
|
||||||
|
|
||||||
|
// Should not duplicate logs section
|
||||||
|
const logsMatches = content.match(/# Logs/g);
|
||||||
|
expect(logsMatches).toHaveLength(1);
|
||||||
|
|
||||||
|
// Should not duplicate dependencies section
|
||||||
|
const depsMatches = content.match(/# Dependencies/g);
|
||||||
|
expect(depsMatches).toHaveLength(1);
|
||||||
|
|
||||||
|
// Should retain custom content
|
||||||
|
expect(content).toContain('# Custom content');
|
||||||
|
expect(content).toContain('custom.txt');
|
||||||
|
|
||||||
|
// Should add new template content that wasn't present
|
||||||
|
expect(content).toContain('# Environment variables');
|
||||||
|
expect(content).toContain('.env');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should handle empty existing file', () => {
|
||||||
|
// Create empty file
|
||||||
|
fs.writeFileSync(testGitignorePath, '');
|
||||||
|
|
||||||
|
manageGitignoreFile(testGitignorePath, templateContent, false);
|
||||||
|
|
||||||
|
expect(fs.existsSync(testGitignorePath)).toBe(true);
|
||||||
|
|
||||||
|
const content = fs.readFileSync(testGitignorePath, 'utf8');
|
||||||
|
expect(content).toContain('# Logs');
|
||||||
|
expect(content).toContain('# Task files');
|
||||||
|
expect(content).toMatch(
|
||||||
|
/# Task files\s*[\r\n]+tasks\.json\s*[\r\n]+tasks\/ /
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should handle file with only whitespace', () => {
|
||||||
|
// Create file with only whitespace
|
||||||
|
fs.writeFileSync(testGitignorePath, ' \n\n \n');
|
||||||
|
|
||||||
|
manageGitignoreFile(testGitignorePath, templateContent, true);
|
||||||
|
|
||||||
|
const content = fs.readFileSync(testGitignorePath, 'utf8');
|
||||||
|
expect(content).toContain('# Logs');
|
||||||
|
expect(content).toContain('# Task files');
|
||||||
|
expect(content).toMatch(
|
||||||
|
/# Task files\s*[\r\n]+# tasks\.json\s*[\r\n]+# tasks\/ /
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Complex Task Section Handling', () => {
|
||||||
|
test('should remove task section with mixed comments and spacing', () => {
|
||||||
|
const existingContent = `# Dependencies
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Task files
|
||||||
|
|
||||||
|
# tasks.json
|
||||||
|
tasks/
|
||||||
|
|
||||||
|
|
||||||
|
# More content
|
||||||
|
more.txt`;
|
||||||
|
|
||||||
|
const templateContent = `# New content
|
||||||
|
new.txt
|
||||||
|
|
||||||
|
# Task files
|
||||||
|
tasks.json
|
||||||
|
tasks/ `;
|
||||||
|
|
||||||
|
fs.writeFileSync(testGitignorePath, existingContent);
|
||||||
|
|
||||||
|
manageGitignoreFile(testGitignorePath, templateContent, false);
|
||||||
|
|
||||||
|
const content = fs.readFileSync(testGitignorePath, 'utf8');
|
||||||
|
|
||||||
|
// Should retain non-task content
|
||||||
|
expect(content).toContain('# Dependencies');
|
||||||
|
expect(content).toContain('node_modules/');
|
||||||
|
expect(content).toContain('# More content');
|
||||||
|
expect(content).toContain('more.txt');
|
||||||
|
|
||||||
|
// Should add new content
|
||||||
|
expect(content).toContain('# New content');
|
||||||
|
expect(content).toContain('new.txt');
|
||||||
|
|
||||||
|
// Should have clean task section (storeTasksInGit = false means uncommented)
|
||||||
|
expect(content).toMatch(
|
||||||
|
/# Task files\s*[\r\n]+tasks\.json\s*[\r\n]+tasks\/ /
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should handle multiple task file variations', () => {
|
||||||
|
const existingContent = `# Existing
|
||||||
|
existing.txt
|
||||||
|
|
||||||
|
# Task files
|
||||||
|
tasks.json
|
||||||
|
# tasks.json
|
||||||
|
# tasks/
|
||||||
|
tasks/
|
||||||
|
#tasks.json
|
||||||
|
|
||||||
|
# More content
|
||||||
|
more.txt`;
|
||||||
|
|
||||||
|
const templateContent = `# Task files
|
||||||
|
tasks.json
|
||||||
|
tasks/ `;
|
||||||
|
|
||||||
|
fs.writeFileSync(testGitignorePath, existingContent);
|
||||||
|
|
||||||
|
manageGitignoreFile(testGitignorePath, templateContent, true);
|
||||||
|
|
||||||
|
const content = fs.readFileSync(testGitignorePath, 'utf8');
|
||||||
|
|
||||||
|
// Should retain non-task content
|
||||||
|
expect(content).toContain('# Existing');
|
||||||
|
expect(content).toContain('existing.txt');
|
||||||
|
expect(content).toContain('# More content');
|
||||||
|
expect(content).toContain('more.txt');
|
||||||
|
|
||||||
|
// Should have clean task section with preference applied (storeTasksInGit = true means commented)
|
||||||
|
expect(content).toMatch(
|
||||||
|
/# Task files\s*[\r\n]+# tasks\.json\s*[\r\n]+# tasks\/ /
|
||||||
|
);
|
||||||
|
|
||||||
|
// Should not have multiple task sections
|
||||||
|
const taskFileMatches = content.match(/# Task files/g);
|
||||||
|
expect(taskFileMatches).toHaveLength(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Error Handling', () => {
|
||||||
|
test('should handle permission errors gracefully', () => {
|
||||||
|
// Create a directory where we would create the file, then remove write permissions
|
||||||
|
const readOnlyDir = path.join(tempDir, 'readonly');
|
||||||
|
fs.mkdirSync(readOnlyDir);
|
||||||
|
fs.chmodSync(readOnlyDir, 0o444); // Read-only
|
||||||
|
|
||||||
|
const readOnlyGitignorePath = path.join(readOnlyDir, '.gitignore');
|
||||||
|
const templateContent = `# Test
|
||||||
|
test.txt
|
||||||
|
|
||||||
|
# Task files
|
||||||
|
tasks.json
|
||||||
|
tasks/ `;
|
||||||
|
|
||||||
|
const logs = [];
|
||||||
|
const mockLog = (level, message) => logs.push({ level, message });
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
manageGitignoreFile(
|
||||||
|
readOnlyGitignorePath,
|
||||||
|
templateContent,
|
||||||
|
false,
|
||||||
|
mockLog
|
||||||
|
);
|
||||||
|
}).toThrow();
|
||||||
|
|
||||||
|
// Verify error was logged
|
||||||
|
expect(logs).toContainEqual({
|
||||||
|
level: 'error',
|
||||||
|
message: expect.stringContaining('Failed to create')
|
||||||
|
});
|
||||||
|
|
||||||
|
// Restore permissions for cleanup
|
||||||
|
fs.chmodSync(readOnlyDir, 0o755);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should handle read errors on existing files', () => {
|
||||||
|
// Create a file then remove read permissions
|
||||||
|
fs.writeFileSync(testGitignorePath, 'existing content');
|
||||||
|
fs.chmodSync(testGitignorePath, 0o000); // No permissions
|
||||||
|
|
||||||
|
const templateContent = `# Test
|
||||||
|
test.txt
|
||||||
|
|
||||||
|
# Task files
|
||||||
|
tasks.json
|
||||||
|
tasks/ `;
|
||||||
|
|
||||||
|
const logs = [];
|
||||||
|
const mockLog = (level, message) => logs.push({ level, message });
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
manageGitignoreFile(testGitignorePath, templateContent, false, mockLog);
|
||||||
|
}).toThrow();
|
||||||
|
|
||||||
|
// Verify error was logged
|
||||||
|
expect(logs).toContainEqual({
|
||||||
|
level: 'error',
|
||||||
|
message: expect.stringContaining('Failed to merge content')
|
||||||
|
});
|
||||||
|
|
||||||
|
// Restore permissions for cleanup
|
||||||
|
fs.chmodSync(testGitignorePath, 0o644);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Real-world Scenarios', () => {
|
||||||
|
test('should handle typical Node.js project .gitignore', () => {
|
||||||
|
const existingNodeGitignore = `# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
|
||||||
|
# Runtime data
|
||||||
|
pids
|
||||||
|
*.pid
|
||||||
|
*.seed
|
||||||
|
*.pid.lock
|
||||||
|
|
||||||
|
# Dependency directories
|
||||||
|
node_modules/
|
||||||
|
jspm_packages/
|
||||||
|
|
||||||
|
# Optional npm cache directory
|
||||||
|
.npm
|
||||||
|
|
||||||
|
# Output of 'npm pack'
|
||||||
|
*.tgz
|
||||||
|
|
||||||
|
# Yarn Integrity file
|
||||||
|
.yarn-integrity
|
||||||
|
|
||||||
|
# dotenv environment variables file
|
||||||
|
.env
|
||||||
|
|
||||||
|
# next.js build output
|
||||||
|
.next`;
|
||||||
|
|
||||||
|
const taskMasterTemplate = `# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# Dependencies
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Environment variables
|
||||||
|
.env
|
||||||
|
|
||||||
|
# Build output
|
||||||
|
dist/
|
||||||
|
build/
|
||||||
|
|
||||||
|
# Task files
|
||||||
|
tasks.json
|
||||||
|
tasks/ `;
|
||||||
|
|
||||||
|
fs.writeFileSync(testGitignorePath, existingNodeGitignore);
|
||||||
|
|
||||||
|
manageGitignoreFile(testGitignorePath, taskMasterTemplate, false);
|
||||||
|
|
||||||
|
const content = fs.readFileSync(testGitignorePath, 'utf8');
|
||||||
|
|
||||||
|
// Should retain existing Node.js specific entries
|
||||||
|
expect(content).toContain('npm-debug.log*');
|
||||||
|
expect(content).toContain('yarn-debug.log*');
|
||||||
|
expect(content).toContain('*.pid');
|
||||||
|
expect(content).toContain('jspm_packages/');
|
||||||
|
expect(content).toContain('.npm');
|
||||||
|
expect(content).toContain('*.tgz');
|
||||||
|
expect(content).toContain('.yarn-integrity');
|
||||||
|
expect(content).toContain('.next');
|
||||||
|
|
||||||
|
// Should add new content from template that wasn't present
|
||||||
|
expect(content).toContain('dist/');
|
||||||
|
expect(content).toContain('build/');
|
||||||
|
|
||||||
|
// Should add task files section with correct preference (storeTasksInGit = false means uncommented)
|
||||||
|
expect(content).toMatch(
|
||||||
|
/# Task files\s*[\r\n]+tasks\.json\s*[\r\n]+tasks\/ /
|
||||||
|
);
|
||||||
|
|
||||||
|
// Should not duplicate common entries
|
||||||
|
const nodeModulesMatches = content.match(/node_modules\//g);
|
||||||
|
expect(nodeModulesMatches).toHaveLength(1);
|
||||||
|
|
||||||
|
const logsMatches = content.match(/# Logs/g);
|
||||||
|
expect(logsMatches).toHaveLength(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should handle project with existing task files in git', () => {
|
||||||
|
const existingContent = `# Dependencies
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# Current task setup - keeping in git
|
||||||
|
# Task files
|
||||||
|
tasks.json
|
||||||
|
tasks/
|
||||||
|
|
||||||
|
# Build output
|
||||||
|
dist/`;
|
||||||
|
|
||||||
|
const templateContent = `# New template
|
||||||
|
# Dependencies
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Task files
|
||||||
|
tasks.json
|
||||||
|
tasks/ `;
|
||||||
|
|
||||||
|
fs.writeFileSync(testGitignorePath, existingContent);
|
||||||
|
|
||||||
|
// Change preference to exclude tasks from git (storeTasksInGit = false means uncommented/ignored)
|
||||||
|
manageGitignoreFile(testGitignorePath, templateContent, false);
|
||||||
|
|
||||||
|
const content = fs.readFileSync(testGitignorePath, 'utf8');
|
||||||
|
|
||||||
|
// Should retain existing content
|
||||||
|
expect(content).toContain('# Dependencies');
|
||||||
|
expect(content).toContain('node_modules/');
|
||||||
|
expect(content).toContain('# Logs');
|
||||||
|
expect(content).toContain('*.log');
|
||||||
|
expect(content).toContain('# Build output');
|
||||||
|
expect(content).toContain('dist/');
|
||||||
|
|
||||||
|
// Should update task preference to uncommented (storeTasksInGit = false)
|
||||||
|
expect(content).toMatch(
|
||||||
|
/# Task files\s*[\r\n]+tasks\.json\s*[\r\n]+tasks\/ /
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -133,7 +133,7 @@ jest.mock('../../../scripts/modules/utils.js', () => ({
|
|||||||
readComplexityReport: mockReadComplexityReport,
|
readComplexityReport: mockReadComplexityReport,
|
||||||
CONFIG: {
|
CONFIG: {
|
||||||
model: 'claude-3-7-sonnet-20250219',
|
model: 'claude-3-7-sonnet-20250219',
|
||||||
maxTokens: 64000,
|
maxTokens: 8192,
|
||||||
temperature: 0.2,
|
temperature: 0.2,
|
||||||
defaultSubtasks: 5
|
defaultSubtasks: 5
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ const DEFAULT_CONFIG = {
|
|||||||
fallback: {
|
fallback: {
|
||||||
provider: 'anthropic',
|
provider: 'anthropic',
|
||||||
modelId: 'claude-3-5-sonnet',
|
modelId: 'claude-3-5-sonnet',
|
||||||
maxTokens: 64000,
|
maxTokens: 8192,
|
||||||
temperature: 0.2
|
temperature: 0.2
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ const DEFAULT_CONFIG = {
|
|||||||
fallback: {
|
fallback: {
|
||||||
provider: 'anthropic',
|
provider: 'anthropic',
|
||||||
modelId: 'claude-3-5-sonnet',
|
modelId: 'claude-3-5-sonnet',
|
||||||
maxTokens: 64000,
|
maxTokens: 8192,
|
||||||
temperature: 0.2
|
temperature: 0.2
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
538
tests/unit/initialize-project.test.js
Normal file
538
tests/unit/initialize-project.test.js
Normal file
@@ -0,0 +1,538 @@
|
|||||||
|
import { jest } from '@jest/globals';
|
||||||
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
import os from 'os';
|
||||||
|
|
||||||
|
// Reduce noise in test output
|
||||||
|
process.env.TASKMASTER_LOG_LEVEL = 'error';
|
||||||
|
|
||||||
|
// === Mock everything early ===
|
||||||
|
jest.mock('child_process', () => ({ execSync: jest.fn() }));
|
||||||
|
jest.mock('fs', () => ({
|
||||||
|
...jest.requireActual('fs'),
|
||||||
|
mkdirSync: jest.fn(),
|
||||||
|
writeFileSync: jest.fn(),
|
||||||
|
readFileSync: jest.fn(),
|
||||||
|
appendFileSync: jest.fn(),
|
||||||
|
existsSync: jest.fn(),
|
||||||
|
mkdtempSync: jest.requireActual('fs').mkdtempSync,
|
||||||
|
rmSync: jest.requireActual('fs').rmSync
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Mock console methods to suppress output
|
||||||
|
const consoleMethods = ['log', 'info', 'warn', 'error', 'clear'];
|
||||||
|
consoleMethods.forEach((method) => {
|
||||||
|
global.console[method] = jest.fn();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Mock ES modules using unstable_mockModule
|
||||||
|
jest.unstable_mockModule('../../scripts/modules/utils.js', () => ({
|
||||||
|
isSilentMode: jest.fn(() => true),
|
||||||
|
enableSilentMode: jest.fn(),
|
||||||
|
log: jest.fn(),
|
||||||
|
findProjectRoot: jest.fn(() => process.cwd())
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Mock git-utils module
|
||||||
|
jest.unstable_mockModule('../../scripts/modules/utils/git-utils.js', () => ({
|
||||||
|
insideGitWorkTree: jest.fn(() => false)
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Mock rule transformer
|
||||||
|
jest.unstable_mockModule('../../src/utils/rule-transformer.js', () => ({
|
||||||
|
convertAllRulesToProfileRules: jest.fn(),
|
||||||
|
getRulesProfile: jest.fn(() => ({
|
||||||
|
conversionConfig: {},
|
||||||
|
globalReplacements: []
|
||||||
|
}))
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Mock any other modules that might output or do real operations
|
||||||
|
jest.unstable_mockModule('../../scripts/modules/config-manager.js', () => ({
|
||||||
|
createDefaultConfig: jest.fn(() => ({ models: {}, project: {} })),
|
||||||
|
saveConfig: jest.fn()
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Mock display libraries
|
||||||
|
jest.mock('figlet', () => ({ textSync: jest.fn(() => 'MOCKED BANNER') }));
|
||||||
|
jest.mock('boxen', () => jest.fn(() => 'MOCKED BOX'));
|
||||||
|
jest.mock('gradient-string', () => jest.fn(() => jest.fn((text) => text)));
|
||||||
|
jest.mock('chalk', () => ({
|
||||||
|
blue: jest.fn((text) => text),
|
||||||
|
green: jest.fn((text) => text),
|
||||||
|
red: jest.fn((text) => text),
|
||||||
|
yellow: jest.fn((text) => text),
|
||||||
|
cyan: jest.fn((text) => text),
|
||||||
|
white: jest.fn((text) => text),
|
||||||
|
dim: jest.fn((text) => text),
|
||||||
|
bold: jest.fn((text) => text),
|
||||||
|
underline: jest.fn((text) => text)
|
||||||
|
}));
|
||||||
|
|
||||||
|
const { execSync } = jest.requireMock('child_process');
|
||||||
|
const mockFs = jest.requireMock('fs');
|
||||||
|
|
||||||
|
// Import the mocked modules
|
||||||
|
const mockUtils = await import('../../scripts/modules/utils.js');
|
||||||
|
const mockGitUtils = await import('../../scripts/modules/utils/git-utils.js');
|
||||||
|
const mockRuleTransformer = await import('../../src/utils/rule-transformer.js');
|
||||||
|
|
||||||
|
// Import after mocks
|
||||||
|
const { initializeProject } = await import('../../scripts/init.js');
|
||||||
|
|
||||||
|
describe('initializeProject – Git / Alias flag logic', () => {
|
||||||
|
let tmpDir;
|
||||||
|
const origCwd = process.cwd();
|
||||||
|
|
||||||
|
// Standard non-interactive options for all tests
|
||||||
|
const baseOptions = {
|
||||||
|
yes: true,
|
||||||
|
skipInstall: true,
|
||||||
|
name: 'test-project',
|
||||||
|
description: 'Test project description',
|
||||||
|
version: '1.0.0',
|
||||||
|
author: 'Test Author'
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
|
||||||
|
// Set up basic fs mocks
|
||||||
|
mockFs.mkdirSync.mockImplementation(() => {});
|
||||||
|
mockFs.writeFileSync.mockImplementation(() => {});
|
||||||
|
mockFs.readFileSync.mockImplementation((filePath) => {
|
||||||
|
if (filePath.includes('assets') || filePath.includes('.cursor/rules')) {
|
||||||
|
return 'mock template content';
|
||||||
|
}
|
||||||
|
if (filePath.includes('.zshrc') || filePath.includes('.bashrc')) {
|
||||||
|
return '# existing config';
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
});
|
||||||
|
mockFs.appendFileSync.mockImplementation(() => {});
|
||||||
|
mockFs.existsSync.mockImplementation((filePath) => {
|
||||||
|
// Template source files exist
|
||||||
|
if (filePath.includes('assets') || filePath.includes('.cursor/rules')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Shell config files exist by default
|
||||||
|
if (filePath.includes('.zshrc') || filePath.includes('.bashrc')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Reset utils mocks
|
||||||
|
mockUtils.isSilentMode.mockReturnValue(true);
|
||||||
|
mockGitUtils.insideGitWorkTree.mockReturnValue(false);
|
||||||
|
|
||||||
|
// Default execSync mock
|
||||||
|
execSync.mockImplementation(() => '');
|
||||||
|
|
||||||
|
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'tm-init-'));
|
||||||
|
process.chdir(tmpDir);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
process.chdir(origCwd);
|
||||||
|
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Git Flag Behavior', () => {
|
||||||
|
it('completes successfully with git:false in dry run', async () => {
|
||||||
|
const result = await initializeProject({
|
||||||
|
...baseOptions,
|
||||||
|
git: false,
|
||||||
|
aliases: false,
|
||||||
|
dryRun: true
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.dryRun).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('completes successfully with git:true when not inside repo', async () => {
|
||||||
|
mockGitUtils.insideGitWorkTree.mockReturnValue(false);
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
initializeProject({
|
||||||
|
...baseOptions,
|
||||||
|
git: true,
|
||||||
|
aliases: false,
|
||||||
|
dryRun: false
|
||||||
|
})
|
||||||
|
).resolves.not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('completes successfully when already inside repo', async () => {
|
||||||
|
mockGitUtils.insideGitWorkTree.mockReturnValue(true);
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
initializeProject({
|
||||||
|
...baseOptions,
|
||||||
|
git: true,
|
||||||
|
aliases: false,
|
||||||
|
dryRun: false
|
||||||
|
})
|
||||||
|
).resolves.not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('uses default git behavior without errors', async () => {
|
||||||
|
mockGitUtils.insideGitWorkTree.mockReturnValue(false);
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
initializeProject({
|
||||||
|
...baseOptions,
|
||||||
|
aliases: false,
|
||||||
|
dryRun: false
|
||||||
|
})
|
||||||
|
).resolves.not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles git command failures gracefully', async () => {
|
||||||
|
mockGitUtils.insideGitWorkTree.mockReturnValue(false);
|
||||||
|
execSync.mockImplementation((cmd) => {
|
||||||
|
if (cmd.includes('git init')) {
|
||||||
|
throw new Error('git not found');
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
initializeProject({
|
||||||
|
...baseOptions,
|
||||||
|
git: true,
|
||||||
|
aliases: false,
|
||||||
|
dryRun: false
|
||||||
|
})
|
||||||
|
).resolves.not.toThrow();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Alias Flag Behavior', () => {
|
||||||
|
it('completes successfully when aliases:true and environment is set up', async () => {
|
||||||
|
const originalShell = process.env.SHELL;
|
||||||
|
const originalHome = process.env.HOME;
|
||||||
|
|
||||||
|
process.env.SHELL = '/bin/zsh';
|
||||||
|
process.env.HOME = '/mock/home';
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
initializeProject({
|
||||||
|
...baseOptions,
|
||||||
|
git: false,
|
||||||
|
aliases: true,
|
||||||
|
dryRun: false
|
||||||
|
})
|
||||||
|
).resolves.not.toThrow();
|
||||||
|
|
||||||
|
process.env.SHELL = originalShell;
|
||||||
|
process.env.HOME = originalHome;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('completes successfully when aliases:false', async () => {
|
||||||
|
await expect(
|
||||||
|
initializeProject({
|
||||||
|
...baseOptions,
|
||||||
|
git: false,
|
||||||
|
aliases: false,
|
||||||
|
dryRun: false
|
||||||
|
})
|
||||||
|
).resolves.not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles missing shell gracefully', async () => {
|
||||||
|
const originalShell = process.env.SHELL;
|
||||||
|
const originalHome = process.env.HOME;
|
||||||
|
|
||||||
|
delete process.env.SHELL; // Remove shell env var
|
||||||
|
process.env.HOME = '/mock/home';
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
initializeProject({
|
||||||
|
...baseOptions,
|
||||||
|
git: false,
|
||||||
|
aliases: true,
|
||||||
|
dryRun: false
|
||||||
|
})
|
||||||
|
).resolves.not.toThrow();
|
||||||
|
|
||||||
|
process.env.SHELL = originalShell;
|
||||||
|
process.env.HOME = originalHome;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles missing shell config file gracefully', async () => {
|
||||||
|
const originalShell = process.env.SHELL;
|
||||||
|
const originalHome = process.env.HOME;
|
||||||
|
|
||||||
|
process.env.SHELL = '/bin/zsh';
|
||||||
|
process.env.HOME = '/mock/home';
|
||||||
|
|
||||||
|
// Shell config doesn't exist
|
||||||
|
mockFs.existsSync.mockImplementation((filePath) => {
|
||||||
|
if (filePath.includes('.zshrc') || filePath.includes('.bashrc')) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (filePath.includes('assets') || filePath.includes('.cursor/rules')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
initializeProject({
|
||||||
|
...baseOptions,
|
||||||
|
git: false,
|
||||||
|
aliases: true,
|
||||||
|
dryRun: false
|
||||||
|
})
|
||||||
|
).resolves.not.toThrow();
|
||||||
|
|
||||||
|
process.env.SHELL = originalShell;
|
||||||
|
process.env.HOME = originalHome;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Flag Combinations', () => {
|
||||||
|
it.each`
|
||||||
|
git | aliases | description
|
||||||
|
${true} | ${true} | ${'git & aliases enabled'}
|
||||||
|
${true} | ${false} | ${'git enabled, aliases disabled'}
|
||||||
|
${false} | ${true} | ${'git disabled, aliases enabled'}
|
||||||
|
${false} | ${false} | ${'git & aliases disabled'}
|
||||||
|
`('handles $description without errors', async ({ git, aliases }) => {
|
||||||
|
const originalShell = process.env.SHELL;
|
||||||
|
const originalHome = process.env.HOME;
|
||||||
|
|
||||||
|
if (aliases) {
|
||||||
|
process.env.SHELL = '/bin/zsh';
|
||||||
|
process.env.HOME = '/mock/home';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (git) {
|
||||||
|
mockGitUtils.insideGitWorkTree.mockReturnValue(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
initializeProject({
|
||||||
|
...baseOptions,
|
||||||
|
git,
|
||||||
|
aliases,
|
||||||
|
dryRun: false
|
||||||
|
})
|
||||||
|
).resolves.not.toThrow();
|
||||||
|
|
||||||
|
process.env.SHELL = originalShell;
|
||||||
|
process.env.HOME = originalHome;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Dry Run Mode', () => {
|
||||||
|
it('returns dry run result and performs no operations', async () => {
|
||||||
|
const result = await initializeProject({
|
||||||
|
...baseOptions,
|
||||||
|
git: true,
|
||||||
|
aliases: true,
|
||||||
|
dryRun: true
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.dryRun).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each`
|
||||||
|
git | aliases | description
|
||||||
|
${true} | ${false} | ${'git-specific behavior'}
|
||||||
|
${false} | ${false} | ${'no-git behavior'}
|
||||||
|
${false} | ${true} | ${'alias behavior'}
|
||||||
|
`('shows $description in dry run', async ({ git, aliases }) => {
|
||||||
|
const result = await initializeProject({
|
||||||
|
...baseOptions,
|
||||||
|
git,
|
||||||
|
aliases,
|
||||||
|
dryRun: true
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.dryRun).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Error Handling', () => {
|
||||||
|
it('handles npm install failures gracefully', async () => {
|
||||||
|
execSync.mockImplementation((cmd) => {
|
||||||
|
if (cmd.includes('npm install')) {
|
||||||
|
throw new Error('npm failed');
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
initializeProject({
|
||||||
|
...baseOptions,
|
||||||
|
git: false,
|
||||||
|
aliases: false,
|
||||||
|
skipInstall: false,
|
||||||
|
dryRun: false
|
||||||
|
})
|
||||||
|
).resolves.not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles git failures gracefully', async () => {
|
||||||
|
mockGitUtils.insideGitWorkTree.mockReturnValue(false);
|
||||||
|
execSync.mockImplementation((cmd) => {
|
||||||
|
if (cmd.includes('git init')) {
|
||||||
|
throw new Error('git failed');
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
initializeProject({
|
||||||
|
...baseOptions,
|
||||||
|
git: true,
|
||||||
|
aliases: false,
|
||||||
|
dryRun: false
|
||||||
|
})
|
||||||
|
).resolves.not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles file system errors gracefully', async () => {
|
||||||
|
mockFs.mkdirSync.mockImplementation(() => {
|
||||||
|
throw new Error('Permission denied');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Should handle file system errors gracefully
|
||||||
|
await expect(
|
||||||
|
initializeProject({
|
||||||
|
...baseOptions,
|
||||||
|
git: false,
|
||||||
|
aliases: false,
|
||||||
|
dryRun: false
|
||||||
|
})
|
||||||
|
).resolves.not.toThrow();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Non-Interactive Mode', () => {
|
||||||
|
it('bypasses prompts with yes:true', async () => {
|
||||||
|
const result = await initializeProject({
|
||||||
|
...baseOptions,
|
||||||
|
git: true,
|
||||||
|
aliases: true,
|
||||||
|
dryRun: true
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result).toEqual({ dryRun: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('completes without hanging', async () => {
|
||||||
|
await expect(
|
||||||
|
initializeProject({
|
||||||
|
...baseOptions,
|
||||||
|
git: false,
|
||||||
|
aliases: false,
|
||||||
|
dryRun: false
|
||||||
|
})
|
||||||
|
).resolves.not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles all flag combinations without hanging', async () => {
|
||||||
|
const flagCombinations = [
|
||||||
|
{ git: true, aliases: true },
|
||||||
|
{ git: true, aliases: false },
|
||||||
|
{ git: false, aliases: true },
|
||||||
|
{ git: false, aliases: false },
|
||||||
|
{} // No flags (uses defaults)
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const flags of flagCombinations) {
|
||||||
|
await expect(
|
||||||
|
initializeProject({
|
||||||
|
...baseOptions,
|
||||||
|
...flags,
|
||||||
|
dryRun: true // Use dry run for speed
|
||||||
|
})
|
||||||
|
).resolves.not.toThrow();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('accepts complete project details', async () => {
|
||||||
|
await expect(
|
||||||
|
initializeProject({
|
||||||
|
name: 'test-project',
|
||||||
|
description: 'test description',
|
||||||
|
version: '2.0.0',
|
||||||
|
author: 'Test User',
|
||||||
|
git: false,
|
||||||
|
aliases: false,
|
||||||
|
dryRun: true
|
||||||
|
})
|
||||||
|
).resolves.not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('works with skipInstall option', async () => {
|
||||||
|
await expect(
|
||||||
|
initializeProject({
|
||||||
|
...baseOptions,
|
||||||
|
skipInstall: true,
|
||||||
|
git: false,
|
||||||
|
aliases: false,
|
||||||
|
dryRun: false
|
||||||
|
})
|
||||||
|
).resolves.not.toThrow();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Function Integration', () => {
|
||||||
|
it('calls utility functions without errors', async () => {
|
||||||
|
await initializeProject({
|
||||||
|
...baseOptions,
|
||||||
|
git: false,
|
||||||
|
aliases: false,
|
||||||
|
dryRun: false
|
||||||
|
});
|
||||||
|
|
||||||
|
// Verify that utility functions were called
|
||||||
|
expect(mockUtils.isSilentMode).toHaveBeenCalled();
|
||||||
|
expect(
|
||||||
|
mockRuleTransformer.convertAllRulesToProfileRules
|
||||||
|
).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles template operations gracefully', async () => {
|
||||||
|
// Make file operations throw errors
|
||||||
|
mockFs.writeFileSync.mockImplementation(() => {
|
||||||
|
throw new Error('Write failed');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Should complete despite file operation failures
|
||||||
|
await expect(
|
||||||
|
initializeProject({
|
||||||
|
...baseOptions,
|
||||||
|
git: false,
|
||||||
|
aliases: false,
|
||||||
|
dryRun: false
|
||||||
|
})
|
||||||
|
).resolves.not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('validates boolean flag conversion', async () => {
|
||||||
|
// Test the boolean flag handling specifically
|
||||||
|
await expect(
|
||||||
|
initializeProject({
|
||||||
|
...baseOptions,
|
||||||
|
git: true, // Should convert to initGit: true
|
||||||
|
aliases: false, // Should convert to addAliases: false
|
||||||
|
dryRun: true
|
||||||
|
})
|
||||||
|
).resolves.not.toThrow();
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
initializeProject({
|
||||||
|
...baseOptions,
|
||||||
|
git: false, // Should convert to initGit: false
|
||||||
|
aliases: true, // Should convert to addAliases: true
|
||||||
|
dryRun: true
|
||||||
|
})
|
||||||
|
).resolves.not.toThrow();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
439
tests/unit/manage-gitignore.test.js
Normal file
439
tests/unit/manage-gitignore.test.js
Normal file
@@ -0,0 +1,439 @@
|
|||||||
|
/**
|
||||||
|
* Unit tests for manage-gitignore.js module
|
||||||
|
* Tests the logic with Jest spies instead of mocked modules
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { jest } from '@jest/globals';
|
||||||
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
import os from 'os';
|
||||||
|
|
||||||
|
// Import the module under test and its exports
|
||||||
|
import manageGitignoreFile, {
|
||||||
|
normalizeLine,
|
||||||
|
isTaskLine,
|
||||||
|
buildTaskFilesSection,
|
||||||
|
TASK_FILES_COMMENT,
|
||||||
|
TASK_JSON_PATTERN,
|
||||||
|
TASK_DIR_PATTERN
|
||||||
|
} from '../../src/utils/manage-gitignore.js';
|
||||||
|
|
||||||
|
describe('manage-gitignore.js Unit Tests', () => {
|
||||||
|
let tempDir;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
|
||||||
|
// Create a temporary directory for testing
|
||||||
|
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'manage-gitignore-test-'));
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
// Clean up the temporary directory
|
||||||
|
try {
|
||||||
|
fs.rmSync(tempDir, { recursive: true, force: true });
|
||||||
|
} catch (err) {
|
||||||
|
// Ignore cleanup errors
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Constants', () => {
|
||||||
|
test('should have correct constant values', () => {
|
||||||
|
expect(TASK_FILES_COMMENT).toBe('# Task files');
|
||||||
|
expect(TASK_JSON_PATTERN).toBe('tasks.json');
|
||||||
|
expect(TASK_DIR_PATTERN).toBe('tasks/');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('normalizeLine function', () => {
|
||||||
|
test('should remove leading/trailing whitespace', () => {
|
||||||
|
expect(normalizeLine(' test ')).toBe('test');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should remove comment hash and trim', () => {
|
||||||
|
expect(normalizeLine('# tasks.json')).toBe('tasks.json');
|
||||||
|
expect(normalizeLine('#tasks/')).toBe('tasks/');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should handle empty strings', () => {
|
||||||
|
expect(normalizeLine('')).toBe('');
|
||||||
|
expect(normalizeLine(' ')).toBe('');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should handle lines without comments', () => {
|
||||||
|
expect(normalizeLine('tasks.json')).toBe('tasks.json');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('isTaskLine function', () => {
|
||||||
|
test('should identify task.json patterns', () => {
|
||||||
|
expect(isTaskLine('tasks.json')).toBe(true);
|
||||||
|
expect(isTaskLine('# tasks.json')).toBe(true);
|
||||||
|
expect(isTaskLine(' # tasks.json ')).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should identify tasks/ patterns', () => {
|
||||||
|
expect(isTaskLine('tasks/')).toBe(true);
|
||||||
|
expect(isTaskLine('# tasks/')).toBe(true);
|
||||||
|
expect(isTaskLine(' # tasks/ ')).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should reject non-task patterns', () => {
|
||||||
|
expect(isTaskLine('node_modules/')).toBe(false);
|
||||||
|
expect(isTaskLine('# Some comment')).toBe(false);
|
||||||
|
expect(isTaskLine('')).toBe(false);
|
||||||
|
expect(isTaskLine('tasks.txt')).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('buildTaskFilesSection function', () => {
|
||||||
|
test('should build commented section when storeTasksInGit is true (tasks stored in git)', () => {
|
||||||
|
const result = buildTaskFilesSection(true);
|
||||||
|
expect(result).toEqual(['# Task files', '# tasks.json', '# tasks/ ']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should build uncommented section when storeTasksInGit is false (tasks ignored)', () => {
|
||||||
|
const result = buildTaskFilesSection(false);
|
||||||
|
expect(result).toEqual(['# Task files', 'tasks.json', 'tasks/ ']);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('manageGitignoreFile function - Input Validation', () => {
|
||||||
|
test('should throw error for invalid targetPath', () => {
|
||||||
|
expect(() => {
|
||||||
|
manageGitignoreFile('', 'content', false);
|
||||||
|
}).toThrow('targetPath must be a non-empty string');
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
manageGitignoreFile(null, 'content', false);
|
||||||
|
}).toThrow('targetPath must be a non-empty string');
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
manageGitignoreFile('invalid.txt', 'content', false);
|
||||||
|
}).toThrow('targetPath must end with .gitignore');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should throw error for invalid content', () => {
|
||||||
|
expect(() => {
|
||||||
|
manageGitignoreFile('.gitignore', '', false);
|
||||||
|
}).toThrow('content must be a non-empty string');
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
manageGitignoreFile('.gitignore', null, false);
|
||||||
|
}).toThrow('content must be a non-empty string');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should throw error for invalid storeTasksInGit', () => {
|
||||||
|
expect(() => {
|
||||||
|
manageGitignoreFile('.gitignore', 'content', 'not-boolean');
|
||||||
|
}).toThrow('storeTasksInGit must be a boolean');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('manageGitignoreFile function - File Operations with Spies', () => {
|
||||||
|
let writeFileSyncSpy;
|
||||||
|
let readFileSyncSpy;
|
||||||
|
let existsSyncSpy;
|
||||||
|
let mockLog;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
// Set up spies
|
||||||
|
writeFileSyncSpy = jest
|
||||||
|
.spyOn(fs, 'writeFileSync')
|
||||||
|
.mockImplementation(() => {});
|
||||||
|
readFileSyncSpy = jest
|
||||||
|
.spyOn(fs, 'readFileSync')
|
||||||
|
.mockImplementation(() => '');
|
||||||
|
existsSyncSpy = jest
|
||||||
|
.spyOn(fs, 'existsSync')
|
||||||
|
.mockImplementation(() => false);
|
||||||
|
mockLog = jest.fn();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
// Restore original implementations
|
||||||
|
writeFileSyncSpy.mockRestore();
|
||||||
|
readFileSyncSpy.mockRestore();
|
||||||
|
existsSyncSpy.mockRestore();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('New File Creation', () => {
|
||||||
|
const templateContent = `# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# Task files
|
||||||
|
tasks.json
|
||||||
|
tasks/ `;
|
||||||
|
|
||||||
|
test('should create new file with commented task lines when storeTasksInGit is true', () => {
|
||||||
|
existsSyncSpy.mockReturnValue(false); // File doesn't exist
|
||||||
|
|
||||||
|
manageGitignoreFile('.gitignore', templateContent, true, mockLog);
|
||||||
|
|
||||||
|
expect(writeFileSyncSpy).toHaveBeenCalledWith(
|
||||||
|
'.gitignore',
|
||||||
|
`# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# Task files
|
||||||
|
# tasks.json
|
||||||
|
# tasks/ `
|
||||||
|
);
|
||||||
|
expect(mockLog).toHaveBeenCalledWith(
|
||||||
|
'success',
|
||||||
|
'Created .gitignore with full template'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should create new file with uncommented task lines when storeTasksInGit is false', () => {
|
||||||
|
existsSyncSpy.mockReturnValue(false); // File doesn't exist
|
||||||
|
|
||||||
|
manageGitignoreFile('.gitignore', templateContent, false, mockLog);
|
||||||
|
|
||||||
|
expect(writeFileSyncSpy).toHaveBeenCalledWith(
|
||||||
|
'.gitignore',
|
||||||
|
`# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# Task files
|
||||||
|
tasks.json
|
||||||
|
tasks/ `
|
||||||
|
);
|
||||||
|
expect(mockLog).toHaveBeenCalledWith(
|
||||||
|
'success',
|
||||||
|
'Created .gitignore with full template'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should handle write errors gracefully', () => {
|
||||||
|
existsSyncSpy.mockReturnValue(false);
|
||||||
|
const writeError = new Error('Permission denied');
|
||||||
|
writeFileSyncSpy.mockImplementation(() => {
|
||||||
|
throw writeError;
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
manageGitignoreFile('.gitignore', templateContent, false, mockLog);
|
||||||
|
}).toThrow('Permission denied');
|
||||||
|
|
||||||
|
expect(mockLog).toHaveBeenCalledWith(
|
||||||
|
'error',
|
||||||
|
'Failed to create .gitignore: Permission denied'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('File Merging', () => {
|
||||||
|
const templateContent = `# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# Dependencies
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Task files
|
||||||
|
tasks.json
|
||||||
|
tasks/ `;
|
||||||
|
|
||||||
|
test('should merge with existing file and add new content', () => {
|
||||||
|
const existingContent = `# Old content
|
||||||
|
old-file.txt
|
||||||
|
|
||||||
|
# Task files
|
||||||
|
# tasks.json
|
||||||
|
# tasks/`;
|
||||||
|
|
||||||
|
existsSyncSpy.mockReturnValue(true); // File exists
|
||||||
|
readFileSyncSpy.mockReturnValue(existingContent);
|
||||||
|
|
||||||
|
manageGitignoreFile('.gitignore', templateContent, false, mockLog);
|
||||||
|
|
||||||
|
expect(writeFileSyncSpy).toHaveBeenCalledWith(
|
||||||
|
'.gitignore',
|
||||||
|
expect.stringContaining('# Old content')
|
||||||
|
);
|
||||||
|
expect(writeFileSyncSpy).toHaveBeenCalledWith(
|
||||||
|
'.gitignore',
|
||||||
|
expect.stringContaining('# Logs')
|
||||||
|
);
|
||||||
|
expect(writeFileSyncSpy).toHaveBeenCalledWith(
|
||||||
|
'.gitignore',
|
||||||
|
expect.stringContaining('# Dependencies')
|
||||||
|
);
|
||||||
|
expect(writeFileSyncSpy).toHaveBeenCalledWith(
|
||||||
|
'.gitignore',
|
||||||
|
expect.stringContaining('# Task files')
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should remove existing task section and replace with new preferences', () => {
|
||||||
|
const existingContent = `# Existing
|
||||||
|
existing.txt
|
||||||
|
|
||||||
|
# Task files
|
||||||
|
tasks.json
|
||||||
|
tasks/
|
||||||
|
|
||||||
|
# More content
|
||||||
|
more.txt`;
|
||||||
|
|
||||||
|
existsSyncSpy.mockReturnValue(true);
|
||||||
|
readFileSyncSpy.mockReturnValue(existingContent);
|
||||||
|
|
||||||
|
manageGitignoreFile('.gitignore', templateContent, false, mockLog);
|
||||||
|
|
||||||
|
const writtenContent = writeFileSyncSpy.mock.calls[0][1];
|
||||||
|
|
||||||
|
// Should contain existing non-task content
|
||||||
|
expect(writtenContent).toContain('# Existing');
|
||||||
|
expect(writtenContent).toContain('existing.txt');
|
||||||
|
expect(writtenContent).toContain('# More content');
|
||||||
|
expect(writtenContent).toContain('more.txt');
|
||||||
|
|
||||||
|
// Should contain new template content
|
||||||
|
expect(writtenContent).toContain('# Logs');
|
||||||
|
expect(writtenContent).toContain('# Dependencies');
|
||||||
|
|
||||||
|
// Should have uncommented task lines (storeTasksInGit = false means ignore tasks)
|
||||||
|
expect(writtenContent).toMatch(
|
||||||
|
/# Task files\s*[\r\n]+tasks\.json\s*[\r\n]+tasks\/ /
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should handle different task preferences correctly', () => {
|
||||||
|
const existingContent = `# Existing
|
||||||
|
existing.txt
|
||||||
|
|
||||||
|
# Task files
|
||||||
|
# tasks.json
|
||||||
|
# tasks/`;
|
||||||
|
|
||||||
|
existsSyncSpy.mockReturnValue(true);
|
||||||
|
readFileSyncSpy.mockReturnValue(existingContent);
|
||||||
|
|
||||||
|
// Test with storeTasksInGit = true (commented)
|
||||||
|
manageGitignoreFile('.gitignore', templateContent, true, mockLog);
|
||||||
|
|
||||||
|
const writtenContent = writeFileSyncSpy.mock.calls[0][1];
|
||||||
|
expect(writtenContent).toMatch(
|
||||||
|
/# Task files\s*[\r\n]+# tasks\.json\s*[\r\n]+# tasks\/ /
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should not duplicate existing template content', () => {
|
||||||
|
const existingContent = `# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# Dependencies
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Task files
|
||||||
|
# tasks.json
|
||||||
|
# tasks/`;
|
||||||
|
|
||||||
|
existsSyncSpy.mockReturnValue(true);
|
||||||
|
readFileSyncSpy.mockReturnValue(existingContent);
|
||||||
|
|
||||||
|
manageGitignoreFile('.gitignore', templateContent, false, mockLog);
|
||||||
|
|
||||||
|
const writtenContent = writeFileSyncSpy.mock.calls[0][1];
|
||||||
|
|
||||||
|
// Should not duplicate the logs section
|
||||||
|
const logsCount = (writtenContent.match(/# Logs/g) || []).length;
|
||||||
|
expect(logsCount).toBe(1);
|
||||||
|
|
||||||
|
// Should not duplicate dependencies
|
||||||
|
const depsCount = (writtenContent.match(/# Dependencies/g) || [])
|
||||||
|
.length;
|
||||||
|
expect(depsCount).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should handle read errors gracefully', () => {
|
||||||
|
existsSyncSpy.mockReturnValue(true);
|
||||||
|
const readError = new Error('File not readable');
|
||||||
|
readFileSyncSpy.mockImplementation(() => {
|
||||||
|
throw readError;
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
manageGitignoreFile('.gitignore', templateContent, false, mockLog);
|
||||||
|
}).toThrow('File not readable');
|
||||||
|
|
||||||
|
expect(mockLog).toHaveBeenCalledWith(
|
||||||
|
'error',
|
||||||
|
'Failed to merge content with .gitignore: File not readable'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should handle write errors during merge gracefully', () => {
|
||||||
|
existsSyncSpy.mockReturnValue(true);
|
||||||
|
readFileSyncSpy.mockReturnValue('existing content');
|
||||||
|
|
||||||
|
const writeError = new Error('Disk full');
|
||||||
|
writeFileSyncSpy.mockImplementation(() => {
|
||||||
|
throw writeError;
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
manageGitignoreFile('.gitignore', templateContent, false, mockLog);
|
||||||
|
}).toThrow('Disk full');
|
||||||
|
|
||||||
|
expect(mockLog).toHaveBeenCalledWith(
|
||||||
|
'error',
|
||||||
|
'Failed to merge content with .gitignore: Disk full'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Edge Cases', () => {
|
||||||
|
test('should work without log function', () => {
|
||||||
|
existsSyncSpy.mockReturnValue(false);
|
||||||
|
const templateContent = `# Test
|
||||||
|
test.txt
|
||||||
|
|
||||||
|
# Task files
|
||||||
|
tasks.json
|
||||||
|
tasks/`;
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
manageGitignoreFile('.gitignore', templateContent, false);
|
||||||
|
}).not.toThrow();
|
||||||
|
|
||||||
|
expect(writeFileSyncSpy).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should handle empty existing file', () => {
|
||||||
|
existsSyncSpy.mockReturnValue(true);
|
||||||
|
readFileSyncSpy.mockReturnValue('');
|
||||||
|
|
||||||
|
const templateContent = `# Task files
|
||||||
|
tasks.json
|
||||||
|
tasks/`;
|
||||||
|
|
||||||
|
manageGitignoreFile('.gitignore', templateContent, false, mockLog);
|
||||||
|
|
||||||
|
expect(writeFileSyncSpy).toHaveBeenCalled();
|
||||||
|
const writtenContent = writeFileSyncSpy.mock.calls[0][1];
|
||||||
|
expect(writtenContent).toContain('# Task files');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should handle template with only task files', () => {
|
||||||
|
existsSyncSpy.mockReturnValue(false);
|
||||||
|
const templateContent = `# Task files
|
||||||
|
tasks.json
|
||||||
|
tasks/ `;
|
||||||
|
|
||||||
|
manageGitignoreFile('.gitignore', templateContent, true, mockLog);
|
||||||
|
|
||||||
|
const writtenContent = writeFileSyncSpy.mock.calls[0][1];
|
||||||
|
expect(writtenContent).toBe(`# Task files
|
||||||
|
# tasks.json
|
||||||
|
# tasks/ `);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -123,7 +123,9 @@ describe('updateTasks', () => {
|
|||||||
details: 'New details 2 based on direction',
|
details: 'New details 2 based on direction',
|
||||||
description: 'Updated description',
|
description: 'Updated description',
|
||||||
dependencies: [],
|
dependencies: [],
|
||||||
priority: 'medium'
|
priority: 'medium',
|
||||||
|
testStrategy: 'Unit test the updated functionality',
|
||||||
|
subtasks: []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 3,
|
id: 3,
|
||||||
@@ -132,7 +134,9 @@ describe('updateTasks', () => {
|
|||||||
details: 'New details 3 based on direction',
|
details: 'New details 3 based on direction',
|
||||||
description: 'Updated description',
|
description: 'Updated description',
|
||||||
dependencies: [],
|
dependencies: [],
|
||||||
priority: 'medium'
|
priority: 'medium',
|
||||||
|
testStrategy: 'Integration test the updated features',
|
||||||
|
subtasks: []
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user