Skip to content

Commit bdd7014

Browse files
committed
Initial commit
0 parents  commit bdd7014

27 files changed

+2887
-0
lines changed

.editorconfig

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
node_modules
2+
typings
3+
dist
4+
.idea
5+
npm-debug.log
6+
.vscode
7+
yarn.lock
8+

.npmignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.*.swp
2+
._*
3+
.DS_Store
4+
.git
5+
.hg
6+
.npmrc
7+
.lock-wscript
8+
.svn
9+
.wafpickle-*
10+
config.gypi
11+
CVS
12+
npm-debug.log

.travis.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
language: node_js
2+
3+
node_js:
4+
- stable
5+
os:
6+
- linux
7+
8+
branches:
9+
only: master
10+
11+
script: npm run tscv && npm run lint && npm t
12+

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Minko Gechev
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# RxJS Migrations
2+
3+
TSLint rules for migration to the latest version of RxJS.
4+
5+
## Rules
6+
7+
This repository provides the following rules:
8+
9+
| Rule Name | Configuration | Description |
10+
| :-----------------------------: | :-----------: | :-----------------------------------------------------: |
11+
| `collapse-rxjs-imports` | none | Collapses multiple imports from `rxjs` to a single one. |
12+
| `migrate-to-pipeable-operators` | none | Migrates side-effect operators to pipeables. |
13+
| `update-rxjs-imports` | none | Updates RxJS 5.x.x imports to RxJS 6.0 |
14+
15+
## Usage with Angular CLI
16+
17+
1. Build the project:
18+
19+
```bash
20+
git clone https://github.com/mgechev/rxjs-migrate
21+
cd rxjs-migrate && npm i
22+
npm run build
23+
```
24+
25+
2. In your project's directory, create a file called `migrate-rxjs.tslint.json` with the following content:
26+
27+
```json
28+
{
29+
"rulesDirectory": ["path/to/the/compiled/rules"],
30+
"rules": {
31+
"update-rxjs-imports": true,
32+
"migrate-to-pipeable-operators": true,
33+
"collapse-rxjs-imports": true
34+
}
35+
}
36+
```
37+
38+
3. Run tslint:
39+
40+
```bash
41+
./node_modules/.bin/tslint -c migrate-rxjs.tslint.json --project src/tsconfig.app.json
42+
```
43+
44+
4. Enjoy! 😎
45+
46+
### Notes
47+
48+
* Once you run all the migrations check the diff and make sure that everything looks as expected. If you see any issues, open an issue at https://github.com/angular/angular-cli.
49+
* Although the migration will format your source code, it's likely that that the style is not consistent with the rest of your project. To make sure that everything is properly following your project's style guide, use a formatter such as prettier or clang-format.
50+
51+
## License
52+
53+
MIT

appveyor.yml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# AppVeyor file
2+
# http://www.appveyor.com/docs/appveyor-yml
3+
# This file: cloned from https://github.com/gruntjs/grunt/blob/master/appveyor.yml
4+
5+
# Build version format
6+
version: "{build}"
7+
8+
# Test against this version of Node.js
9+
environment:
10+
nodejs_version: "Stable"
11+
12+
build: off
13+
14+
clone_depth: 10
15+
16+
# Fix line endings on Windows
17+
init:
18+
- git config --global core.autocrlf true
19+
20+
install:
21+
- ps: Install-Product node $env:nodejs_version
22+
- npm install -g [email protected]
23+
- ps: $env:path = $env:appdata + "\npm;" + $env:path
24+
- npm install
25+
26+
test_script:
27+
# Output useful info for debugging.
28+
- node --version && npm --version
29+
# We test multiple Windows shells because of prior stdout buffering issues
30+
# filed against Grunt. https://github.com/joyent/node/issues/3584
31+
- ps: "npm --version # PowerShell" # Pass comment to PS for easier debugging
32+
- npm t
33+
34+
notifications:
35+
- provider: Webhook
36+
url: https://webhooks.gitter.im/e/cfd8ce5ddee6f3a0b0c9
37+
on_build_success: false
38+
on_build_failure: true
39+
on_build_status_changed: true
40+

build/buildDocs.ts

+192
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
/*
2+
* Copyright 2016 Palantir Technologies, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the 'License');
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an 'AS IS' BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/*
18+
* This TS script reads the metadata from each TSLint built-in rule
19+
* and serializes it in a format appropriate for the docs website.
20+
*
21+
* This script expects there to be a tslint-gh-pages directory
22+
* parallel to the main tslint directory. The tslint-gh-pages should
23+
* have the gh-pages branch of the TSLint repo checked out.
24+
* One easy way to do this is with the following Git command:
25+
*
26+
* ```
27+
* git worktree add -b gh-pages ../tslint-gh-pages origin/gh-pages
28+
* ```
29+
*
30+
* See http://palantir.github.io/tslint/develop/docs/ for more info
31+
*
32+
*/
33+
34+
import * as fs from 'fs';
35+
import * as glob from 'glob';
36+
import stringify = require('json-stringify-pretty-compact');
37+
import * as yaml from 'js-yaml';
38+
import * as path from 'path';
39+
40+
import {IFormatterMetadata, IRuleMetadata} from 'tslint';
41+
42+
type Metadata = IRuleMetadata | IFormatterMetadata;
43+
44+
interface Documented {
45+
metadata: Metadata;
46+
}
47+
48+
interface IDocumentation {
49+
/**
50+
* File name for the json data file listing.
51+
*/
52+
dataFileName: string;
53+
54+
/**
55+
* Exported item name from each file.
56+
*/
57+
exportName: string;
58+
59+
/**
60+
* Pattern matching files to be documented.
61+
*/
62+
globPattern: string;
63+
64+
/**
65+
* Key of the item's name within the metadata object.
66+
*/
67+
nameMetadataKey: string;
68+
69+
/**
70+
* Function to generate individual documentation pages.
71+
*/
72+
pageGenerator: (metadata: any) => string;
73+
74+
/**
75+
* Documentation subdirectory to output to.
76+
*/
77+
subDirectory: string;
78+
}
79+
80+
const DOCS_DIR = '../docs';
81+
82+
process.chdir('./build');
83+
84+
/**
85+
* Documentation definition for rule modules.
86+
*/
87+
const ruleDocumentation: IDocumentation = {
88+
dataFileName: 'rules.json',
89+
exportName: 'Rule',
90+
globPattern: '../dist/src/*Rule.js',
91+
nameMetadataKey: 'ruleName',
92+
pageGenerator: generateRuleFile,
93+
subDirectory: path.join(DOCS_DIR, 'rules'),
94+
};
95+
96+
/**
97+
* Documentation definition for formatter modules.
98+
*/
99+
const formatterDocumentation: IDocumentation = {
100+
dataFileName: 'formatters.json',
101+
exportName: 'Formatter',
102+
globPattern: '../lib/formatters/*Formatter.js',
103+
nameMetadataKey: 'formatterName',
104+
pageGenerator: generateFormatterFile,
105+
subDirectory: path.join(DOCS_DIR, 'formatters'),
106+
};
107+
108+
/**
109+
* Builds complete documentation.
110+
*/
111+
function buildDocumentation(documentation: IDocumentation) {
112+
// Create each module's documentation file.
113+
const paths = glob.sync(documentation.globPattern);
114+
const metadataJson = paths.map((path: string) => {
115+
return buildSingleModuleDocumentation(documentation, path);
116+
});
117+
118+
// Create a data file with details of every module.
119+
buildDocumentationDataFile(documentation, metadataJson);
120+
}
121+
122+
/**
123+
* Produces documentation for a single file/module.
124+
*/
125+
function buildSingleModuleDocumentation(documentation: IDocumentation, modulePath: string): Metadata {
126+
// Load the module.
127+
// tslint:disable-next-line:no-var-requires
128+
const module = require(modulePath);
129+
const DocumentedItem = module[documentation.exportName] as Documented;
130+
if (DocumentedItem !== null && DocumentedItem.metadata !== null) {
131+
// Build the module's page.
132+
const { metadata } = DocumentedItem;
133+
const fileData = documentation.pageGenerator(metadata);
134+
135+
// Ensure a directory exists and write the module's file.
136+
const moduleName = (metadata as any)[documentation.nameMetadataKey];
137+
const fileDirectory = path.join(documentation.subDirectory, moduleName);
138+
if (!fs.existsSync(documentation.subDirectory)) {
139+
fs.mkdirSync(documentation.subDirectory);
140+
}
141+
if (!fs.existsSync(fileDirectory)) {
142+
fs.mkdirSync(fileDirectory);
143+
}
144+
fs.writeFileSync(path.join(fileDirectory, 'index.html'), fileData);
145+
146+
return metadata;
147+
}
148+
}
149+
150+
function buildDocumentationDataFile(documentation: IDocumentation, metadataJson: any[]) {
151+
const dataJson = JSON.stringify(metadataJson, undefined, 2);
152+
fs.writeFileSync(path.join(DOCS_DIR, '_data', documentation.dataFileName), dataJson);
153+
}
154+
155+
/**
156+
* Generates Jekyll data from any item's metadata.
157+
*/
158+
function generateJekyllData(metadata: any, layout: string, type: string, name: string): any {
159+
return {
160+
...metadata,
161+
layout,
162+
title: `${type}: ${name}`,
163+
};
164+
}
165+
166+
/**
167+
* Based off a rule's metadata, generates a Jekyll 'HTML' file
168+
* that only consists of a YAML front matter block.
169+
*/
170+
function generateRuleFile(metadata: IRuleMetadata): string {
171+
if (metadata.optionExamples) {
172+
metadata = { ...metadata };
173+
metadata.optionExamples = (metadata.optionExamples as any[]).map((example) =>
174+
typeof example === 'string' ? example : stringify(example));
175+
}
176+
177+
const yamlData = generateJekyllData(metadata, 'rule', 'Rule', metadata.ruleName);
178+
yamlData.optionsJSON = JSON.stringify(metadata.options, undefined, 2);
179+
return `---\n${yaml.safeDump(yamlData, {lineWidth: 140} as any)}---`;
180+
}
181+
182+
/**
183+
* Based off a formatter's metadata, generates a Jekyll 'HTML' file
184+
* that only consists of a YAML front matter block.
185+
*/
186+
function generateFormatterFile(metadata: IFormatterMetadata): string {
187+
const yamlData = generateJekyllData(metadata, 'formatter', 'TSLint formatter', metadata.formatterName);
188+
return `---\n${yaml.safeDump(yamlData, {lineWidth: 140} as any)}---`;
189+
}
190+
191+
buildDocumentation(ruleDocumentation);
192+
buildDocumentation(formatterDocumentation);

build/package.ts

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
process.stdin.setEncoding('utf8');
2+
3+
const blacklist = [
4+
'scripts',
5+
'devDependencies'
6+
];
7+
8+
process.stdin.resume();
9+
process.stdin.setEncoding('utf8');
10+
11+
let packageJson = '';
12+
process.stdin.on('data', (chunk: string) => {
13+
packageJson += chunk;
14+
});
15+
process.stdin.on('end', () => {
16+
let parsed: any;
17+
try {
18+
parsed = JSON.parse(packageJson);
19+
} catch (e) {
20+
console.error('Cannot parse to JSON');
21+
process.exit(1);
22+
}
23+
const result = {};
24+
Object.keys(parsed).forEach((key: string) => {
25+
if (blacklist.indexOf(key) < 0) {
26+
result[key] = parsed[key];
27+
}
28+
});
29+
process.stdout.write(JSON.stringify(result, null, 2));
30+
packageJson = '';
31+
});
32+

0 commit comments

Comments
 (0)