feat(scaffolder): starting to move things around and remove the old scaffolder data

This commit is contained in:
blam
2020-06-17 14:56:30 +02:00
parent 55e6414d85
commit b01217cdb5
9 changed files with 42 additions and 36 deletions
+2 -1
View File
@@ -38,6 +38,7 @@
"@backstage/cli": "^0.1.1-alpha.8",
"@types/fs-extra": "^9.0.1",
"@types/supertest": "^2.0.8",
"supertest": "^4.0.2"
"supertest": "^4.0.2",
"yaml": "^1.10.0"
}
}
@@ -13,3 +13,37 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// import fs from 'fs-extra';
import fs from 'fs';
import {
TemplateEntityV1alpha1,
LOCATION_ANNOTATION,
} from '@backstage/catalog-model';
import { InputError } from '@backstage/backend-common';
import { PreparerBase } from './types';
export class FilePreparer implements PreparerBase {
async prepare(template: TemplateEntityV1alpha1): Promise<string> {
const location = template?.metadata?.annotations?.[LOCATION_ANNOTATION];
const [locationType, actualLocation] = (location ?? '').split(/:(.+)/);
if (locationType !== 'file') {
throw new InputError(
`Wrong location type: ${locationType}, should be 'file'`,
);
}
if (!actualLocation) {
throw new InputError(
`Couldn't parse location for template: ${template.metadata.name}`,
);
}
const templateId = template.metadata.name;
const tempDir = await fs.promises.mkdtemp(templateId);
// await fs.copy(actualLocation, tempDir);
return tempDir;
}
}
@@ -15,7 +15,10 @@
*/
import { PreparerBase, RemoteLocation, PreparerBuilder } from './types';
import { TemplateEntityV1alpha1 } from '@backstage/catalog-model';
import {
TemplateEntityV1alpha1,
LOCATION_ANNOTATION,
} from '@backstage/catalog-model';
export class Preparers implements PreparerBuilder {
private preparerMap = new Map<RemoteLocation, PreparerBase>();
@@ -38,8 +41,7 @@ export class Preparers implements PreparerBuilder {
private getPreparerKeyFromEntity(
entity: TemplateEntityV1alpha1,
): RemoteLocation {
const annotation =
entity.metadata.annotations?.['backstage.io/managed-by-location'] ?? '';
const annotation = entity.metadata.annotations?.[LOCATION_ANNOTATION] ?? '';
const [key] = annotation?.split(':');
if (!key) {
@@ -35,7 +35,7 @@ export async function createRouter(
router.post('/v1/jobs', async (_, res) => {
// TODO(blam): Actually make this function work
// res.status(201).json({ accepted: true });
res.status(201).json({ accepted: true });
const mockEntity: TemplateEntityV1alpha1 = {
apiVersion: 'backstage.io/v1alpha1',
@@ -1,6 +0,0 @@
{
"id": "mock-template-2",
"name": "mockmannen",
"description": "mock template for building stuff in backstage",
"ownerId": "blam"
}
@@ -1,7 +0,0 @@
{
"id": "mock-template",
"name": "mockmannen",
"description": "mock template for building stuff in backstage",
"ownerId": "blam",
<heres some invalid hson>
}
@@ -1,6 +0,0 @@
{
"id": "mock-template-2",
"name": "mockmannen",
"description": "mock template for building stuff in backstage",
"ownerId": "blam"
}
@@ -1,6 +0,0 @@
{
"id": "mock-template",
"name": "mockmannen",
"description": "mock template for building stuff in backstage",
"ownerId": "blam"
}
@@ -1,6 +0,0 @@
{
"id": "mock-template",
"name": "mockmannen",
"description": "mock template for building stuff in backstage",
"ownerId": "blam"
}