Skip to content

Commit e7aae1b

Browse files
committed
fix: TODO handle getting closest config
1 parent c157b0b commit e7aae1b

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

src/coc.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env node
1+
#!/usr/bin/env node
22
const path = require("path");
33
const fs = require("fs");
44
const execute = require('./execute');
@@ -37,6 +37,38 @@ function getRepositories(path) {
3737
}
3838
}
3939

40+
// TODO: handle getting closest config
41+
async function getConfig(directory, filename = '') {
42+
const filePath = path.resolve(directory, filename);
43+
if (!filePath.includes('node_modules')) {
44+
const configPath = findClosestConfig(filePath)
45+
if (configPath) {
46+
return { config: require(configPath), configPath, filePath };
47+
48+
} else {
49+
console.log('No CoCreate.config file found in parent directories.');
50+
}
51+
}
52+
53+
}
54+
55+
function findClosestConfig(filePath) {
56+
let currentDir = filePath;
57+
58+
while (currentDir !== '/' && currentDir !== '.') {
59+
let configFile = path.join(currentDir, 'CoCreate.config.js');
60+
61+
if (fs.existsSync(configFile)) {
62+
return configFile;
63+
}
64+
65+
currentDir = path.dirname(currentDir);
66+
}
67+
68+
return null;
69+
}
70+
71+
4072
const currentRepoPath = path.resolve(process.cwd(), "CoCreate.config.js");
4173
let packageJsonPath = path.resolve(process.cwd(), 'package.json');
4274
let directory

0 commit comments

Comments
 (0)