Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@studiohyperdrive/howto-schematics

Package Overview
Dependencies
Maintainers
9
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@studiohyperdrive/howto-schematics - npm Package Compare versions

Comparing version 1.0.0-2 to 1.0.0

src/rules/generate-docs.d.ts

2

package.json
{
"name": "@studiohyperdrive/howto-schematics",
"version": "1.0.0-2",
"version": "1.0.0",
"description": "A blank schematics",

@@ -5,0 +5,0 @@ "scripts": {

@@ -1,7 +0,6 @@

import { Rule } from '@angular-devkit/schematics';
export declare function atomSchematic({ name, module, style, spec, }: {
export declare const atomSchematic: ({ name, module, style, spec, }: {
name: string;
module?: string;
style?: string;
spec?: boolean;
}): Rule;
module?: string | undefined;
style?: string | undefined;
spec?: boolean | undefined;
}) => import("@angular-devkit/schematics").Rule;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const schematics_1 = require("@angular-devkit/schematics");
const workspace_1 = require("../utils/workspace");
const generate_component_1 = require("../rules/generate-component");
const generate_type_1 = require("../rules/generate-type");
const component_1 = require("../types/component");
const generate_styleguide_1 = require("../rules/generate-styleguide");
const generate_styleguide_component_1 = require("../rules/generate-styleguide-component");
const setup_root_component_1 = require("../rules/setup-root-component");
const update_root_component_1 = require("../rules/update-root-component");
const setup_styleguide_component_1 = require("../rules/setup-styleguide-component");
const update_routes_1 = require("../rules/update-routes");
function atomSchematic({ name, module = 'ui', style = 'scss', spec = true, }) {
return (tree) => {
if (!name) {
throw new schematics_1.SchematicsException('Option (name) is required!');
}
const workspace = workspace_1.readWorkspace(tree);
const projectConfig = workspace.projects['ui'];
if (!projectConfig) {
throw new schematics_1.SchematicsException(`Could not find project (ui) in workspace`);
}
const ruleOptions = {
name,
project: 'ui',
module,
path: `${projectConfig.sourceRoot}/lib/atoms`,
prefix: component_1.ComponentPrefixes.atom,
export: true,
style,
styleext: style,
spec,
type: component_1.ComponentTypes.atom,
};
const styleguideOptions = Object.assign({}, ruleOptions, { project: 'styleguide', module: 'atoms', prefix: 'sg' });
// TODO: figure out how to trigger build after generation
return schematics_1.chain([
...generate_component_1.generateComponent(ruleOptions, workspace),
...generate_styleguide_1.generateStyleguide(styleguideOptions, workspace, tree),
...generate_styleguide_component_1.generateStyleguideComponent(styleguideOptions, workspace),
...setup_styleguide_component_1.setupStyleguideComponent(styleguideOptions),
...setup_root_component_1.setupRootComponent(styleguideOptions, workspace),
...update_root_component_1.updateRootComponent(styleguideOptions, workspace),
...update_routes_1.updateRoutes(styleguideOptions),
]);
};
}
exports.atomSchematic = atomSchematic;
exports.atomSchematic = generate_type_1.typeSchematic(component_1.ComponentTypes.atom);
//# sourceMappingURL=index.js.map

@@ -1,7 +0,6 @@

import { Rule } from '@angular-devkit/schematics';
export declare function moleculeSchematic({ name, module, style, spec, }: {
export declare const moleculeSchematic: ({ name, module, style, spec, }: {
name: string;
module?: string;
style?: string;
spec?: boolean;
}): Rule;
module?: string | undefined;
style?: string | undefined;
spec?: boolean | undefined;
}) => import("@angular-devkit/schematics").Rule;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const schematics_1 = require("@angular-devkit/schematics");
const workspace_1 = require("../utils/workspace");
const generate_component_1 = require("../rules/generate-component");
const generate_type_1 = require("../rules/generate-type");
const component_1 = require("../types/component");
const generate_styleguide_1 = require("../rules/generate-styleguide");
const generate_styleguide_component_1 = require("../rules/generate-styleguide-component");
const setup_styleguide_component_1 = require("../rules/setup-styleguide-component");
const update_root_component_1 = require("../rules/update-root-component");
const update_routes_1 = require("../rules/update-routes");
const setup_root_component_1 = require("../rules/setup-root-component");
function moleculeSchematic({ name, module = 'ui', style = 'scss', spec = true, }) {
return (tree) => {
if (!name) {
throw new schematics_1.SchematicsException('Option (name) is required!');
}
const workspace = workspace_1.readWorkspace(tree);
const projectConfig = workspace.projects['ui'];
if (!projectConfig) {
throw new schematics_1.SchematicsException(`Could not find project (ui) in workspace`);
}
const ruleOptions = {
name,
project: 'ui',
module,
path: `${projectConfig.sourceRoot}/lib/molecules`,
prefix: component_1.ComponentPrefixes.molecule,
export: true,
style,
styleext: style,
spec,
type: component_1.ComponentTypes.molecule,
};
const styleguideOptions = Object.assign({}, ruleOptions, { project: 'styleguide', module: 'molecules', prefix: 'sg' });
// TODO: figure out how to trigger build after generation
return schematics_1.chain([
...generate_component_1.generateComponent(ruleOptions, workspace),
...generate_styleguide_1.generateStyleguide(styleguideOptions, workspace, tree),
...generate_styleguide_component_1.generateStyleguideComponent(styleguideOptions, workspace),
...setup_styleguide_component_1.setupStyleguideComponent(styleguideOptions),
...setup_root_component_1.setupRootComponent(styleguideOptions, workspace),
...update_root_component_1.updateRootComponent(styleguideOptions, workspace),
...update_routes_1.updateRoutes(styleguideOptions),
]);
};
}
exports.moleculeSchematic = moleculeSchematic;
exports.moleculeSchematic = generate_type_1.typeSchematic(component_1.ComponentTypes.molecule);
//# sourceMappingURL=index.js.map

@@ -1,7 +0,6 @@

import { Rule } from '@angular-devkit/schematics';
export declare function organismSchematic({ name, module, style, spec, }: {
export declare const organismSchematic: ({ name, module, style, spec, }: {
name: string;
module?: string;
style?: string;
spec?: boolean;
}): Rule;
module?: string | undefined;
style?: string | undefined;
spec?: boolean | undefined;
}) => import("@angular-devkit/schematics").Rule;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const schematics_1 = require("@angular-devkit/schematics");
const workspace_1 = require("../utils/workspace");
const generate_component_1 = require("../rules/generate-component");
const generate_type_1 = require("../rules/generate-type");
const component_1 = require("../types/component");
const generate_styleguide_1 = require("../rules/generate-styleguide");
const generate_styleguide_component_1 = require("../rules/generate-styleguide-component");
const setup_styleguide_component_1 = require("../rules/setup-styleguide-component");
const update_root_component_1 = require("../rules/update-root-component");
const update_routes_1 = require("../rules/update-routes");
const setup_root_component_1 = require("../rules/setup-root-component");
function organismSchematic({ name, module = 'ui', style = 'scss', spec = true, }) {
return (tree) => {
if (!name) {
throw new schematics_1.SchematicsException('Option (name) is required!');
}
const workspace = workspace_1.readWorkspace(tree);
const projectConfig = workspace.projects['ui'];
if (!projectConfig) {
throw new schematics_1.SchematicsException(`Could not find project (ui) in workspace`);
}
const ruleOptions = {
name,
project: 'ui',
module,
path: `${projectConfig.sourceRoot}/lib/organisms`,
prefix: component_1.ComponentPrefixes.organism,
export: true,
style,
styleext: style,
spec,
type: component_1.ComponentTypes.organism,
};
const styleguideOptions = Object.assign({}, ruleOptions, { project: 'styleguide', module: 'organisms', prefix: 'sg' });
// TODO: figure out how to trigger build after generation
return schematics_1.chain([
...generate_component_1.generateComponent(ruleOptions, workspace),
...generate_styleguide_1.generateStyleguide(styleguideOptions, workspace, tree),
...generate_styleguide_component_1.generateStyleguideComponent(styleguideOptions, workspace),
...setup_styleguide_component_1.setupStyleguideComponent(styleguideOptions),
...setup_root_component_1.setupRootComponent(styleguideOptions, workspace),
...update_root_component_1.updateRootComponent(styleguideOptions, workspace),
...update_routes_1.updateRoutes(styleguideOptions),
]);
};
}
exports.organismSchematic = organismSchematic;
exports.organismSchematic = generate_type_1.typeSchematic(component_1.ComponentTypes.organism);
//# sourceMappingURL=index.js.map

@@ -1,7 +0,6 @@

import { Rule } from '@angular-devkit/schematics';
export declare function pageSchematic({ name, module, style, spec, }: {
export declare const pageSchematic: ({ name, module, style, spec, }: {
name: string;
module?: string;
style?: string;
spec?: boolean;
}): Rule;
module?: string | undefined;
style?: string | undefined;
spec?: boolean | undefined;
}) => import("@angular-devkit/schematics").Rule;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const schematics_1 = require("@angular-devkit/schematics");
const workspace_1 = require("../utils/workspace");
const generate_component_1 = require("../rules/generate-component");
const generate_type_1 = require("../rules/generate-type");
const component_1 = require("../types/component");
const generate_styleguide_1 = require("../rules/generate-styleguide");
const generate_styleguide_component_1 = require("../rules/generate-styleguide-component");
const setup_styleguide_component_1 = require("../rules/setup-styleguide-component");
const update_root_component_1 = require("../rules/update-root-component");
const update_routes_1 = require("../rules/update-routes");
const setup_root_component_1 = require("../rules/setup-root-component");
function pageSchematic({ name, module = 'ui', style = 'scss', spec = true, }) {
return (tree) => {
if (!name) {
throw new schematics_1.SchematicsException('Option (name) is required!');
}
const workspace = workspace_1.readWorkspace(tree);
const projectConfig = workspace.projects['ui'];
if (!projectConfig) {
throw new schematics_1.SchematicsException(`Could not find project (ui) in workspace`);
}
const ruleOptions = {
name,
project: 'ui',
module,
path: `${projectConfig.sourceRoot}/lib/pages`,
prefix: component_1.ComponentPrefixes.page,
export: true,
style,
styleext: style,
spec,
type: component_1.ComponentTypes.page,
};
const styleguideOptions = Object.assign({}, ruleOptions, { project: 'styleguide', module: 'pages', prefix: 'sg' });
// TODO: figure out how to trigger build after generation
return schematics_1.chain([
...generate_component_1.generateComponent(ruleOptions, workspace),
...generate_styleguide_1.generateStyleguide(styleguideOptions, workspace, tree),
...generate_styleguide_component_1.generateStyleguideComponent(styleguideOptions, workspace),
...setup_styleguide_component_1.setupStyleguideComponent(styleguideOptions),
...setup_root_component_1.setupRootComponent(styleguideOptions, workspace),
...update_root_component_1.updateRootComponent(styleguideOptions, workspace),
...update_routes_1.updateRoutes(styleguideOptions),
]);
};
}
exports.pageSchematic = pageSchematic;
exports.pageSchematic = generate_type_1.typeSchematic(component_1.ComponentTypes.page);
//# sourceMappingURL=index.js.map

@@ -11,2 +11,4 @@ "use strict";

}
const componentPrefix = prefix || component_1.ComponentPrefixes[type];
const componentPath = path || `${projectConfig.sourceRoot}/lib/${type}`;
return [

@@ -17,4 +19,4 @@ schematics_1.externalSchematic('@schematics/angular', 'component', {

module,
path: path || `${projectConfig.sourceRoot}/lib/${type}`,
prefix: prefix || component_1.ComponentPrefixes[type],
path: componentPath,
prefix: componentPrefix,
export: true,

@@ -21,0 +23,0 @@ style,

import { Rule } from '@angular-devkit/schematics';
import { experimental } from '@angular-devkit/core';
import { ComponentTypes } from '../types/component';
import { ComponentTypes, ComponentPrefixes } from '../types/component';
export declare const generateStyleguideComponent: (options: {
name: string;
type: ComponentTypes;
prefix: ComponentPrefixes;
}, workspace: experimental.workspace.WorkspaceSchema) => Rule[];
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const schematics_1 = require("@angular-devkit/schematics");
const core_1 = require("@angular-devkit/core");
const component_1 = require("../types/component");
const generate_component_1 = require("./generate-component");
const stringUtils = require("../utils/strings");
const updateComponent = ({ type, name, path, prefix, }) => {
return (tree, context) => {
const templates = schematics_1.apply(schematics_1.url('../templates/type-page'), [
schematics_1.applyTemplates(Object.assign({}, core_1.strings, stringUtils, { type,
name,
prefix })),
schematics_1.move(core_1.join(path, name)),
]);
return schematics_1.mergeWith(templates, schematics_1.MergeStrategy.Overwrite)(tree, context);
};
};
exports.generateStyleguideComponent = (options, workspace) => {

@@ -18,6 +32,12 @@ const { name, type, } = options;

type: component_1.ComponentTypes.page,
prefix: 'sg',
prefix: component_1.ComponentPrefixes.styleguide,
}, workspace),
updateComponent({
type,
name,
path: `${styleguideConfig.sourceRoot}/app/${type}s`,
prefix: component_1.ComponentPrefixes[type],
}),
];
};
//# sourceMappingURL=generate-styleguide-component.js.map
import { Rule } from '@angular-devkit/schematics';
export declare const updateRoutes: ({ module, name, project, }: {
import { ComponentTypes } from '../types/component';
export declare const updateRoutes: (options: {
module: string;
name: string;
project: string;
type: ComponentTypes;
}) => Rule[];

@@ -9,26 +9,60 @@ "use strict";

const ast_1 = require("../utils/ast");
exports.updateRoutes = ({ module, name, project, }) => {
return [(tree) => {
const workspace = workspace_1.readWorkspace(tree);
const projectConfig = workspace.projects[project];
if (!projectConfig) {
throw new schematics_1.SchematicsException(`Could not find project (${project}) in workspace`);
}
const routingModulePath = `${projectConfig.sourceRoot}/app/${module}/${module}-routing.module.ts`;
if (!tree.exists(routingModulePath)) {
return tree;
}
let result = tree;
let templateSource = file_1.readIntoSourceFile(result, routingModulePath);
let variableDeclarations = ast_1.findVariableDeclarations(templateSource);
// TODO: clean this up so we don't have to use parent
let routesDeclaration = ast_1.findNodeByIdentifier(variableDeclarations, 'routes');
let routeConfigs = ast_1.findNodes(routesDeclaration, ts.SyntaxKind.ObjectLiteralExpression);
result = ast_1.writeChangesToTree(result, routingModulePath, [
ast_1.insertAfterLastOccurrence(ast_1.findImports(templateSource), `\nimport { ${core_1.strings.classify(name)}Component } from './${name}/${name}.component';`, routingModulePath, 0),
ast_1.insertAfterLastOccurrence(routeConfigs, `\n { path: '${name}', component: ${core_1.strings.classify(name)}Component },${routeConfigs.length ? '' : '\n'}`, routingModulePath, routesDeclaration.getEnd() + 12),
]);
const strings_1 = require("../utils/strings");
const strings_2 = require("@angular-devkit/core/src/utils/strings");
const updateStyleguideRoutes = ({ module, name, project, }) => {
return (tree) => {
const workspace = workspace_1.readWorkspace(tree);
const projectConfig = workspace.projects[project];
if (!projectConfig) {
throw new schematics_1.SchematicsException(`Could not find project (${project}) in workspace`);
}
const routingModulePath = core_1.join(projectConfig.sourceRoot, 'app', module, `${module}-routing.module.ts`);
if (!tree.exists(routingModulePath)) {
return tree;
}
let result = tree;
let templateSource = file_1.readIntoSourceFile(result, routingModulePath);
let variableDeclarations = ast_1.findVariableDeclarations(templateSource);
// TODO: clean this up so we don't have to use parent
let routesDeclaration = ast_1.findNodeByIdentifier(variableDeclarations, `${strings_1.upper(module)}_ROUTES`);
let routeConfigs = ast_1.findNodes(routesDeclaration, ts.SyntaxKind.ObjectLiteralExpression);
result = ast_1.writeChangesToTree(result, routingModulePath, [
ast_1.insertAfterLastOccurrence(ast_1.findImports(templateSource), `\nimport { ${core_1.strings.classify(name)}Component } from './${name}/${name}.component';`, routingModulePath, 0),
ast_1.insertAfterLastOccurrence(routeConfigs, ` { path: '${name}', component: ${core_1.strings.classify(name)}Component, data: { title: '${strings_2.classify(name)}' } },${routeConfigs.length ? '' : '\n'}`, routingModulePath, routesDeclaration.getEnd() + 12),
]);
return result;
};
};
const updateNavigation = ({ type, project, }) => {
return (tree) => {
const workspace = workspace_1.readWorkspace(tree);
const projectConfig = workspace.projects[project];
if (!projectConfig) {
throw new schematics_1.SchematicsException(`Could not find project (${project}) in workspace`);
}
const appComponentPath = core_1.join(projectConfig.sourceRoot, 'app', 'app.component.ts');
if (!tree.exists(appComponentPath)) {
return tree;
}
let result = tree;
let templateSource = file_1.readIntoSourceFile(result, appComponentPath);
let navItems = ast_1.findNodes(templateSource, ts.SyntaxKind.VariableDeclarationList);
let items = ast_1.findNodes(navItems[0], ts.SyntaxKind.ArrayLiteralExpression);
if (navItems.find((item) => item.getFullText().includes(`${type}s`))) {
return result;
}];
}
result = ast_1.writeChangesToTree(result, appComponentPath, [
ast_1.insertAfterLastOccurrence(items, `\n { path: '${type}s', label: '${strings_2.classify(type)}s' },\n`, appComponentPath, items[0].getEnd() - 2, {
offset: -1
}),
]);
return result;
};
};
exports.updateRoutes = (options) => {
return [
updateStyleguideRoutes(options),
updateNavigation(options),
];
};
//# sourceMappingURL=update-routes.js.map
import { Rule } from '@angular-devkit/schematics';
export declare function styleguideSchematic(_options: any): Rule;
export declare function styleguideSchematic(options: any): Rule;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const schematics_1 = require("@angular-devkit/schematics");
const core_1 = require("@angular-devkit/core");
const tasks_1 = require("@angular-devkit/schematics/tasks");
const component_1 = require("../types/component");

@@ -28,3 +30,54 @@ const workspace_1 = require("../utils/workspace");

};
function styleguideSchematic(_options) {
const updateWorkspace = () => {
return (tree) => {
const workspace = tree.read('angular.json');
if (!workspace) {
throw new schematics_1.SchematicsException(`Could not find an angular.json in workspace`);
}
const workspaceContents = JSON.parse(workspace.toString());
tree.overwrite('angular.json', JSON.stringify(Object.assign({}, workspaceContents, { projects: Object.assign({}, workspaceContents.projects, { styleguide: Object.assign({}, workspaceContents.projects.styleguide, { architect: Object.assign({}, workspaceContents.projects.styleguide.architect, { build: Object.assign({}, workspaceContents.projects.styleguide.architect.build, { options: Object.assign({}, workspaceContents.projects.styleguide.architect.build.options, { assets: [
...workspaceContents.projects.styleguide.architect.build.options.assets,
{
glob: '**/readme.md',
input: 'projects/ui/src/lib',
output: '/assets',
},
] }) }) }) }) }) }), null, 2));
return tree;
};
};
const addDependencies = () => {
return (tree) => {
const packageJson = tree.read('package.json');
if (!packageJson) {
throw new schematics_1.SchematicsException(`Could not find a package.json in workspace`);
}
const packageJsonContents = JSON.parse(packageJson.toString());
tree.overwrite('package.json', JSON.stringify(Object.assign({}, packageJsonContents, { dependencies: Object.assign({}, packageJsonContents.dependencies, { "@angular/cdk": "^8.2.3", "@angular/material": "^8.2.3", "ngx-markdown": "8.2.1" }) }), null, 2));
return tree;
};
};
const setupStyleguide = () => {
return (tree) => {
const workspace = workspace_1.readWorkspace(tree);
const projectConfig = workspace.projects['styleguide'];
if (!projectConfig) {
throw new schematics_1.SchematicsException(`Could not find project (styleguide) in workspace`);
}
const templates = schematics_1.apply(schematics_1.url(`./files`), [
schematics_1.applyTemplates(Object.assign({}, core_1.strings, { project: workspace.defaultProject })),
schematics_1.move(projectConfig.sourceRoot),
]);
return schematics_1.mergeWith(templates, schematics_1.MergeStrategy.Overwrite);
};
};
const installDependencies = ({ skipInstall }) => {
return (tree, context) => {
if (skipInstall) {
return tree;
}
context.addTask(new tasks_1.NodePackageInstallTask());
};
};
function styleguideSchematic(options) {
return (_tree, _context) => {

@@ -39,2 +92,3 @@ return schematics_1.chain([

}),
setupStyleguide(),
schematics_1.externalSchematic('@schematics/angular', 'library', {

@@ -46,2 +100,5 @@ name: 'ui',

updateLinter(),
updateWorkspace(),
addDependencies(),
installDependencies(options),
]);

@@ -48,0 +105,0 @@ };

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc