-
Notifications
You must be signed in to change notification settings - Fork 73
feat(templates): adding external templates #2215
Changes from all commits
949d11f
4ca9416
a76f94f
f12aad0
a2b576f
8b103c1
f6a8399
c2d84c6
b8d9c69
5dabe76
1910103
d1d9974
1fbba2c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Using Graphback With Your Own Templates | ||
|
||
In case you want to use some other templates than the ones offered, Graphback also supports adding your templates. The process is fairly simple and is as follows: | ||
|
||
## Step 1: Creating an object for your template | ||
|
||
To add your template, you first need to have it in the form of an object which you'll later add to an array. This is best explained by an example: | ||
|
||
Let's say you have a template which you want to name `a-sample-template` and the files for it are located in the repository `https://github.com/sample-user/sample-project`. Then the object for your template would look like this: | ||
|
||
``` | ||
{ | ||
"name": "a-sample-template", | ||
"description": "Fetching current templates in the sample template", | ||
"repos": [ | ||
{ | ||
"uri": "https://github.com/sample-user/sample-project", | ||
"branch": "specify-desired-branch", | ||
"path": "exact-path-of-the-directory", | ||
"mountpath": "client" | ||
}, | ||
{ | ||
"uri": "https://github.com/sample-user/sample-project", | ||
"branch": "specify-desired-branch", | ||
"path": "exact-path-of-the-directory" | ||
} | ||
], | ||
} | ||
``` | ||
|
||
Note that you can specify as many repositories as you want (with the desired branch and mount path). Files from the specified repositories would be picked up for your template. | ||
|
||
## Step 2: Adding your template object | ||
|
||
In the packages directory of Graphback you'll find the file `community-templates.ts`. This exports an array called `externalTemplates`. It is in this array that you should add your template object for it to be picked up by the CLI. So the final file would look something like this: | ||
|
||
``` | ||
export default externalTemplates = [ | ||
{ | ||
"name": "a-sample-template", | ||
"description": "Fetching current templates in the sample template", | ||
"repos": [ | ||
{ | ||
"uri": "https://github.com/sample-user/sample-project", | ||
"branch": "specify-desired-branch", | ||
"path": "exact-path-of-the-directory", | ||
"mountpath": "client" | ||
}, | ||
{ | ||
"uri": "https://github.com/sample-user/sample-project", | ||
"branch": "specify-desired-branch", | ||
"path": "exact-path-of-the-directory" | ||
} | ||
], | ||
} | ||
] | ||
``` | ||
|
||
With this, you're good to go. Yes, it's that simple! If you still have any doubts or are facing problems feel free to reach out to us! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default externalTemplates = []; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
import { createWriteStream, mkdirSync, existsSync } from 'fs'; | ||
import chalk from 'chalk'; | ||
import ora from 'ora' | ||
import * as github from 'parse-github-url'; | ||
import * as request from 'request'; | ||
import github from 'parse-github-url'; | ||
import request from 'request'; | ||
import * as tar from 'tar'; | ||
import * as tmp from 'tmp'; | ||
import externalTemplates from '../../../community-templates'; | ||
import { Template, TemplateRepository } from './templateMetadata'; | ||
|
||
/** | ||
* available templates | ||
*/ | ||
export const allTemplates: Template[] = [ | ||
export let allTemplates: Template[] = [ | ||
{ | ||
name: 'apollo-fullstack-react-postgres-ts', | ||
description: 'Apollo GraphQL Server connecting to Postgres database and React client using TypeScript', | ||
|
@@ -113,6 +114,12 @@ export const allTemplates: Template[] = [ | |
} | ||
]; | ||
|
||
const externalTemplatesArray: Template[] = externalTemplates; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would also improve how we present those templates - Graphback and community templates when executing create-graphback cmd There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for reviewing the code @wtrocki. Do you have any suggestions about how I could go on implementing this? All templates must still reside in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Experiment with this methods. Now all will be printed there. |
||
externalTemplatesArray.forEach( | ||
template => (template.name = 'Community: ' + template.name) | ||
); | ||
allTemplates = allTemplates.concat(externalTemplatesArray); | ||
|
||
/** | ||
* information about repository | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be ts file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean the url should point to a particular ts file on the person's repository?