Primeiro commit do projeto Angular

This commit is contained in:
2026-03-14 20:41:55 +00:00
parent 9bebe1de72
commit 94f4f46395
22413 changed files with 3221690 additions and 0 deletions
@@ -0,0 +1,15 @@
/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
{
"extends": "<%= relativePathToWorkspaceRoot %>/tsconfig.json",
"compilerOptions": {
"outDir": "<%= relativePathToWorkspaceRoot %>/out-tsc/worker",
"lib": [
"es2018",
"webworker"
],
"types": []
},
"include": [
"src/**/*.worker.ts"
]
}
@@ -0,0 +1,6 @@
/// <reference lib="webworker" />
addEventListener('message', ({ data }) => {
const response = `worker response to ${data}`;
postMessage(response);
});
+11
View File
@@ -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 WebWorkerOptions } from './schema';
declare const webWorkerSchematic: RuleFactory<WebWorkerOptions>;
export default webWorkerSchematic;
+102
View File
@@ -0,0 +1,102 @@
"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
*/
Object.defineProperty(exports, "__esModule", { value: true });
const schematics_1 = require("@angular-devkit/schematics");
const posix_1 = require("node:path/posix");
const parse_name_1 = require("../utility/parse-name");
const paths_1 = require("../utility/paths");
const project_1 = require("../utility/project");
const workspace_1 = require("../utility/workspace");
function addSnippet(options) {
return (host, context) => {
context.logger.debug('Updating appmodule');
if (options.path === undefined) {
return;
}
const fileRegExp = new RegExp(`^${options.name}.*\\.ts`);
const siblingModules = host
.getDir(options.path)
.subfiles // Find all files that start with the same name, are ts files,
// and aren't spec or module files.
.filter((f) => fileRegExp.test(f) && !/(module|spec|config|routes)\.ts$/.test(f))
// Sort alphabetically for consistency.
.sort();
if (siblingModules.length === 0) {
// No module to add in.
return;
}
const siblingModulePath = `${options.path}/${siblingModules[0]}`;
const logMessage = 'console.log(`page got message: ${data}`);';
const workerCreationSnippet = `
if (typeof Worker !== 'undefined') {
// Create a new
const worker = new Worker(new URL('./${options.name}.worker', import.meta.url));
worker.onmessage = ({ data }) => {
${logMessage}
};
worker.postMessage('hello');
} else {
// Web Workers are not supported in this environment.
// You should add a fallback so that your program still executes correctly.
}
`;
// Append the worker creation snippet.
const originalContent = host.readText(siblingModulePath);
host.overwrite(siblingModulePath, originalContent + '\n' + workerCreationSnippet);
return host;
};
}
const webWorkerSchematic = (0, project_1.createProjectSchematic)((options, { project }) => {
const projectType = project.extensions['projectType'];
if (projectType !== 'application') {
throw new schematics_1.SchematicsException(`Web Worker requires a project type of "application".`);
}
if (options.path === undefined) {
options.path = (0, workspace_1.buildDefaultPath)(project);
}
const parsedPath = (0, parse_name_1.parseName)(options.path, options.name);
options.name = parsedPath.name;
options.path = parsedPath.path;
const templateSourceWorkerCode = (0, schematics_1.apply)((0, schematics_1.url)('./files/worker'), [
(0, schematics_1.applyTemplates)({ ...options, ...schematics_1.strings }),
(0, schematics_1.move)(parsedPath.path),
]);
const root = project.root || '';
const templateSourceWorkerConfig = (0, schematics_1.apply)((0, schematics_1.url)('./files/worker-tsconfig'), [
(0, schematics_1.applyTemplates)({
...options,
relativePathToWorkspaceRoot: (0, paths_1.relativePathToWorkspaceRoot)(root),
}),
(0, schematics_1.move)(root),
]);
return (0, schematics_1.chain)([
// Add project configuration.
(0, workspace_1.updateWorkspace)((workspace) => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const project = workspace.projects.get(options.project);
const buildTarget = project.targets.get('build');
const testTarget = project.targets.get('test');
if (!buildTarget) {
throw new Error(`Build target is not defined for this project.`);
}
const workerConfigPath = (0, posix_1.join)(root, 'tsconfig.worker.json');
(buildTarget.options ??= {}).webWorkerTsConfig ??= workerConfigPath;
if (testTarget) {
(testTarget.options ??= {}).webWorkerTsConfig ??= workerConfigPath;
}
}),
// Create the worker in a sibling module.
options.snippet ? addSnippet(options) : (0, schematics_1.noop)(),
// Add the worker.
(0, schematics_1.mergeWith)(templateSourceWorkerCode),
(0, schematics_1.mergeWith)(templateSourceWorkerConfig),
]);
});
exports.default = webWorkerSchematic;
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;AAEH,2DAcoC;AACpC,2CAAuC;AACvC,sDAAkD;AAClD,4CAA+D;AAC/D,gDAA4D;AAC5D,oDAAyE;AAGzE,SAAS,UAAU,CAAC,OAAyB;IAC3C,OAAO,CAAC,IAAU,EAAE,OAAyB,EAAE,EAAE;QAC/C,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;QAE3C,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAC/B,OAAO;QACT,CAAC;QAED,MAAM,UAAU,GAAG,IAAI,MAAM,CAAC,IAAI,OAAO,CAAC,IAAI,SAAS,CAAC,CAAC;QACzD,MAAM,cAAc,GAAG,IAAI;aACxB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;aACpB,QAAQ,CAAC,8DAA8D;YACxE,mCAAmC;aAClC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,kCAAkC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YACjF,uCAAuC;aACtC,IAAI,EAAE,CAAC;QAEV,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAChC,uBAAuB;YACvB,OAAO;QACT,CAAC;QAED,MAAM,iBAAiB,GAAG,GAAG,OAAO,CAAC,IAAI,IAAI,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;QACjE,MAAM,UAAU,GAAG,2CAA2C,CAAC;QAC/D,MAAM,qBAAqB,GAAG;;;yCAGO,OAAO,CAAC,IAAI;;MAE/C,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 @@
/**
* Creates a new web worker in your project. Web workers allow you to run JavaScript code in
* the background, improving the performance and responsiveness of your application by
* offloading computationally intensive tasks. This schematic generates the necessary files
* for a new web worker and provides an optional code snippet to demonstrate its usage.
*/
export type Schema = {
/**
* The name for the new web worker. This will be used to create the worker file (e.g.,
* `my-worker.worker.ts`).
*/
name: string;
/**
* The path where the web worker file should be created, relative to the current workspace.
* If not specified, the worker will be created in the current directory.
*/
path?: string;
/**
* The name of the project where the web worker should be created. If not specified, the CLI
* will determine the project from the current directory.
*/
project: string;
/**
* Generate a code snippet that demonstrates how to create and use the new web worker.
*/
snippet?: boolean;
};
+5
View File
@@ -0,0 +1,5 @@
"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 });
//# sourceMappingURL=schema.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"schema.js","sourceRoot":"","sources":["schema.ts"],"names":[],"mappings":";AACA,mFAAmF;AACnF,oFAAoF"}
+41
View File
@@ -0,0 +1,41 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "SchematicsAngularWebWorker",
"title": "Angular Web Worker Options Schema",
"type": "object",
"additionalProperties": false,
"description": "Creates a new web worker in your project. Web workers allow you to run JavaScript code in the background, improving the performance and responsiveness of your application by offloading computationally intensive tasks. This schematic generates the necessary files for a new web worker and provides an optional code snippet to demonstrate its usage.",
"properties": {
"path": {
"type": "string",
"format": "path",
"$default": {
"$source": "workingDirectory"
},
"description": "The path where the web worker file should be created, relative to the current workspace. If not specified, the worker will be created in the current directory.",
"visible": false
},
"project": {
"type": "string",
"description": "The name of the project where the web worker should be created. If not specified, the CLI will determine the project from the current directory.",
"$default": {
"$source": "projectName"
}
},
"name": {
"type": "string",
"description": "The name for the new web worker. This will be used to create the worker file (e.g., `my-worker.worker.ts`).",
"$default": {
"$source": "argv",
"index": 0
},
"x-prompt": "What name would you like to use for the worker?"
},
"snippet": {
"type": "boolean",
"default": true,
"description": "Generate a code snippet that demonstrates how to create and use the new web worker."
}
},
"required": ["name", "project"]
}