Skip to content

Commit

Permalink
Merge pull request #17 from olliethedev/feat/blog-plugin
Browse files Browse the repository at this point in the history
feat: add command logic
  • Loading branch information
olliethedev authored Oct 26, 2023
2 parents e27f02a + 8ae9fa0 commit d006043
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 17 deletions.
51 changes: 43 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.1.13",
"version": "1.1.14",
"private": true,
"workspaces": [
"./packages/*"
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-graphql-amplifiers-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@amplifiers/amplify-graphql-amplifiers-core",
"version": "1.1.13",
"version": "1.1.14",
"description": "Amplify GraphQL @createModel transformer. This directive is intended to be used for creating a new model once a Cognito Event is fired.",
"keywords": [
"aws",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@amplifiers/amplify-graphql-create-model-transformer",
"version": "1.1.13",
"version": "1.1.14",
"description": "Amplify GraphQL @createModel transformer. This directive is intended to be used for creating a new model once a Cognito Event is fired.",
"keywords": [
"aws",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@amplifiers/amplify-graphql-process-image-transformer",
"version": "1.1.13",
"version": "1.1.14",
"description": "This directive allows you to process images.",
"keywords": [
"aws",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@amplifiers/amplify-graphql-send-email-transformer",
"version": "1.1.13",
"version": "1.1.14",
"description": "Amplify GraphQL @sendEmail transformer.",
"keywords": [
"aws",
Expand Down
62 changes: 60 additions & 2 deletions packages/amplify-util-blog/commands/add.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
const fs = require("fs");
const fs = require("fs-extra");
const path = require("path");
const eventName = "add";

async function run(context) {
context.print.info(`Event handler ${eventName} is running.`);
updateSchema(context);
updateUIElements(context);
context.print.info(`Done running ${eventName}`);
}

function updateSchema(context) {
// Get the API name from the context
const apiMeta = context.amplify.getProjectMeta().api;
console.log(apiMeta);
Expand Down Expand Up @@ -38,7 +43,9 @@ async function run(context) {
const blogSchemaStart = schema.indexOf("# BLOG SCHEMA START.");
const blogSchemaEnd = schema.indexOf("# BLOG SCHEMA END.");
if (blogSchemaStart !== -1 && blogSchemaEnd !== -1) {
context.print.info("Blog schema already exists in schema.graphql");
context.print.info(
"Post and Tag models already exist in schema.graphql. Remove them and run `amplify plugin amplify-util-blog add` again."
);
return;
}
const blogSchema = `
Expand Down Expand Up @@ -79,6 +86,57 @@ async function run(context) {
context.print.info("Merged schema.graphql and blogSchema.graphql");
}

function updateUIElements(context) {
const projectConfigPath =
context.amplify.pathManager.getProjectConfigFilePath();

const projectConfig = JSON.parse(fs.readFileSync(projectConfigPath, "utf8"));

context.print.info(projectConfig);

if (projectConfig.frontend !== "javascript") {
context.print.info(
"Blog Plugin only supports javascript/typescript front-end project for now"
);
return;
}

if (projectConfig.javascript.framework !== "react") {
context.print.info(
"Blog Plugin only supports react front-end project for now"
);
return;
}

const srcDir = projectConfig.javascript.config.SourceDir;

const uiComponentsDestination = path.join(
context.amplify.pathManager.searchProjectRootPath(),
srcDir,
"ui-components",
"blog"
);

if (fs.existsSync(uiComponentsDestination)) {
context.print.info(
"Blog folder already exists in ui-components. Remove it and run `amplify plugin amplify-util-blog add` again."
);
return;
}

const uiComponentsSource = path.join(
__dirname,
"..",
"ui-components",
"blog"
);

context.print.info(uiComponentsSource);
context.print.info(uiComponentsDestination);

fs.copySync(uiComponentsSource, uiComponentsDestination);
}

module.exports = {
run,
};
13 changes: 11 additions & 2 deletions packages/amplify-util-blog/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
{
"name": "@amplifiers/amplify-util-blog",
"version": "1.1.13",
"version": "1.1.14",
"description": "",
"main": "index.js",
"files": [
"commands",
"event-handlers",
"ui-components",
"amplify-plugin.json"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"compile": "echo WIP"
},
"author": "",
"license": "ISC"
"license": "ISC",
"dependencies": {
"fs-extra": "^11.1.1"
}
}
19 changes: 19 additions & 0 deletions packages/amplify-util-blog/ui-components/blog/Page.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/***************************************************************************
* The contents of this file were generated with Amplify Studio. *
* Please refrain from making any modifications to this file. *
* Any changes to this file will be overwritten when running amplify pull. *
**************************************************************************/

import * as React from "react";
import { EscapeHatchProps } from "@aws-amplify/ui-react/internal";
import { FlexProps } from "@aws-amplify/ui-react";
export declare type PrimitiveOverrideProps<T> = Partial<T> & React.DOMAttributes<HTMLDivElement>;
export declare type PageOverridesProps = {
Page?: PrimitiveOverrideProps<FlexProps>;
"Frame 1"?: PrimitiveOverrideProps<FlexProps>;
"Frame 2"?: PrimitiveOverrideProps<FlexProps>;
} & EscapeHatchProps;
export declare type PageProps = React.PropsWithChildren<Partial<FlexProps> & {
overrides?: PageOverridesProps | undefined | null;
}>;
export default function Page(props: PageProps): React.ReactElement;
58 changes: 58 additions & 0 deletions packages/amplify-util-blog/ui-components/blog/Page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/***************************************************************************
* The contents of this file were generated with Amplify Studio. *
* Please refrain from making any modifications to this file. *
* Any changes to this file will be overwritten when running amplify pull. *
**************************************************************************/

/* eslint-disable */
import * as React from "react";
import { getOverrideProps } from "@aws-amplify/ui-react/internal";
import { Flex } from "@aws-amplify/ui-react";
export default function Page(props) {
const { overrides, ...rest } = props;
return (
<Flex
gap="0"
direction="column"
width="1440px"
height="unset"
justifyContent="flex-start"
alignItems="flex-start"
overflow="hidden"
position="relative"
padding="0px 0px 0px 0px"
backgroundColor="rgba(250,250,250,1)"
{...getOverrideProps(overrides, "Page")}
{...rest}
>
<Flex
gap="0"
direction="row"
width="unset"
height="unset"
justifyContent="flex-start"
alignItems="flex-start"
overflow="hidden"
shrink="0"
alignSelf="stretch"
position="relative"
padding="0px 0px 0px 0px"
{...getOverrideProps(overrides, "Frame 1")}
></Flex>
<Flex
gap="0"
direction="row"
width="unset"
height="unset"
justifyContent="flex-start"
alignItems="flex-start"
overflow="hidden"
shrink="0"
alignSelf="stretch"
position="relative"
padding="0px 0px 0px 0px"
{...getOverrideProps(overrides, "Frame 2")}
></Flex>
</Flex>
);
}

0 comments on commit d006043

Please sign in to comment.