Primeiro commit do projeto Angular
This commit is contained in:
Generated
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { RouterModule, Routes } from '@angular/router';<% if (lazyRoute) { %>
|
||||
import { <%= classify(name) %> } from './<%= dasherize(name) %>';<% } %>
|
||||
|
||||
const routes: Routes = [<% if (lazyRoute) { %>{ path: '', component: <%= classify(name) %> }<% } %>];
|
||||
|
||||
@NgModule({
|
||||
imports: [RouterModule.for<%= routingScope %>(routes)],
|
||||
exports: [RouterModule]
|
||||
})
|
||||
export class <%= classify(name) %>RoutingModule { }
|
||||
Generated
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
import { NgModule } from '@angular/core';<% if (commonModule) { %>
|
||||
import { CommonModule } from '@angular/common';<% } %><% if (lazyRouteWithoutRouteModule) { %>
|
||||
import { Routes, RouterModule } from '@angular/router';<% } %>
|
||||
<% if ((!lazyRoute && routing) || lazyRouteWithRouteModule) { %>
|
||||
import { <%= classify(name) %>RoutingModule } from './<%= dasherize(name) %>-routing<%= typeSeparator %>module';<% } %>
|
||||
<% if (lazyRouteWithoutRouteModule) { %>
|
||||
const routes: Routes = [
|
||||
{ path: '', component: <%= classify(name) %> }
|
||||
];<% } %>
|
||||
|
||||
@NgModule({
|
||||
declarations: [],
|
||||
imports: [<% if (commonModule) { %>
|
||||
CommonModule<% } %><% if ((!lazyRoute && routing) || lazyRouteWithRouteModule) { %>,
|
||||
<%= classify(name) %>RoutingModule<% } %><% if (lazyRouteWithoutRouteModule) { %>,
|
||||
RouterModule.forChild(routes)<% } %>
|
||||
]
|
||||
})
|
||||
export class <%= classify(name) %>Module { }
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google LLC All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.dev/license
|
||||
*/
|
||||
import { RuleFactory } from '@angular-devkit/schematics';
|
||||
import { Schema as ModuleOptions } from './schema';
|
||||
declare const moduleSchematic: RuleFactory<ModuleOptions>;
|
||||
export default moduleSchematic;
|
||||
+164
@@ -0,0 +1,164 @@
|
||||
"use strict";
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google LLC All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.dev/license
|
||||
*/
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const schematics_1 = require("@angular-devkit/schematics");
|
||||
const posix_1 = require("node:path/posix");
|
||||
const ts = __importStar(require("../third_party/github.com/Microsoft/TypeScript/lib/typescript"));
|
||||
const ast_utils_1 = require("../utility/ast-utils");
|
||||
const change_1 = require("../utility/change");
|
||||
const find_module_1 = require("../utility/find-module");
|
||||
const parse_name_1 = require("../utility/parse-name");
|
||||
const project_1 = require("../utility/project");
|
||||
const validation_1 = require("../utility/validation");
|
||||
const workspace_1 = require("../utility/workspace");
|
||||
const schema_1 = require("./schema");
|
||||
function buildRelativeModulePath(options, modulePath) {
|
||||
const importModulePath = (0, posix_1.join)(options.path ?? '', options.flat ? '' : schematics_1.strings.dasherize(options.name), schematics_1.strings.dasherize(options.name) + options.typeSeparator + 'module');
|
||||
return (0, find_module_1.buildRelativePath)(modulePath, importModulePath);
|
||||
}
|
||||
function addImportToNgModule(options) {
|
||||
return (host) => {
|
||||
if (!options.module) {
|
||||
return host;
|
||||
}
|
||||
const modulePath = options.module;
|
||||
const sourceText = host.readText(modulePath);
|
||||
const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
|
||||
const relativePath = buildRelativeModulePath(options, modulePath);
|
||||
const changes = (0, ast_utils_1.addImportToModule)(source, modulePath, schematics_1.strings.classify(`${options.name}Module`), relativePath);
|
||||
const recorder = host.beginUpdate(modulePath);
|
||||
for (const change of changes) {
|
||||
if (change instanceof change_1.InsertChange) {
|
||||
recorder.insertLeft(change.pos, change.toAdd);
|
||||
}
|
||||
}
|
||||
host.commitUpdate(recorder);
|
||||
return host;
|
||||
};
|
||||
}
|
||||
function addRouteDeclarationToNgModule(options, routingModulePath) {
|
||||
return (host) => {
|
||||
if (!options.route) {
|
||||
return host;
|
||||
}
|
||||
if (!options.module) {
|
||||
throw new Error('Module option required when creating a lazy loaded routing module.');
|
||||
}
|
||||
let path;
|
||||
if (routingModulePath) {
|
||||
path = routingModulePath;
|
||||
}
|
||||
else {
|
||||
path = options.module;
|
||||
}
|
||||
const sourceText = host.readText(path);
|
||||
const addDeclaration = (0, ast_utils_1.addRouteDeclarationToModule)(ts.createSourceFile(path, sourceText, ts.ScriptTarget.Latest, true), path, buildRoute(options, options.module));
|
||||
const recorder = host.beginUpdate(path);
|
||||
recorder.insertLeft(addDeclaration.pos, addDeclaration.toAdd);
|
||||
host.commitUpdate(recorder);
|
||||
return host;
|
||||
};
|
||||
}
|
||||
function getRoutingModulePath(host, modulePath) {
|
||||
const routingModulePath = modulePath.endsWith(find_module_1.ROUTING_MODULE_EXT_LEGACY) || modulePath.endsWith(find_module_1.ROUTING_MODULE_EXT)
|
||||
? modulePath
|
||||
: modulePath
|
||||
.replace(find_module_1.MODULE_EXT_LEGACY, find_module_1.ROUTING_MODULE_EXT_LEGACY)
|
||||
.replace(find_module_1.MODULE_EXT, find_module_1.ROUTING_MODULE_EXT);
|
||||
return host.exists(routingModulePath) ? routingModulePath : undefined;
|
||||
}
|
||||
function buildRoute(options, modulePath) {
|
||||
const relativeModulePath = buildRelativeModulePath(options, modulePath);
|
||||
const moduleName = `${schematics_1.strings.classify(options.name)}Module`;
|
||||
const loadChildren = `() => import('${relativeModulePath}').then(m => m.${moduleName})`;
|
||||
return `{ path: '${options.route}', loadChildren: ${loadChildren} }`;
|
||||
}
|
||||
const moduleSchematic = (0, project_1.createProjectSchematic)(async (options, { tree }) => {
|
||||
if (options.path === undefined) {
|
||||
options.path = await (0, workspace_1.createDefaultPath)(tree, options.project);
|
||||
}
|
||||
if (options.module) {
|
||||
options.module = (0, find_module_1.findModuleFromOptions)(tree, options);
|
||||
}
|
||||
let routingModulePath;
|
||||
const isLazyLoadedModuleGen = !!(options.route && options.module);
|
||||
if (isLazyLoadedModuleGen) {
|
||||
options.routingScope = schema_1.RoutingScope.Child;
|
||||
routingModulePath = getRoutingModulePath(tree, options.module);
|
||||
}
|
||||
const parsedPath = (0, parse_name_1.parseName)(options.path, options.name);
|
||||
options.name = parsedPath.name;
|
||||
options.path = parsedPath.path;
|
||||
(0, validation_1.validateClassName)(schematics_1.strings.classify(options.name));
|
||||
const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [
|
||||
options.routing || (isLazyLoadedModuleGen && routingModulePath)
|
||||
? (0, schematics_1.noop)()
|
||||
: (0, schematics_1.filter)((path) => !path.includes('-routing')),
|
||||
(0, schematics_1.applyTemplates)({
|
||||
...schematics_1.strings,
|
||||
'if-flat': (s) => (options.flat ? '' : s),
|
||||
lazyRoute: isLazyLoadedModuleGen,
|
||||
lazyRouteWithoutRouteModule: isLazyLoadedModuleGen && !routingModulePath,
|
||||
lazyRouteWithRouteModule: isLazyLoadedModuleGen && !!routingModulePath,
|
||||
...options,
|
||||
}),
|
||||
(0, schematics_1.move)(parsedPath.path),
|
||||
]);
|
||||
const moduleDasherized = schematics_1.strings.dasherize(options.name);
|
||||
const modulePath = `${!options.flat ? moduleDasherized + '/' : ''}${moduleDasherized}${options.typeSeparator}module.ts`;
|
||||
const componentOptions = {
|
||||
module: modulePath,
|
||||
flat: options.flat,
|
||||
name: options.name,
|
||||
path: options.path,
|
||||
project: options.project,
|
||||
standalone: false,
|
||||
};
|
||||
return (0, schematics_1.chain)([
|
||||
!isLazyLoadedModuleGen ? addImportToNgModule(options) : (0, schematics_1.noop)(),
|
||||
addRouteDeclarationToNgModule(options, routingModulePath),
|
||||
(0, schematics_1.mergeWith)(templateSource),
|
||||
isLazyLoadedModuleGen ? (0, schematics_1.schematic)('component', componentOptions) : (0, schematics_1.noop)(),
|
||||
]);
|
||||
});
|
||||
exports.default = moduleSchematic;
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
+63
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* Creates a new, generic NgModule definition in the given project.
|
||||
*/
|
||||
export type Schema = {
|
||||
/**
|
||||
* The new NgModule imports "CommonModule".
|
||||
*/
|
||||
commonModule?: boolean;
|
||||
/**
|
||||
* Create the new files at the top level of the current project root.
|
||||
*/
|
||||
flat?: boolean;
|
||||
/**
|
||||
* The declaring NgModule.
|
||||
*/
|
||||
module?: string;
|
||||
/**
|
||||
* The name of the NgModule.
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* The path at which to create the NgModule, relative to the workspace root.
|
||||
*/
|
||||
path?: string;
|
||||
/**
|
||||
* The name of the project.
|
||||
*/
|
||||
project: string;
|
||||
/**
|
||||
* The route path for a lazy-loaded module. When supplied, creates a component in the new
|
||||
* module, and adds the route to that component in the `Routes` array declared in the module
|
||||
* provided in the `--module` option.
|
||||
*/
|
||||
route?: string;
|
||||
/**
|
||||
* Create a routing module.
|
||||
*/
|
||||
routing?: boolean;
|
||||
/**
|
||||
* The scope for the new routing module.
|
||||
*/
|
||||
routingScope?: RoutingScope;
|
||||
/**
|
||||
* The separator character to use before the type within the generated file's name. For
|
||||
* example, if you set the option to `.`, the file will be named `example.module.ts`.
|
||||
*/
|
||||
typeSeparator?: TypeSeparator;
|
||||
};
|
||||
/**
|
||||
* The scope for the new routing module.
|
||||
*/
|
||||
export declare enum RoutingScope {
|
||||
Child = "Child",
|
||||
Root = "Root"
|
||||
}
|
||||
/**
|
||||
* The separator character to use before the type within the generated file's name. For
|
||||
* example, if you set the option to `.`, the file will be named `example.module.ts`.
|
||||
*/
|
||||
export declare enum TypeSeparator {
|
||||
Empty = "-",
|
||||
TypeSeparator = "."
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
// THIS FILE IS AUTOMATICALLY GENERATED. TO UPDATE THIS FILE YOU NEED TO CHANGE THE
|
||||
// CORRESPONDING JSON SCHEMA FILE, THEN RUN devkit-admin build (or bazel build ...).
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TypeSeparator = exports.RoutingScope = void 0;
|
||||
/**
|
||||
* The scope for the new routing module.
|
||||
*/
|
||||
var RoutingScope;
|
||||
(function (RoutingScope) {
|
||||
RoutingScope["Child"] = "Child";
|
||||
RoutingScope["Root"] = "Root";
|
||||
})(RoutingScope || (exports.RoutingScope = RoutingScope = {}));
|
||||
/**
|
||||
* The separator character to use before the type within the generated file's name. For
|
||||
* example, if you set the option to `.`, the file will be named `example.module.ts`.
|
||||
*/
|
||||
var TypeSeparator;
|
||||
(function (TypeSeparator) {
|
||||
TypeSeparator["Empty"] = "-";
|
||||
TypeSeparator["TypeSeparator"] = ".";
|
||||
})(TypeSeparator || (exports.TypeSeparator = TypeSeparator = {}));
|
||||
//# sourceMappingURL=schema.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"schema.js","sourceRoot":"","sources":["schema.ts"],"names":[],"mappings":";AACA,mFAAmF;AACnF,oFAAoF;;;AAmDpF;;GAEG;AACH,IAAY,YAGX;AAHD,WAAY,YAAY;IACpB,+BAAe,CAAA;IACf,6BAAa,CAAA;AACjB,CAAC,EAHW,YAAY,4BAAZ,YAAY,QAGvB;AAED;;;GAGG;AACH,IAAY,aAGX;AAHD,WAAY,aAAa;IACrB,4BAAW,CAAA;IACX,oCAAmB,CAAA;AACvB,CAAC,EAHW,aAAa,6BAAb,aAAa,QAGxB"}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema",
|
||||
"$id": "SchematicsAngularModule",
|
||||
"title": "Angular Module Options Schema",
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"description": "Creates a new, generic NgModule definition in the given project.",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "The name of the NgModule.",
|
||||
"$default": {
|
||||
"$source": "argv",
|
||||
"index": 0
|
||||
},
|
||||
"x-prompt": "What name would you like to use for the NgModule?"
|
||||
},
|
||||
"path": {
|
||||
"type": "string",
|
||||
"format": "path",
|
||||
"$default": {
|
||||
"$source": "workingDirectory"
|
||||
},
|
||||
"description": "The path at which to create the NgModule, relative to the workspace root.",
|
||||
"visible": false
|
||||
},
|
||||
"project": {
|
||||
"type": "string",
|
||||
"description": "The name of the project.",
|
||||
"$default": {
|
||||
"$source": "projectName"
|
||||
}
|
||||
},
|
||||
"routing": {
|
||||
"type": "boolean",
|
||||
"description": "Create a routing module.",
|
||||
"default": false,
|
||||
"x-user-analytics": "ep.ng_routing"
|
||||
},
|
||||
"routingScope": {
|
||||
"enum": ["Child", "Root"],
|
||||
"type": "string",
|
||||
"description": "The scope for the new routing module.",
|
||||
"default": "Child"
|
||||
},
|
||||
"route": {
|
||||
"type": "string",
|
||||
"description": "The route path for a lazy-loaded module. When supplied, creates a component in the new module, and adds the route to that component in the `Routes` array declared in the module provided in the `--module` option."
|
||||
},
|
||||
"flat": {
|
||||
"type": "boolean",
|
||||
"description": "Create the new files at the top level of the current project root. ",
|
||||
"default": false
|
||||
},
|
||||
"commonModule": {
|
||||
"type": "boolean",
|
||||
"description": "The new NgModule imports \"CommonModule\". ",
|
||||
"default": true,
|
||||
"visible": false
|
||||
},
|
||||
"module": {
|
||||
"type": "string",
|
||||
"description": "The declaring NgModule.",
|
||||
"alias": "m"
|
||||
},
|
||||
"typeSeparator": {
|
||||
"type": "string",
|
||||
"default": "-",
|
||||
"enum": ["-", "."],
|
||||
"description": "The separator character to use before the type within the generated file's name. For example, if you set the option to `.`, the file will be named `example.module.ts`."
|
||||
}
|
||||
},
|
||||
"required": ["name", "project"]
|
||||
}
|
||||
Reference in New Issue
Block a user