feat: v4.0.0 (#1016)
Co-authored-by: Denys Konovalov <kontakt@denyskon.de> Co-authored-by: Mathieu COSYNS <64072917+Mathieu-COSYNS@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
682576ffc4
commit
799c7e6936
42
cypress/utils/config.ts
Normal file
42
cypress/utils/config.ts
Normal file
@ -0,0 +1,42 @@
|
||||
import fs from 'fs-extra';
|
||||
import path from 'path';
|
||||
import yaml from 'js-yaml';
|
||||
|
||||
import type { Config } from '@staticcms/core/interface';
|
||||
|
||||
const devTestDirectory = path.join(__dirname, '..', '..', 'packages', 'core', 'dev-test');
|
||||
const backendsDirectory = path.join(devTestDirectory, 'backends');
|
||||
|
||||
export async function copyBackendFiles(backend: string) {
|
||||
await Promise.all(
|
||||
['config.yml', 'index.html'].map(file => {
|
||||
return fs.copyFile(
|
||||
path.join(backendsDirectory, backend, file),
|
||||
path.join(devTestDirectory, file),
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export async function updateConfig(configModifier: (config: Config) => void) {
|
||||
const configFile = path.join(devTestDirectory, 'config.yml');
|
||||
const configContent = await fs.readFile(configFile, 'utf-8');
|
||||
const config = yaml.load(configContent) as Config;
|
||||
await configModifier(config);
|
||||
await fs.writeFileSync(configFile, yaml.dump(config));
|
||||
}
|
||||
|
||||
export async function switchVersion(version: string) {
|
||||
const htmlFile = path.join(devTestDirectory, 'index.html');
|
||||
const content = await fs.readFile(htmlFile);
|
||||
|
||||
const replaceString =
|
||||
version === 'latest'
|
||||
? '<script src="dist/static-cms.js"></script>'
|
||||
: `<script src="https://unpkg.com/@staticcms/app@${version}/dist/static-cms-app.js"></script>`;
|
||||
|
||||
await fs.writeFile(
|
||||
htmlFile,
|
||||
content.toString().replace(/<script src=".+?static-cms.+?"><\/script>/, replaceString),
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user