7e0a8ad532
* Revert "Revert "feat(core): Align GitHub metadata handling with other backends (#3292)"" This reverts commit 5bdd3df9ccbb5149c22d79987ebdcd6cab4b261f. * fix(backend-github): fix migration code * test(backend-github): fix test * test(e2e): shorten wait time * test(e2e): try and fix test on CI
43 lines
1.3 KiB
JavaScript
43 lines
1.3 KiB
JavaScript
const fs = require('fs-extra');
|
|
const path = require('path');
|
|
const yaml = require('js-yaml');
|
|
|
|
const devTestDirectory = path.join(__dirname, '..', '..', 'dev-test');
|
|
const backendsDirectory = path.join(devTestDirectory, 'backends');
|
|
|
|
async function copyBackendFiles(backend) {
|
|
await Promise.all(
|
|
['config.yml', 'index.html'].map(file => {
|
|
return fs.copyFile(
|
|
path.join(backendsDirectory, backend, file),
|
|
path.join(devTestDirectory, file),
|
|
);
|
|
}),
|
|
);
|
|
}
|
|
|
|
async function updateConfig(configModifier) {
|
|
const configFile = path.join(devTestDirectory, 'config.yml');
|
|
const configContent = await fs.readFile(configFile);
|
|
const config = yaml.safeLoad(configContent);
|
|
await configModifier(config);
|
|
await fs.writeFileSync(configFile, yaml.safeDump(config));
|
|
}
|
|
|
|
async function switchVersion(version) {
|
|
const htmlFile = path.join(devTestDirectory, 'index.html');
|
|
const content = await fs.readFile(htmlFile);
|
|
|
|
const replaceString =
|
|
version === 'latest'
|
|
? '<script src="dist/netlify-cms.js"></script>'
|
|
: `<script src="https://unpkg.com/netlify-cms@${version}/dist/netlify-cms.js"></script>`;
|
|
|
|
await fs.writeFile(
|
|
htmlFile,
|
|
content.toString().replace(/<script src=".+?netlify-cms.+?"><\/script>/, replaceString),
|
|
);
|
|
}
|
|
|
|
module.exports = { copyBackendFiles, updateConfig, switchVersion };
|