Skip to content

Commit

Permalink
feat(proj-plugins): cross-check for project-plugins and project-gener…
Browse files Browse the repository at this point in the history
…ators (#534)
  • Loading branch information
JayaKrishnaNamburu committed Feb 3, 2021
1 parent 1b2a976 commit 909285c
Show file tree
Hide file tree
Showing 16 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/teleport-project-generator-angular/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const createAngularProjectGenerator = () => {
const pagesModuleGeneratorAngularPlugin = createAngularModulePlugin({ moduleType: 'page' })

const generator = createProjectGenerator({
id: 'teleport-project-angular',
components: {
generator: createAngularComponentGenerator,
mappings: [AngularProjectMapping as Mapping],
Expand Down
1 change: 1 addition & 0 deletions packages/teleport-project-generator-gatsby/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { createCustomHTMLEntryFile, styleSheetDependentConfigGenerator } from '.

const createGatsbyProjectGenerator = () => {
const generator = createProjectGenerator({
id: 'teleport-project-gatsby',
components: {
generator: createCustomReactGatsbyComponentGenerator,
path: ['src', 'components'],
Expand Down
1 change: 1 addition & 0 deletions packages/teleport-project-generator-gridsome/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const createGridsomeProjectGenerator = () => {
})

const generator = createProjectGenerator({
id: 'teleport-project-gridsome',
components: {
generator: createVueComponentGenerator,
mappings: [GridsomeProjectMapping as Mapping],
Expand Down
1 change: 1 addition & 0 deletions packages/teleport-project-generator-next/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const createNextProjectGenerator = () => {
})

const generator = createProjectGenerator({
id: 'teleport-project-next',
style: ReactStyleVariation.StyledJSX,
components: {
generator: createReactComponentGenerator,
Expand Down
1 change: 1 addition & 0 deletions packages/teleport-project-generator-nuxt/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const createNuxtProjectGenerator = () => {
})

const generator = createProjectGenerator({
id: 'teleport-project-nuxt',
components: {
generator: createVueComponentGenerator,
mappings: [NuxtMapping as Mapping],
Expand Down
1 change: 1 addition & 0 deletions packages/teleport-project-generator-preact/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const createPreactProjectGenerator = () => {
const routerPlugin = createReactAppRoutingPlugin({ flavor: 'preact' })

const generator = createProjectGenerator({
id: 'teleport-project-preact',
style: PreactStyleVariation.CSSModules,
components: {
generator: createPreactComponentGenerator,
Expand Down
1 change: 1 addition & 0 deletions packages/teleport-project-generator-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import ReactTemplate from './project-template'

const createReactProjectGenerator = () => {
const generator = createProjectGenerator({
id: 'teleport-project-react',
style: ReactStyleVariation.CSSModules,
components: {
generator: createReactComponentGenerator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import ReactNativeTemplate from './reactnative-project-template'

const createReactNativeProjectGenerator = () => {
const generator = createProjectGenerator({
id: 'teleport-project-react-native',
components: {
generator: createReactNativeComponentGenerator,
mappings: [ReactNativeProjectMapping as Mapping],
Expand Down
1 change: 1 addition & 0 deletions packages/teleport-project-generator-stencil/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const createStencilProjectGenerator = () => {
})

const generator = createProjectGenerator({
id: 'teleport-project-stencil',
components: {
generator: createStencilComponentGenerator,
mappings: [StencilProjectMapping as Mapping],
Expand Down
1 change: 1 addition & 0 deletions packages/teleport-project-generator-vue/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const createVueProjectGenerator = () => {
const vueHeadConfigPlugin = createVueHeadConfigPlugin({ metaObjectKey: 'metaInfo' })

const generator = createProjectGenerator({
id: 'teleport-project-vue',
components: {
generator: createVueComponentGenerator,
mappings: [VueProjectMapping as Mapping],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class PluginGatsbyStyledComponents implements ProjectPlugin {
async runBefore(structure: ProjectPluginStructure) {
const { strategy } = structure

if (strategy.id !== 'teleport-project-gatsby') {
throw new Error('Plugin can be used only with teleport-project-gatsby')
}

strategy.style = GatsbyStyleVariation.StyledComponents
delete strategy.framework.config
if (strategy?.projectStyleSheet?.generator) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class PluginNextCSSModules implements ProjectPlugin {
async runBefore(structure: ProjectPluginStructure) {
const { strategy } = structure

if (strategy.id !== 'teleport-project-next') {
throw new Error('Plugin can be used only with teleport-project-next')
}

strategy.style = ReactStyleVariation.CSSModules
if (strategy?.projectStyleSheet?.generator) {
strategy.projectStyleSheet.plugins = [createStyleSheetPlugin({ moduleExtension: true })]
Expand Down
4 changes: 4 additions & 0 deletions packages/teleport-project-plugin-next-react-jss/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class PluginNextReactJSS implements ProjectPlugin {
async runBefore(structure: ProjectPluginStructure) {
const { strategy } = structure

if (strategy.id !== 'teleport-project-next') {
throw new Error('Plugin can be used only with teleport-project-next')
}

strategy.style = ReactStyleVariation.ReactJSS
if (strategy?.projectStyleSheet?.generator) {
strategy.projectStyleSheet.plugins = [createStyleSheetPlugin(), importStatementsPlugin]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class PluginNextStyledComponents implements ProjectPlugin {
async runBefore(structure: ProjectPluginStructure) {
const { strategy } = structure

if (strategy.id !== 'teleport-project-next') {
throw new Error('Plugin can be used only with teleport-project-next')
}

strategy.style = ReactStyleVariation.StyledComponents
if (strategy?.projectStyleSheet?.generator) {
strategy.projectStyleSheet.plugins = [createStyleSheetPlugin(), importStatementsPlugin]
Expand Down
2 changes: 1 addition & 1 deletion packages/teleport-test/src/standalone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const reactProjectUIDL = (reactProjectJSON as unknown) as ProjectUIDL
const assetFile = readFileSync(join(__dirname, 'asset.png'))
const base64File = Buffer.from(assetFile).toString('base64')
const packerOptions: PackerOptions = {
publisher: PublisherType.CODESANDBOX,
publisher: PublisherType.DISK,
projectType: ProjectType.REACT,
publishOptions: {
outputPath: 'dist',
Expand Down
1 change: 1 addition & 0 deletions packages/teleport-types/src/generators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export interface GeneratorFactoryParams {
export type ComponentGeneratorInstance = (params?: GeneratorFactoryParams) => ComponentGenerator

export interface ProjectStrategy {
id: string
style?: StyleVariation
components: {
generator: ComponentGeneratorInstance
Expand Down

0 comments on commit 909285c

Please sign in to comment.