Primeiro commit do projeto Angular
This commit is contained in:
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"plugins": {
|
||||
"@tailwindcss/postcss": {}
|
||||
}
|
||||
}
|
||||
+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 TailwindOptions } from './schema';
|
||||
declare const tailwindSchematic: RuleFactory<TailwindOptions>;
|
||||
export default tailwindSchematic;
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
"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 __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const schematics_1 = require("@angular-devkit/schematics");
|
||||
const node_assert_1 = __importDefault(require("node:assert"));
|
||||
const posix_1 = require("node:path/posix");
|
||||
const utility_1 = require("../utility");
|
||||
const json_file_1 = require("../utility/json-file");
|
||||
const latest_versions_1 = require("../utility/latest-versions");
|
||||
const project_1 = require("../utility/project");
|
||||
const TAILWIND_DEPENDENCIES = ['tailwindcss', '@tailwindcss/postcss', 'postcss'];
|
||||
const POSTCSS_CONFIG_FILES = ['.postcssrc.json', 'postcss.config.json'];
|
||||
function addTailwindStyles(options, project) {
|
||||
return async (tree) => {
|
||||
const buildTarget = project.targets.get('build');
|
||||
if (!buildTarget) {
|
||||
throw new schematics_1.SchematicsException(`Project "${options.project}" does not have a build target.`);
|
||||
}
|
||||
const styles = buildTarget.options?.['styles'];
|
||||
let stylesheetPath;
|
||||
if (styles) {
|
||||
stylesheetPath = styles
|
||||
.map((s) => (typeof s === 'string' ? s : s.input))
|
||||
.find((p) => p.endsWith('.css'));
|
||||
}
|
||||
if (!stylesheetPath) {
|
||||
const newStylesheetPath = (0, posix_1.join)(project.sourceRoot ?? 'src', 'tailwind.css');
|
||||
tree.create(newStylesheetPath, `@import 'tailwindcss';\n`);
|
||||
return (0, utility_1.updateWorkspace)((workspace) => {
|
||||
const project = workspace.projects.get(options.project);
|
||||
if (project) {
|
||||
const buildTarget = project.targets.get('build');
|
||||
(0, node_assert_1.default)(buildTarget, 'Build target should still be present');
|
||||
// Update main styles
|
||||
const buildOptions = buildTarget.options;
|
||||
(0, node_assert_1.default)(buildOptions, 'Build options should still be present');
|
||||
const existingStyles = buildOptions['styles'] ?? [];
|
||||
buildOptions['styles'] = [newStylesheetPath, ...existingStyles];
|
||||
// Update configuration styles
|
||||
if (buildTarget.configurations) {
|
||||
for (const config of Object.values(buildTarget.configurations)) {
|
||||
if (config && 'styles' in config) {
|
||||
const existingStyles = config['styles'] ?? [];
|
||||
config['styles'] = [newStylesheetPath, ...existingStyles];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
let stylesheetContent = tree.readText(stylesheetPath);
|
||||
if (!/@import ["']tailwindcss["'];/.test(stylesheetContent)) {
|
||||
stylesheetContent += `\n@import 'tailwindcss';\n`;
|
||||
tree.overwrite(stylesheetPath, stylesheetContent);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
function managePostCssConfiguration(project) {
|
||||
return async (tree) => {
|
||||
const searchPaths = ['/', project.root]; // Workspace root and project root
|
||||
for (const path of searchPaths) {
|
||||
for (const configFile of POSTCSS_CONFIG_FILES) {
|
||||
const fullPath = (0, posix_1.join)(path, configFile);
|
||||
if (tree.exists(fullPath)) {
|
||||
const postcssConfig = new json_file_1.JSONFile(tree, fullPath);
|
||||
const tailwindPluginPath = ['plugins', '@tailwindcss/postcss'];
|
||||
if (postcssConfig.get(tailwindPluginPath) === undefined) {
|
||||
postcssConfig.modify(tailwindPluginPath, {});
|
||||
}
|
||||
// Config found and handled
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
// No existing config found, so create one from the template
|
||||
const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [
|
||||
(0, schematics_1.applyTemplates)({
|
||||
...schematics_1.strings,
|
||||
}),
|
||||
(0, schematics_1.move)(project.root),
|
||||
]);
|
||||
return (0, schematics_1.mergeWith)(templateSource);
|
||||
};
|
||||
}
|
||||
const tailwindSchematic = (0, project_1.createProjectSchematic)((options, { project }) => {
|
||||
return (0, schematics_1.chain)([
|
||||
addTailwindStyles(options, project),
|
||||
managePostCssConfiguration(project),
|
||||
...TAILWIND_DEPENDENCIES.map((name) => (0, utility_1.addDependency)(name, latest_versions_1.latestVersions[name], {
|
||||
type: utility_1.DependencyType.Dev,
|
||||
existing: utility_1.ExistingBehavior.Skip,
|
||||
install: options.skipInstall ? utility_1.InstallBehavior.None : utility_1.InstallBehavior.Auto,
|
||||
})),
|
||||
]);
|
||||
});
|
||||
exports.default = tailwindSchematic;
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;AAEH,2DAWoC;AACpC,8DAAiC;AACjC,2CAAuC;AACvC,wCAOoB;AACpB,oDAAgD;AAChD,gEAA4D;AAC5D,gDAA4D;AAG5D,MAAM,qBAAqB,GAAG,CAAC,aAAa,EAAE,sBAAsB,EAAE,SAAS,CAAC,CAAC;AACjF,MAAM,oBAAoB,GAAG,CAAC,iBAAiB,EAAE,qBAAqB,CAAC,CAAC;AAExE,SAAS,iBAAiB,CAAC,OAA4B,EAAE,OAA0B;IACjF,OAAO,KAAK,EAAE,IAAI,EAAE,EAAE;QACpB,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CA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CAAC,CACH;KACF,CAAC,CAAC;AACL,CAAC,CACF,CAAC;AAEF,kBAAe,iBAAiB,CAAC"}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
export type Schema = {
|
||||
/**
|
||||
* The package to be added.
|
||||
*/
|
||||
package?: string;
|
||||
/**
|
||||
* The name of the project.
|
||||
*/
|
||||
project: string;
|
||||
/**
|
||||
* Skip the automatic installation of packages. You will need to manually install the
|
||||
* dependencies later.
|
||||
*/
|
||||
skipInstall?: boolean;
|
||||
[property: string]: any;
|
||||
};
|
||||
+5
@@ -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
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"schema.js","sourceRoot":"","sources":["schema.ts"],"names":[],"mappings":";AACA,mFAAmF;AACnF,oFAAoF"}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema",
|
||||
"title": "Tailwind CSS Schematic",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"project": {
|
||||
"type": "string",
|
||||
"description": "The name of the project.",
|
||||
"$default": {
|
||||
"$source": "projectName"
|
||||
}
|
||||
},
|
||||
"package": {
|
||||
"type": "string",
|
||||
"description": "The package to be added."
|
||||
},
|
||||
"skipInstall": {
|
||||
"description": "Skip the automatic installation of packages. You will need to manually install the dependencies later.",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
}
|
||||
},
|
||||
"required": ["project"]
|
||||
}
|
||||
Reference in New Issue
Block a user