angular-django2
v0.1.3
Published
Angular library workspace for Django-friendly integration primitives and custom Angular CLI schematics.
Maintainers
Readme
angular-django2
angular-django2 provides Angular-friendly configuration primitives for Django-backed applications and a schematics collection for custom ng generate flows.
The initial package surface is intentionally small:
provideAngularDjango2(...)for root-level configurationANGULAR_DJANGO2_CONFIGfor DI-based access to resolved configAngularDjango2Servicefor URL and CSRF helper methods- schematics for
application,service,class,app-shell,component,material-setup,project-structure,ng-app,ng-api, anddata-service
Usage
Angular.dev best practices prefer standalone bootstrap and provider functions. A typical setup looks like this:
import { provideHttpClient, withXsrfConfiguration } from '@angular/common/http';
import { ApplicationConfig } from '@angular/core';
import { provideAngularDjango2 } from 'angular-django2';
export const appConfig: ApplicationConfig = {
providers: [
provideHttpClient(
withXsrfConfiguration({
cookieName: 'csrftoken',
headerName: 'X-CSRFToken',
}),
),
provideAngularDjango2({
apiBaseUrl: 'https://api.example.com',
withCredentials: true,
}),
],
};The resolved configuration defaults are:
apiBaseUrl: ''csrfCookieName: 'csrftoken'csrfHeaderName: 'X-CSRFToken'withCredentials: true
Schematics
After installing the package in another Angular workspace, you can run:
ng generate angular-django2:application my-app
ng generate angular-django2:material-setup --project=my-app
ng generate angular-django2:project-structure --project=my-app
ng generate angular-django2:app-shell --project my-app
ng generate angular-django2:component dashboard-card
ng generate angular-django2:service django-api
ng generate angular-django2:class api-contract
ng generate angular-django2:ng-app my-app
ng generate angular-django2:ng-api --inputPath=openapi.json
ng generate angular-django2:data-service usersCurrent defaults:
application:standalone: true,routing: true,style: 'scss'material-setup: configures Angular Material with theme and providers- Options:
--theme(indigo-pink, deeppurple-amber, pink-bluegrey, purple-green, custom),--typography,--animations
- Options:
project-structure: creates standard directory structure (core/,shared/,features/) with barrel exportscomponent:standalone: true,changeDetection: 'OnPush'service,class, andapp-shell: pass through to Angular CLIng-app: generates a complete Angular app with Material UI in a single step — runsapplication, adds@angular/material/@angular/cdk, configures theming, creates the standard directory structure, and writes a responsive sidenav app shell- Options:
--theme,--typography,--animations,--routing,--standalone,--style,--prefix
- Options:
ng-api: bootstraps ng-openapi-gen — adds the package todevDependencies, writesng-openapi-gen.json, and adds agenerate:apinpm script- Options:
--inputPath(default:openapi.json),--outputPath(default:src/app/api)
- Options:
data-service: generates a typed*DataServicewrapper around an ng-openapi-gen*ApiServicewith search and CRUD helpers- Options:
--apiService,--apiPath(default:../api/services),--path,--flat,--skipTests
- Options:
OpenAPI workflow
# 1. Bootstrap ng-openapi-gen
ng generate angular-django2:ng-api --inputPath=openapi.json
# 2. Generate typed Angular services from your OpenAPI spec
npm run generate:api
# 3. Wrap a generated service with search/CRUD helpers
ng generate angular-django2:data-service usersUse ng add angular-django2 to register the collection in angular.json, or add it manually:
{
"cli": {
"schematicCollections": ["angular-django2", "@schematics/angular"]
}
}Local Workspace Commands
npm run lint
npm run build
npm run test:node
npm run test:ci
npm run pack:dry-runPublishing
Build the library and publish the generated package from dist/angular-django2.
For the current unscoped package name:
npm publish ./dist/angular-django2The first successful publish creates the npm package page automatically.
