-
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.
feat: add schematics and split editors to web and newletter
Closes #7
- Loading branch information
Showing
19 changed files
with
381 additions
and
86 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,36 @@ | ||
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 { addDependencies, addGrapesJsCssToTarget } from './utility'; | ||
|
||
export const ngAdd = | ||
(options: any) => async () => { | ||
|
||
const grapesCssAssetPaths = []; | ||
const grapesJsAssetPaths = []; | ||
|
||
if (options.editorType === 'webpage editor') { | ||
|
||
grapesCssAssetPaths.push( | ||
'node_modules/grapesjs/dist/css/grapes.min.css', | ||
'node_modules/grapesjs-preset-newsletter/dist/grapesjs-preset-newsletter.css' | ||
); | ||
grapesJsAssetPaths.push( | ||
'node_modules/grapesjs/dist/grapes.min.js', | ||
'node_modules/grapesjs-preset-newsletter/dist/grapesjs-preset-newsletter.min.js' | ||
); | ||
} else { | ||
grapesCssAssetPaths.push( | ||
'node_modules/grapesjs/dist/css/grapes.min.css', | ||
'node_modules/grapesjs-preset-webpage/dist/grapesjs-preset-webpage.min.css' | ||
); | ||
grapesJsAssetPaths.push( | ||
'node_modules/grapesjs/dist/grapes.min.js', | ||
'node_modules/grapesjs-preset-webpage/dist/grapesjs-preset-webpage.min.js' | ||
); | ||
} | ||
return chain([ | ||
addGrapesJsCssToTarget(options.project, 'build', grapesCssAssetPaths, 'styles'), | ||
addGrapesJsCssToTarget(options.project, 'build', 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": "webpage editor", | ||
"x-prompt": { | ||
"message": "What type of editor would you like to use?", | ||
"type": "list", | ||
"items": [ | ||
{ "value": "webpage editor", "label": "Webpage Editor" }, | ||
{ "value": "newsletter editor", "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,63 @@ | ||
import { JsonValue } from '@angular-devkit/core'; | ||
import { ProjectDefinition } from '@angular-devkit/core/src/workspace'; | ||
import { SchematicsException, Rule, Tree, SchematicContext } from '@angular-devkit/schematics'; | ||
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks'; | ||
import { updateWorkspace } from '@schematics/angular/utility/workspace'; | ||
|
||
export function getProjectTargetOptions( | ||
project: ProjectDefinition, | ||
buildTarget: string | ||
): Record<string, JsonValue | undefined> { | ||
const options = project.targets?.get(buildTarget)?.options; | ||
|
||
if (!options) { | ||
throw new SchematicsException( | ||
`Cannot determine project target configuration for: ${buildTarget}.` | ||
); | ||
} | ||
|
||
return options; | ||
} | ||
|
||
export function addGrapesJsCssToTarget( | ||
projectName: string, | ||
targetName: 'test' | 'build', | ||
assetPaths: string [], | ||
targetAsset: 'styles' | 'scripts' | ||
) { | ||
return updateWorkspace(workspace => { | ||
|
||
const project = workspace.projects.get(projectName); | ||
|
||
if (!projectName && typeof workspace.extensions['defaultProject'] === 'string') { | ||
projectName = workspace.extensions['defaultProject']; | ||
} | ||
|
||
if (!project) { | ||
return; | ||
} | ||
|
||
const targetOptions = getProjectTargetOptions(project, targetName); | ||
const formattedExistingAssets = targetOptions[targetAsset] as (string | {input: string})[]; | ||
|
||
if (!formattedExistingAssets) { | ||
targetOptions[targetAsset] = assetPaths; | ||
} else { | ||
const existingStyles = formattedExistingAssets.map(s => (typeof s === 'string' ? s : s.input)); | ||
|
||
assetPaths.forEach(assetPath => { | ||
if (!existingStyles.includes(assetPath)) { | ||
formattedExistingAssets.push(assetPath); | ||
} | ||
}); | ||
|
||
} | ||
}); | ||
} | ||
|
||
export function addDependencies(): Rule { | ||
return (tree: Tree, context: SchematicContext) => { | ||
context.addTask(new NodePackageInstallTask()); | ||
return tree; | ||
}; | ||
} |
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,12 @@ | ||
export interface Editor { | ||
} | ||
|
||
export interface Config { | ||
container: string; | ||
plugins: string[]; | ||
components: string; | ||
pluginsOpts: Record<string, any>; | ||
storageManager: { | ||
id: string | ||
}; | ||
} |
Oops, something went wrong.