@ikamva/ngx-tailwindcss
Version:
Tailwind CSS angular schematic
60 lines • 2.89 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const schematics_1 = require("@angular-devkit/schematics");
const installDependencies_1 = require("./rules/installDependencies");
const updateAngularJsonOptions_1 = require("./rules/updateAngularJsonOptions");
const addPackageJsonDependencies_1 = require("./rules/addPackageJsonDependencies");
function default_1(_options) {
return (tree, _context) => {
return schematics_1.chain([
addPackageJsonDependencies_1.addPackageJsonDependencies(),
createTailwindCss(_options),
addConfig(`./files/tailwind-config/${_options.workspace}`, _context),
addConfig('./files/webpack', _context),
updateAngularJsonOptions_1.updateAngularJsonOptions(_options),
installDependencies_1.installDependencies()
])(tree, _context);
};
}
exports.default = default_1;
function addConfig(path, _context) {
return (_host) => __awaiter(this, void 0, void 0, function* () {
_context.logger.debug(`Src Path ${path}`);
const sourceTemplates = schematics_1.url(path);
const applyTemplate = schematics_1.apply(sourceTemplates, []);
return schematics_1.mergeWith(applyTemplate);
});
}
/**
* Create tailwind.css in source root project
* adds tailwindcss imports
*/
function createTailwindCss(_options) {
return (tree) => {
const angularJSON = tree.read("angular.json").toString("utf-8");
// Check if is an angular cli workspace
if (!angularJSON) {
throw new schematics_1.SchematicsException("Not an Angular CLI workspace");
}
// Get angular workspace
const workspace = JSON.parse(angularJSON);
// Get Project name
const projectName = _options.project || workspace.defaultProject;
// Get project
const project = workspace.projects[projectName];
// Get SRC Path
const srcPath = project['sourceRoot'];
tree.create(`${srcPath}/tailwind/tailwind.scss`, `@import "tailwindcss/base";\n@import "tailwindcss/components";\n@import "tailwindcss/utilities";`);
return tree;
};
}
//# sourceMappingURL=index.js.map