[now-build-utils][now-static-build][now-cli] Update detectors and undo previous changes (#3452)

* Revert detect-builders and detect-routes changes

* Add `projectSettings` and support non-api routes

* Start with framework detectors

* Update @now/static-build

* Update now-dev

* Update tests

* Use local builders fro testing with now-dev

* Add outputDirectory to @now/static builds

* Ignore update only for bundeled builders

* Revert now-dev builder changes

* Revert more changes

* Adjust tests further

* Update gridsome test

* Adjust hugo test

* Undo version change

* Read file instead of importing

* Ignore failed.page.txt

* Update packages/now-build-utils/src/detect-builders.ts

Co-Authored-By: Steven <steven@ceriously.com>

* Simplify outputDirectory

* Remove NODE_ENV

* Convert tests to typescript

* Remove console.log

Co-authored-by: Steven <steven@ceriously.com>
This commit is contained in:
Andy
2019-12-20 16:29:39 +01:00
committed by GitHub
parent 92a40db048
commit 3794234d7a
149 changed files with 4801 additions and 3088 deletions

View File

@@ -0,0 +1,81 @@
import { Framework, FrameworkDetectionItem } from '@now/frameworks';
import { DetectorFilesystem } from './detectors/filesystem';
export interface DetectFrameworkOptions {
fs: DetectorFilesystem;
frameworkList: Framework[];
}
async function matches(fs: DetectorFilesystem, framework: Framework) {
const { detectors } = framework;
if (!detectors) {
return false;
}
const { every, some } = detectors;
if (every !== undefined && !Array.isArray(every)) {
return false;
}
if (some !== undefined && !Array.isArray(some)) {
return false;
}
const check = async ({ file, matchContent }: FrameworkDetectionItem) => {
if (!file) {
return false;
}
if ((await fs.exists(file)) === false) {
return false;
}
if (matchContent) {
const regex = new RegExp(matchContent, 'gm');
const content = await fs.readFile(file);
if (!regex.test(content.toString())) {
return false;
}
}
return true;
};
const result: boolean[] = [];
if (every) {
const everyResult = await Promise.all(every.map(item => check(item)));
result.push(...everyResult);
}
if (some) {
let someResult = false;
for (const item of some) {
if (await check(item)) {
someResult = true;
break;
}
}
result.push(someResult);
}
return result.every(res => res === true);
}
export async function detectFramework({
fs,
frameworkList,
}: DetectFrameworkOptions): Promise<string | null> {
for (const framework of frameworkList) {
if (await matches(fs, framework)) {
return framework.slug;
}
}
return null;
}