This repository was archived by the owner on Feb 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 490
Feat: ng add support #1433
Merged
Merged
Feat: ng add support #1433
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,11 @@ | |
"description": "Angular directive for DataTables", | ||
"scripts": { | ||
"build": "npm run clean && npm run compile && npm run bundles", | ||
"clean": "rimraf -f index.{d.ts,js,js.map,metadata.json} src/*.{d.ts,js,map,metadata.json} bundles", | ||
"clean": "rimraf -f index.{d.ts,js,js.map,metadata.json} src/*.{d.ts,js,map,metadata.json} bundles schematics/**/*.{d.ts,js,map}", | ||
"compile": "npm run lint:code && ngc -p tsconfig-build.json", | ||
"compile:tsc": "npm run lint && tsc -p tsconfig.json", | ||
"bundles": "npm run rollup && npm run rollup:min", | ||
"schematics:build": "tsc -p schematics/tsconfig.json", | ||
"lint": "npm run lint:code && npm run lint:test", | ||
"lint:code": "tslint ./src/**/*.ts -t verbose --exclude ./src/**/*.d.ts", | ||
"lint:test": "tslint ./test/**/*.ts -t verbose --exclude ./test/**/*.d.ts", | ||
|
@@ -23,6 +24,7 @@ | |
"Michael Bennett <[email protected]>", | ||
"Steven Masala <[email protected]>" | ||
], | ||
"schematics": "./schematics/src/collection.json", | ||
"main": "bundles/angular-datatables.umd.js", | ||
"module": "index.js", | ||
"typings": "index.d.ts", | ||
|
@@ -38,6 +40,8 @@ | |
"jquery": ">=3.4.1" | ||
}, | ||
"devDependencies": { | ||
"@angular-devkit/core": "^9.0.5", | ||
"@angular-devkit/schematics": "^9.0.5", | ||
"@angular/common": "^8.0.0", | ||
"@angular/compiler": "^8.0.0", | ||
"@angular/compiler-cli": "^8.0.0", | ||
|
@@ -66,6 +70,7 @@ | |
"rollup": "~1.15.0", | ||
"rollup-plugin-uglify": "~6.0.2", | ||
"rxjs": "^6.5.2", | ||
"schematics-utilities": "^2.0.1", | ||
"tslint": "~5.17.0", | ||
"typescript": "~3.4.5", | ||
"zone.js": "~0.9.1" | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[*] | ||
charset = utf-8 | ||
indent_size = 2 | ||
indent_style = space |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Outputs | ||
src/**/*.js | ||
src/**/*.js.map | ||
src/**/*.d.ts | ||
dist/ | ||
|
||
# IDEs | ||
.idea/ | ||
jsconfig.json | ||
.vscode/ | ||
|
||
# Misc | ||
node_modules/ | ||
npm-debug.log* | ||
yarn-error.log* | ||
|
||
# Mac OSX Finder files. | ||
**/.DS_Store | ||
.DS_Store |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Ignores TypeScript files, but keeps definitions. | ||
*.ts | ||
!*.d.ts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"$schema": "../../node_modules/@angular-devkit/schematics/collection-schema.json", | ||
"schematics": { | ||
"ng-add": { | ||
"description": "Adds Angular Datatables to the application without affecting any templates", | ||
"factory": "./ng-add/index", | ||
"schema": "./ng-add/schema.json", | ||
"aliases": ["install"] | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { Rule, SchematicContext, Tree, chain } from '@angular-devkit/schematics'; | ||
import { | ||
addPackageJsonDependency, NodeDependency, NodeDependencyType, getWorkspace, | ||
getProjectFromWorkspace, addModuleImportToRootModule | ||
} from 'schematics-utilities'; | ||
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks'; | ||
|
||
export default function (_options: any): Rule { | ||
return chain([ | ||
addPackageJsonDependencies(), | ||
installPackageJsonDependencies(), | ||
updateAngularJsonFile(), | ||
addModuleToAppModule() | ||
]); | ||
} | ||
|
||
function addPackageJsonDependencies() { | ||
return (tree: Tree, context: SchematicContext) => { | ||
// Update package.json | ||
const dependencies: NodeDependency[] = [ | ||
{ type: NodeDependencyType.Default, version: '3.4.1', name: 'jquery' }, | ||
{ type: NodeDependencyType.Default, version: '1.1.0', name: 'datatables.net' }, | ||
{ type: NodeDependencyType.Default, version: '1.1.0', name: 'datatables.net-dt' }, | ||
{ type: NodeDependencyType.Default, version: '1.1.0', name: 'angular-datatables' }, | ||
{ type: NodeDependencyType.Dev, version: '1.1.0', name: '@types/jquery' }, | ||
{ type: NodeDependencyType.Dev, version: '1.1.0', name: '@types/datatables.net' } | ||
]; | ||
|
||
dependencies.forEach(dependency => { | ||
|
||
addPackageJsonDependency(tree, dependency); | ||
context.logger.log('info', `✅️ Added "${dependency.name}" into ${dependency.type}`); | ||
}); | ||
return tree | ||
} | ||
} | ||
|
||
function installPackageJsonDependencies(): Rule { | ||
return (host: Tree, context: SchematicContext) => { | ||
context.addTask(new NodePackageInstallTask()); | ||
context.logger.log('info', `🔍 Installing packages...`); | ||
|
||
return host; | ||
}; | ||
} | ||
|
||
|
||
function updateAngularJsonFile() { | ||
return (tree: Tree, context: SchematicContext) => { | ||
try { | ||
const angularJsonFile = tree.read('angular.json'); | ||
|
||
if (angularJsonFile) { | ||
const angularJsonFileObject = JSON.parse(angularJsonFile.toString('utf-8')); | ||
const project = Object.keys(angularJsonFileObject['projects'])[0]; | ||
const projectObject = angularJsonFileObject.projects[project]; | ||
|
||
const styles = projectObject.targets.build.options.styles; | ||
const scripts = projectObject.targets.build.options.scripts; | ||
|
||
styles.push({ | ||
input: "node_modules/datatables.net-dt/css/jquery.dataTables.css" | ||
}); | ||
|
||
scripts.push({ | ||
input: "node_modules/jquery/dist/jquery.js" | ||
}); | ||
|
||
scripts.push({ | ||
input: "node_modules/datatables.net/js/jquery.dataTables.js" | ||
}); | ||
|
||
tree.overwrite('angular.json', JSON.stringify(angularJsonFileObject, null, 2)); | ||
context.logger.log('info', `✅️ Updated angular.json`); | ||
} else { | ||
context.logger.log('error', '🚫 Failed to locate angular.json.') | ||
} | ||
} catch (e) { | ||
context.logger.log('error', `🚫 Failed to update angular.json.`); | ||
} | ||
|
||
} | ||
} | ||
|
||
function addModuleToAppModule(): Rule { | ||
return (host: Tree, context: SchematicContext) => { | ||
const moduleName = 'DataTablesModule'; | ||
try { | ||
const workspace = getWorkspace(host); | ||
const project = getProjectFromWorkspace( | ||
workspace, | ||
Object.keys(workspace['projects'])[0] | ||
); | ||
addModuleImportToRootModule(host, moduleName, 'angular-datatables', project); | ||
} catch (e) { | ||
context.logger.log('error', `🚫 Failed to update app.module.ts`); | ||
return host; | ||
} | ||
context.logger.log('info', `✅️ "${moduleName}" is imported`); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"id": "angular-datatables-schematic-angular-datatables", | ||
"title": "Angular DataTables angular-datatables schematic", | ||
"type": "object", | ||
"properties": { | ||
"project": { | ||
"title": "angular-datatables", | ||
"type": "string", | ||
"description": "The name of the project.", | ||
"$default": { | ||
"$source": "projectName" | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": "tsconfig", | ||
"lib": [ | ||
"es2018", | ||
"dom" | ||
], | ||
"declaration": true, | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"noEmitOnError": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitAny": true, | ||
"noImplicitThis": true, | ||
"noUnusedParameters": true, | ||
"noUnusedLocals": true, | ||
"rootDir": "src/", | ||
"skipDefaultLibCheck": true, | ||
"skipLibCheck": true, | ||
"sourceMap": true, | ||
"strictNullChecks": true, | ||
"target": "es6", | ||
"types": [ | ||
"jasmine", | ||
"node" | ||
] | ||
}, | ||
"include": [ | ||
"src/**/*" | ||
], | ||
"exclude": [ | ||
"src/*/files/**/*" | ||
] | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.