Skip to content

Commit

Permalink
feat(utils/detection): add provider detector
Browse files Browse the repository at this point in the history
  • Loading branch information
ComfortablyCoding committed Sep 7, 2022
1 parent 31f46bf commit 97d5d7b
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion utils/detection.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const path = require(`path`);
const shell = require(`shelljs`);
const { pathExists } = require(`fs-extra`);
const { setConfig, config } = require(`./config`);
const child_process = require(`child_process`);
const { getApiKey } = require(`../providers/heroku/apiKey`);
const { pathExists } = require(`./utils`);
const { loadProviders, loadProviderConfig } = require(`../config`);

const projectType = async () => {
const isTS = await pathExists(path.join(process.cwd(), `tsconfig.json`));
Expand All @@ -15,6 +16,26 @@ const projectType = async () => {
return `js`;
};

const provider = async () => {
const providers = loadProviders();

let providerName = null;
for (const provider in providers) {
try {
const providerConfig = loadProviderConfig(provider);
const hasProviderGeneratedFile = await pathExists(
providerConfig.outputFileName
);
if (hasProviderGeneratedFile) {
providerName = providerConfig.name;
break;
}
} catch (error) {}
}

return providerName;
};

const packageManager = async () => {
const [isYarn, isNPM] = await Promise.all([
pathExists(`yarn.lock`),
Expand Down Expand Up @@ -65,5 +86,6 @@ const herokuCLI = async () => {
module.exports = {
packageManager,
projectType,
provider,
herokuCLI
};

0 comments on commit 97d5d7b

Please sign in to comment.