Skip to content

Commit

Permalink
fix: TODO handle getting closest config
Browse files Browse the repository at this point in the history
  • Loading branch information
frankpagan committed Jan 9, 2024
1 parent c157b0b commit e7aae1b
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/coc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node
#!/usr/bin/env node
const path = require("path");
const fs = require("fs");
const execute = require('./execute');
Expand Down Expand Up @@ -37,6 +37,38 @@ function getRepositories(path) {
}
}

// TODO: handle getting closest config
async function getConfig(directory, filename = '') {
const filePath = path.resolve(directory, filename);
if (!filePath.includes('node_modules')) {
const configPath = findClosestConfig(filePath)
if (configPath) {
return { config: require(configPath), configPath, filePath };

} else {
console.log('No CoCreate.config file found in parent directories.');
}
}

}

function findClosestConfig(filePath) {
let currentDir = filePath;

while (currentDir !== '/' && currentDir !== '.') {
let configFile = path.join(currentDir, 'CoCreate.config.js');

if (fs.existsSync(configFile)) {
return configFile;
}

currentDir = path.dirname(currentDir);
}

return null;
}


const currentRepoPath = path.resolve(process.cwd(), "CoCreate.config.js");
let packageJsonPath = path.resolve(process.cwd(), 'package.json');
let directory
Expand Down

0 comments on commit e7aae1b

Please sign in to comment.