simple-task-master
Version:
A simple command-line task management tool
108 lines • 4.16 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.findWorkspaceRoot = findWorkspaceRoot;
exports.getTasksDirectory = getTasksDirectory;
exports.getWorkspaceRoot = getWorkspaceRoot;
const fs = __importStar(require("fs/promises"));
const path = __importStar(require("path"));
const constants_1 = require("./constants");
const config_1 = require("./config");
/**
* Find the STM workspace directory by searching up the directory tree
* @param startDir - Directory to start searching from (defaults to current working directory)
* @returns The path to the project root containing .simple-task-master, or null if not found
*/
async function findWorkspaceRoot(startDir) {
let currentDir = path.resolve(startDir || process.cwd());
const root = path.parse(currentDir).root;
while (currentDir !== root) {
const stmDir = path.join(currentDir, constants_1.PATHS.BASE_DIR);
try {
const stats = await fs.stat(stmDir);
if (stats.isDirectory()) {
// Found the .simple-task-master directory
return currentDir;
}
}
catch {
// Directory doesn't exist, continue searching
}
// Move up one directory
currentDir = path.dirname(currentDir);
}
// Check the root directory as well
const rootStmDir = path.join(root, constants_1.PATHS.BASE_DIR);
try {
const stats = await fs.stat(rootStmDir);
if (stats.isDirectory()) {
return root;
}
}
catch {
// Not found
}
return null;
}
/**
* Get the tasks directory path, searching up the directory tree if needed
* @param startDir - Directory to start searching from
* @returns The path to the tasks directory
* @throws Error if no STM workspace is found
*/
async function getTasksDirectory(startDir) {
const workspaceRoot = await findWorkspaceRoot(startDir);
if (!workspaceRoot) {
throw new Error('No STM workspace found. Run "stm init" to initialize a workspace.');
}
// Use ConfigManager to get the configured tasks directory
const configManager = new config_1.ConfigManager(workspaceRoot);
await configManager.load();
return configManager.getTasksDir();
}
/**
* Get the workspace root directory, searching up the directory tree if needed
* @param startDir - Directory to start searching from
* @returns The workspace root directory
* @throws Error if no STM workspace is found
*/
async function getWorkspaceRoot(startDir) {
const workspaceRoot = await findWorkspaceRoot(startDir);
if (!workspaceRoot) {
throw new Error('No STM workspace found. Run "stm init" to initialize a workspace.');
}
return workspaceRoot;
}
//# sourceMappingURL=workspace.js.map