Skip to content

Instantly share code, notes, and snippets.

@AvocadoVenom
AvocadoVenom / folder.index.ts
Last active December 10, 2019 23:14
Angular schematic : create an empty folder with .gitkeep file
export function scaffoldSchematics(options: any): Rule {
return (tree: Tree, _context: SchematicContext) => {
return tree.create('path/to/folder/.gitkeep'), '');
};
}
@AvocadoVenom
AvocadoVenom / collection.json
Last active December 10, 2019 23:24
Angular schematic : schema
{
"$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json",
"schematics": {
"scaffold-schematics": {
"description": "A schematic to scaffold your project.",
"factory": "./scaffold-schematics/index#scaffoldSchematics",
"schema": "./scaffold-schematics/schema.json"
}
}
}
@AvocadoVenom
AvocadoVenom / data-folders.index.ts
Last active December 12, 2019 22:00
Angular schematic : data folders
function createDataRelatedFolders(options: ModuleOptions): Rule {
return (tree: Tree, _: SchematicContext) => {
tree.create(normalize(`${options.name}/data/models/.gitkeep`), '');
tree.create(normalize(`${options.name}/data/services/.gitkeep`), '');
return tree;
};
}
@AvocadoVenom
AvocadoVenom / store.index.ts
Last active December 12, 2019 22:00
Angular schematic : store folder
function createStoreFolder(options: ModuleOptions): Rule {
return (tree: Tree, _: SchematicContext) => {
tree.create(normalize(`${options.name}/data/store/.gitkeep`), '');
return tree;
};
}
@AvocadoVenom
AvocadoVenom / adp-components.index.ts
Last active December 12, 2019 22:00
Angular schematic : ADP folders
function createAtomicDesignPatternFolders(options: ModuleOptions): Rule {
return (tree: Tree, _: SchematicContext) => {
tree.create(normalize(`${options.name}/components/atoms/.gitkeep`), '');
tree.create(normalize(`${options.name}/components/molecules/.gitkeep`), '');
tree.create(normalize(`${options.name}/components/organisms/.gitkeep`), '');
tree.create(normalize(`${options.name}/components/pages/.gitkeep`), '');
return tree;
};
}
@AvocadoVenom
AvocadoVenom / components-module.index.ts
Last active December 12, 2019 22:00
Creating a components module file
function createComponentsModuleFileDefinition(options: ModuleOptions): Rule {
const templateSource = apply(url('./files'), [
filter(path => path.endsWith('/components.module.ts.template')),
applyTemplates({
...strings,
...options
}),
renameTemplateFiles(),
move(normalize(`${options.name}/components`))
]);
@AvocadoVenom
AvocadoVenom / __name@dasherize__.module.ts.template
Last active December 12, 2019 22:00
Angular schematics : creating main module from template
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ComponentsModule } from './components/components.module';
@NgModule({
declarations: [],
imports: [CommonModule, ComponentsModule]
})
export class <%= classify(name) %>Module { }
@AvocadoVenom
AvocadoVenom / final.index.ts
Last active December 12, 2019 21:59
Angular schematics : final execution method
export function scaffoldSchematics(options: ModuleOptions): Rule {
return chain([
executeComponentsTasks(options),
createDataRelatedFolders(options),
options.useStore ? createStoreFolder(options) : noop(),
createMainModuleFileDefinition(options)
]);
}
@AvocadoVenom
AvocadoVenom / data.actions.ts
Created February 20, 2020 11:47
A data store actions definition file with Load and Set actions
import { Action } from '@ngrx/store';
export const LOAD_DATA = '[Data] LOAD_DATA';
export const SET_DATA = '[Data] SET_DATA';
export class LoadData implements Action {
readonly type = LOAD_DATA;
}
export class SetData implements Action {
@AvocadoVenom
AvocadoVenom / data.effects.ts
Created February 20, 2020 11:52
A data store effects definition file
import { Injectable } from '@angular/core';
import { Store } from '@ngrx/store';
import { Effect, ofType, Actions } from '@ngrx/effects';
import { switchMap, map, catchError } from 'rxjs/operators';
import { of } from 'rxjs';
import * as fromApp from '@store/app.reducer';
import * as Actions from '@store/data/data.actions';
import { DataService } from '@app/data/services/data/data.service';