diff --git a/plugins/scaffolder-backend/src/index.ts b/plugins/scaffolder-backend/src/index.ts index 92c9090376..8a27ffd658 100644 --- a/plugins/scaffolder-backend/src/index.ts +++ b/plugins/scaffolder-backend/src/index.ts @@ -15,3 +15,4 @@ */ export { router } from './plugin'; +export const createScaffolder = () => {}; diff --git a/plugins/scaffolder-backend/src/lib/logger.ts b/plugins/scaffolder-backend/src/lib/logger.ts new file mode 100644 index 0000000000..c3a4a4e26c --- /dev/null +++ b/plugins/scaffolder-backend/src/lib/logger.ts @@ -0,0 +1,41 @@ +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import * as winston from 'winston'; + +export const logger = winston.createLogger({ + level: 'info', + format: winston.format.json(), + transports: [ + // + // - Write all logs with level `error` and below to `error.log` + // - Write all logs with level `info` and below to `combined.log` + // + new winston.transports.File({ filename: 'error.log', level: 'error' }), + new winston.transports.File({ filename: 'combined.log' }), + ], +}); + +// +// If we're not in production then log to the `console` with the format: +// `${info.level}: ${info.message} JSON.stringify({ ...rest }) ` +// +if (process.env.NODE_ENV !== 'production') { + logger.add( + new winston.transports.Console({ + format: winston.format.simple(), + }), + ); +} diff --git a/plugins/scaffolder-backend/src/lib/repo/disk.ts b/plugins/scaffolder-backend/src/lib/repo/disk.ts index 60eb46b9c6..57a2c3f013 100644 --- a/plugins/scaffolder-backend/src/lib/repo/disk.ts +++ b/plugins/scaffolder-backend/src/lib/repo/disk.ts @@ -15,7 +15,7 @@ */ import glob from 'glob'; -import * as fs from 'fs-extra'; +import fs from 'fs-extra'; import { logger } from 'lib/logger'; import { Template, RepositoryBase as Base } from '.'; @@ -28,11 +28,12 @@ export class DiskRepository implements Base { private repository: Template[] = []; private localIndex: DiskIndexEntry[] = []; - constructor(private repoDir = `${__dirname}/templates`) { - this.reindex(); - } - + constructor(private repoDir = `${__dirname}/templates`) {} public async list(): Promise { + if (this.repository.length === 0) { + await this.reindex(); + } + return this.repository; } diff --git a/plugins/scaffolder-backend/src/lib/templater/cookiecutter.ts b/plugins/scaffolder-backend/src/lib/templater/cookiecutter.ts index d3d84c6e12..f998e7d854 100644 --- a/plugins/scaffolder-backend/src/lib/templater/cookiecutter.ts +++ b/plugins/scaffolder-backend/src/lib/templater/cookiecutter.ts @@ -15,7 +15,7 @@ import { TemplaterBase, TemplaterRunOptions } from '.'; * See the License for the specific language governing permissions and * limitations under the License. */ -import * as fs from 'fs-extra'; +import fs from 'fs-extra'; class CookieCutter implements TemplaterBase { public async run(options: TemplaterRunOptions): Promise {