Skip to content

Instantly share code, notes, and snippets.

View IKatsuba's full-sized avatar

Igor Katsuba IKatsuba

View GitHub Profile
@IKatsuba
IKatsuba / tailwind.config.js
Created February 15, 2024 07:49
Create glob patterns for an Angular library with Tailwind CSS and Nx
const { createGlobPatternsForDependencies } = require('@nx/angular/tailwind');
const { join } = require('path');
const { Project } = require('ts-morph');
const { workspaceRoot } = require('nx/src/utils/workspace-root');
/**
* Get all the library imports from the given paths
* @param {string} scope
* @param {string[]} paths
addPackageJsonDependency(tree, {
name: '@package/name',
version: '~2.0.0',
type: NodeDependencyType.Dev
});
removeImports(imports)
editImports(imports, ({moduleSpecifier}) => ({
moduleSpecifier: moduleSpecifier.replace('@org', '@new-org')
})
const imports = getImports('src/**/*.ts', {
moduleSpecifier: '@org/*',
});
createImports('/src/some.ts', [
{
namedImports: ['CoreModule'],
moduleSpecifier: '@org/core',
isTypeOnly: true,
}
]);
setActiveProject(createProject(new NgMorphTree('/')));
const enums = getEnums('/**/*.ts');
editEnums(enums, ({name}) => ({name: name.toUpperCase()}))
const rule: Rule = (tree: Tree, context: SchematicContext): void => {
setActiveProject(createProject(tree));
const appModule = getMainModule('src/main.ts');
addImportToNgModule(appModule, 'SomeModule');
addImports(appModule.getFilePath(), {moduleSpecifier: '@some/package', namedExports: ['SomeModule']})
export function addSymbolToNgModuleMetadata(
source: ts.SourceFile,
ngModulePath: string,
metadataField: string,
symbolName: string,
importPath: string | null = null,
): Change[] {
const nodes = getDecoratorMetadata(source, 'NgModule', '@angular/core');
let node: any = nodes[0]; // tslint:disable-line:no-any
type Rule = (tree: Tree, context: SchematicContext) => Tree | Observable<Tree> | Rule | Promise<void | Rule> | void;