feat: universal file for github-actions

This commit is contained in:
Ivan Shmidt
2020-09-29 12:39:14 +02:00
parent 248f615148
commit 37da165e70
8 changed files with 41 additions and 8 deletions
+16 -1
View File
@@ -77,6 +77,21 @@ export const makeConfigs = async (
mainFields.unshift('browser');
}
const commonjsInclude: Array<RegExp | string> = [/node_modules/];
// Purpose of this file is
// to be bridge between
// frontend- and backend-
// plugins' code
const UNIVERSAL_FILE = 'universal.js';
const universalPath = paths.resolveTarget(UNIVERSAL_FILE);
const universalFileExists = fs.existsSync(universalPath);
if (universalFileExists) {
mainFields.push(UNIVERSAL_FILE);
commonjsInclude.push(UNIVERSAL_FILE);
}
configs.push({
input: 'src/index.ts',
output,
@@ -88,7 +103,7 @@ export const makeConfigs = async (
}),
resolve({ mainFields }),
commonjs({
include: /node_modules/,
include: commonjsInclude,
exclude: [/\/[^/]+\.(?:stories|test)\.[^/]+$/],
}),
postcss(),
+2 -1
View File
@@ -50,6 +50,7 @@
"jest-fetch-mock": "^3.0.3"
},
"files": [
"dist"
"dist",
"universal.js"
]
}
@@ -32,7 +32,7 @@ import {
useApi,
} from '@backstage/core';
import ExternalLinkIcon from '@material-ui/icons/Launch';
import { GITHUB_ACTIONS_ANNOTATION } from '../useProjectName';
import { GITHUB_ACTIONS_ANNOTATION } from '../../../universal';
const useStyles = makeStyles<Theme>({
externalLinkIcon: {
@@ -19,7 +19,7 @@ import { Routes, Route } from 'react-router';
import { rootRouteRef, buildRouteRef } from '../plugin';
import { WorkflowRunDetails } from './WorkflowRunDetails';
import { WorkflowRunsTable } from './WorkflowRunsTable';
import { GITHUB_ACTIONS_ANNOTATION } from './useProjectName';
import { GITHUB_ACTIONS_ANNOTATION } from '../../universal';
import { WarningPanel } from '@backstage/core';
export const isPluginApplicableToEntity = (entity: Entity) =>
@@ -16,8 +16,7 @@
import { useAsync } from 'react-use';
import { Entity } from '@backstage/catalog-model';
export const GITHUB_ACTIONS_ANNOTATION = 'github.com/project-slug';
import { GITHUB_ACTIONS_ANNOTATION } from '../../universal';
export const useProjectName = (entity: Entity) => {
const { value, loading, error } = useAsync(async () => {
-1
View File
@@ -18,4 +18,3 @@ export { plugin } from './plugin';
export * from './api';
export { Router, isPluginApplicableToEntity } from './components/Router';
export * from './components/Cards';
export { GITHUB_ACTIONS_ANNOTATION } from './components/useProjectName';
+18
View File
@@ -0,0 +1,18 @@
/*
* 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.
*/
// This file is shared between frontend and backend plugins
module.exports.GITHUB_ACTIONS_ANNOTATION = 'github.com/project-slug';
@@ -19,7 +19,8 @@ import { TemplaterBase, TemplaterRunOptions } from '..';
import path from 'path';
import { TemplaterRunResult } from '../types';
import * as yaml from 'yaml';
import { GITHUB_ACTIONS_ANNOTATION } from '@backstage/plugin-github-actions';
// eslint-disable-next-line monorepo/no-internal-import
import { GITHUB_ACTIONS_ANNOTATION } from '@backstage/plugin-github-actions/universal';
export class CreateReactAppTemplater implements TemplaterBase {
public async run(options: TemplaterRunOptions): Promise<TemplaterRunResult> {