-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the `ng add` schematic and create separate components for webpage and newsletter mode. Closes #7
- Loading branch information
1 parent
5dc335c
commit 86e6150
Showing
24 changed files
with
426 additions
and
110 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,37 @@ | ||
import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics'; | ||
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks'; | ||
|
||
// Just return the tree | ||
export function ngAdd(): Rule { | ||
return (tree: Tree, context: SchematicContext) => { | ||
context.addTask(new NodePackageInstallTask()); | ||
return tree; | ||
import { chain } from '@angular-devkit/schematics'; | ||
|
||
import { Schema } from './schema'; | ||
import { addDependencies, addGrapesJsCssToTarget } from './utility'; | ||
|
||
export const ngAdd = | ||
(options: Schema) => async () => { | ||
|
||
const baseGrapesjsPath = 'node_modules/grapesjs/dist'; | ||
const baseGrapesjsWebpagePath = 'node_modules/grapesjs-preset-webpage/dist'; | ||
const baseGrapesjsNewsletterPath = 'node_modules/grapesjs-preset-newsletter/dist'; | ||
|
||
const grapesCssAssetPaths = [`${baseGrapesjsPath}/grapes.min.css`]; | ||
const grapesJsAssetPaths = [`${baseGrapesjsPath}/grapes.min.js`]; | ||
|
||
if (options.editorType === 'webpageEditor') { | ||
|
||
grapesCssAssetPaths.push( | ||
`${baseGrapesjsWebpagePath}/grapesjs-preset-newsletter.css` | ||
); | ||
grapesJsAssetPaths.push( | ||
`${baseGrapesjsWebpagePath}/grapesjs-preset-newsletter.min.js` | ||
); | ||
} else { | ||
grapesCssAssetPaths.push( | ||
`${baseGrapesjsNewsletterPath}/grapesjs-preset-webpage.min.css` | ||
); | ||
grapesJsAssetPaths.push( | ||
`${baseGrapesjsNewsletterPath}/grapesjs-preset-webpage.min.js` | ||
); | ||
} | ||
return chain([ | ||
addGrapesJsCssToTarget(options.project, grapesCssAssetPaths, 'styles'), | ||
addGrapesJsCssToTarget(options.project, grapesJsAssetPaths, 'scripts'), | ||
addDependencies() | ||
]); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"$id": "GrapesjsSchematicsNgAdd", | ||
"title": "ng add schematic", | ||
"type": "object", | ||
"description": "Adds appropriate css and js files to angular.json file", | ||
"properties": { | ||
"project": { | ||
"type": "string", | ||
"description": "Name of the project.", | ||
"$default": { | ||
"$source": "projectName" | ||
} | ||
}, | ||
"editorType": { | ||
"type": "string", | ||
"default": "webpageEditor", | ||
"x-prompt": { | ||
"message": "What type of editor would you like to use?", | ||
"type": "list", | ||
"items": [ | ||
{ "value": "webpageEditor", "label": "Webpage Editor" }, | ||
{ "value": "newsletterEditor", "label": "Newsletter Editor" } | ||
] | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface Schema { | ||
project: string; | ||
editorType: 'webpageEditor' | 'newsletterEditor'; | ||
} |
Oops, something went wrong.