This repository has been archived by the owner on Oct 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
so eventually users will be able to install typewiz by running: ng add typewiz-angular
- Loading branch information
Showing
11 changed files
with
398 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -48,5 +48,8 @@ | |
"tslint --fix", | ||
"git add" | ||
] | ||
}, | ||
"resolutions": { | ||
"source-map": "0.6.1" | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -1,23 +1,29 @@ | ||
{ | ||
"name": "typewiz-angular", | ||
"version": "1.1.0-1", | ||
"version": "1.1.0", | ||
"main": "dist/patch-angular.js", | ||
"typings": "dist/patch-angular.d.ts", | ||
"repository": "https://github.com/urish/typewiz", | ||
"author": "Uri Shaked <uri@urishaked.com>", | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "rimraf dist && tsc", | ||
"build": "rimraf dist && tsc && copyfiles -u 1 src/**/*.json dist", | ||
"lint": "tslint -p .", | ||
"prepublish": "yarn build" | ||
"prepare": "yarn build" | ||
}, | ||
"files": ["dist"], | ||
"files": [ | ||
"dist" | ||
], | ||
"engines": { | ||
"node": ">= 6.4.0" | ||
}, | ||
"dependencies": { | ||
"@angular-devkit/core": "^0.6.8", | ||
"@angular-devkit/schematics": "^0.6.8", | ||
"@phenomnomnominal/tsquery": "^2.0.0-beta.4", | ||
"typescript": "^2.4.2", | ||
"typewiz-core": "^1.0.2" | ||
}, | ||
"schematics": "./dist/collection.json", | ||
"devDependencies": {} | ||
} |
This file contains 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 @@ | ||
import { patchAngular } from './patch-angular'; | ||
|
||
patchAngular('node_modules'); |
This file contains 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 @@ | ||
// This is the root config file where the schematics are defined. | ||
{ | ||
"$schema": "./node_modules/@angular-devkit/schematics/collection-schema.json", | ||
"schematics": { | ||
// Adds Angular Material to an application without changing any templates | ||
"ng-add": { | ||
"description": "Adds TypeWiz to your Angular project", | ||
"factory": "./install" | ||
} | ||
} | ||
} |
This file contains 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,81 @@ | ||
import { Tree } from '@angular-devkit/schematics'; | ||
import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; | ||
import * as path from 'path'; | ||
|
||
const collectionPath = path.join(__dirname, '../collection.json'); | ||
|
||
describe('my-full-schematic', () => { | ||
it('should install typewiz-webpack and add `prepare` script to package.json', () => { | ||
const runner = new SchematicTestRunner('schematics', collectionPath); | ||
const inputTree = Tree.empty(); | ||
inputTree.create('package.json', '{}'); | ||
const tree = runner.runSchematic('ng-add', {}, inputTree); | ||
|
||
const packageJson = JSON.parse(tree.readContent('package.json')); | ||
expect(packageJson).toEqual({ | ||
devDependencies: { | ||
'typewiz-webpack': '1.1.0', | ||
}, | ||
scripts: { | ||
prepare: 'node node_modules/typewiz-angular/dist/cli', | ||
}, | ||
}); | ||
}); | ||
|
||
it('should upgrade typewiz-webpack to latest if it already exists', () => { | ||
const runner = new SchematicTestRunner('schematics', collectionPath); | ||
const inputTree = Tree.empty(); | ||
inputTree.create( | ||
'package.json', | ||
JSON.stringify({ | ||
devDependencies: { | ||
'typewiz-webpack': '1.0.0', | ||
}, | ||
}), | ||
); | ||
const tree = runner.runSchematic('ng-add', {}, inputTree); | ||
|
||
const packageJson = JSON.parse(tree.readContent('package.json')); | ||
expect(packageJson.devDependencies).toEqual({ | ||
'typewiz-webpack': '1.1.0', | ||
}); | ||
}); | ||
|
||
it('should update the `prepare` script in package.json if it already exists', () => { | ||
const runner = new SchematicTestRunner('schematics', collectionPath); | ||
const inputTree = Tree.empty(); | ||
inputTree.create( | ||
'package.json', | ||
JSON.stringify({ | ||
scripts: { | ||
prepare: 'npm run build', | ||
}, | ||
}), | ||
); | ||
const tree = runner.runSchematic('ng-add', {}, inputTree); | ||
|
||
const packageJson = JSON.parse(tree.readContent('package.json')); | ||
expect(packageJson.scripts).toEqual({ | ||
prepare: 'npm run build && node node_modules/typewiz-angular/dist/cli', | ||
}); | ||
}); | ||
|
||
it('should not update the `prepare` script if it already contains typewiz', () => { | ||
const runner = new SchematicTestRunner('schematics', collectionPath); | ||
const inputTree = Tree.empty(); | ||
inputTree.create( | ||
'package.json', | ||
JSON.stringify({ | ||
scripts: { | ||
prepare: 'npm run build && node node_modules/typewiz-angular/dist/cli', | ||
}, | ||
}), | ||
); | ||
const tree = runner.runSchematic('ng-add', {}, inputTree); | ||
|
||
const packageJson = JSON.parse(tree.readContent('package.json')); | ||
expect(packageJson.scripts).toEqual({ | ||
prepare: 'npm run build && node node_modules/typewiz-angular/dist/cli', | ||
}); | ||
}); | ||
}); |
This file contains 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,35 @@ | ||
import { chain, Rule, SchematicContext, Tree } from '@angular-devkit/schematics'; | ||
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks'; | ||
import { ISchema } from './schema'; | ||
|
||
export default function(options: ISchema): Rule { | ||
return chain([addTypewizToPackageJson]); | ||
} | ||
|
||
export function addTypewizToPackageJson(host: Tree, context: SchematicContext): Tree { | ||
if (host.exists('package.json')) { | ||
const sourceText = host.read('package.json')!.toString('utf-8'); | ||
const json = JSON.parse(sourceText); | ||
|
||
// add dependency | ||
const type = 'devDependencies'; | ||
json[type] = json[type] || {}; | ||
json[type]['typewiz-webpack'] = '1.1.0'; | ||
|
||
// add script | ||
const typewizAngularCommand = 'node node_modules/typewiz-angular/dist/cli'; | ||
json.scripts = json.scripts || {}; | ||
if (json.scripts.prepare) { | ||
if (json.scripts.prepare.indexOf('typewiz-angular') === -1) { | ||
json.scripts.prepare += ' && ' + typewizAngularCommand; | ||
} | ||
} else { | ||
json.scripts.prepare = typewizAngularCommand; | ||
} | ||
|
||
host.overwrite('package.json', JSON.stringify(json, null, 2)); | ||
context.addTask(new NodePackageInstallTask()); | ||
} | ||
|
||
return host; | ||
} |
This file contains 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 @@ | ||
export interface ISchema { | ||
/** Name of the project to target. */ | ||
project?: string; | ||
} |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.