Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mgechev committed Mar 31, 2018
0 parents commit bdd7014
Show file tree
Hide file tree
Showing 27 changed files with 2,887 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .editorconfig
@@ -0,0 +1,5 @@
root = true

[*]
indent_style = space
indent_size = 2
8 changes: 8 additions & 0 deletions .gitignore
@@ -0,0 +1,8 @@
node_modules
typings
dist
.idea
npm-debug.log
.vscode
yarn.lock

12 changes: 12 additions & 0 deletions .npmignore
@@ -0,0 +1,12 @@
.*.swp
._*
.DS_Store
.git
.hg
.npmrc
.lock-wscript
.svn
.wafpickle-*
config.gypi
CVS
npm-debug.log
12 changes: 12 additions & 0 deletions .travis.yml
@@ -0,0 +1,12 @@
language: node_js

node_js:
- stable
os:
- linux

branches:
only: master

script: npm run tscv && npm run lint && npm t

21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Minko Gechev

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
53 changes: 53 additions & 0 deletions README.md
@@ -0,0 +1,53 @@
# RxJS Migrations

TSLint rules for migration to the latest version of RxJS.

## Rules

This repository provides the following rules:

| Rule Name | Configuration | Description |
| :-----------------------------: | :-----------: | :-----------------------------------------------------: |
| `collapse-rxjs-imports` | none | Collapses multiple imports from `rxjs` to a single one. |
| `migrate-to-pipeable-operators` | none | Migrates side-effect operators to pipeables. |
| `update-rxjs-imports` | none | Updates RxJS 5.x.x imports to RxJS 6.0 |

## Usage with Angular CLI

1. Build the project:

```bash
git clone https://github.com/mgechev/rxjs-migrate
cd rxjs-migrate && npm i
npm run build
```

2. In your project's directory, create a file called `migrate-rxjs.tslint.json` with the following content:

```json
{
"rulesDirectory": ["path/to/the/compiled/rules"],
"rules": {
"update-rxjs-imports": true,
"migrate-to-pipeable-operators": true,
"collapse-rxjs-imports": true
}
}
```

3. Run tslint:

```bash
./node_modules/.bin/tslint -c migrate-rxjs.tslint.json --project src/tsconfig.app.json
```

4. Enjoy! 😎

### Notes

* 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.
* 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.

## License

MIT
40 changes: 40 additions & 0 deletions appveyor.yml
@@ -0,0 +1,40 @@
# AppVeyor file
# http://www.appveyor.com/docs/appveyor-yml
# This file: cloned from https://github.com/gruntjs/grunt/blob/master/appveyor.yml

# Build version format
version: "{build}"

# Test against this version of Node.js
environment:
nodejs_version: "Stable"

build: off

clone_depth: 10

# Fix line endings on Windows
init:
- git config --global core.autocrlf true

install:
- ps: Install-Product node $env:nodejs_version
- npm install -g npm@3.10.8
- ps: $env:path = $env:appdata + "\npm;" + $env:path
- npm install

test_script:
# Output useful info for debugging.
- node --version && npm --version
# We test multiple Windows shells because of prior stdout buffering issues
# filed against Grunt. https://github.com/joyent/node/issues/3584
- ps: "npm --version # PowerShell" # Pass comment to PS for easier debugging
- npm t

notifications:
- provider: Webhook
url: https://webhooks.gitter.im/e/cfd8ce5ddee6f3a0b0c9
on_build_success: false
on_build_failure: true
on_build_status_changed: true

192 changes: 192 additions & 0 deletions build/buildDocs.ts
@@ -0,0 +1,192 @@
/*
* Copyright 2016 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* This TS script reads the metadata from each TSLint built-in rule
* and serializes it in a format appropriate for the docs website.
*
* This script expects there to be a tslint-gh-pages directory
* parallel to the main tslint directory. The tslint-gh-pages should
* have the gh-pages branch of the TSLint repo checked out.
* One easy way to do this is with the following Git command:
*
* ```
* git worktree add -b gh-pages ../tslint-gh-pages origin/gh-pages
* ```
*
* See http://palantir.github.io/tslint/develop/docs/ for more info
*
*/

import * as fs from 'fs';
import * as glob from 'glob';
import stringify = require('json-stringify-pretty-compact');
import * as yaml from 'js-yaml';
import * as path from 'path';

import {IFormatterMetadata, IRuleMetadata} from 'tslint';

type Metadata = IRuleMetadata | IFormatterMetadata;

interface Documented {
metadata: Metadata;
}

interface IDocumentation {
/**
* File name for the json data file listing.
*/
dataFileName: string;

/**
* Exported item name from each file.
*/
exportName: string;

/**
* Pattern matching files to be documented.
*/
globPattern: string;

/**
* Key of the item's name within the metadata object.
*/
nameMetadataKey: string;

/**
* Function to generate individual documentation pages.
*/
pageGenerator: (metadata: any) => string;

/**
* Documentation subdirectory to output to.
*/
subDirectory: string;
}

const DOCS_DIR = '../docs';

process.chdir('./build');

/**
* Documentation definition for rule modules.
*/
const ruleDocumentation: IDocumentation = {
dataFileName: 'rules.json',
exportName: 'Rule',
globPattern: '../dist/src/*Rule.js',
nameMetadataKey: 'ruleName',
pageGenerator: generateRuleFile,
subDirectory: path.join(DOCS_DIR, 'rules'),
};

/**
* Documentation definition for formatter modules.
*/
const formatterDocumentation: IDocumentation = {
dataFileName: 'formatters.json',
exportName: 'Formatter',
globPattern: '../lib/formatters/*Formatter.js',
nameMetadataKey: 'formatterName',
pageGenerator: generateFormatterFile,
subDirectory: path.join(DOCS_DIR, 'formatters'),
};

/**
* Builds complete documentation.
*/
function buildDocumentation(documentation: IDocumentation) {
// Create each module's documentation file.
const paths = glob.sync(documentation.globPattern);
const metadataJson = paths.map((path: string) => {
return buildSingleModuleDocumentation(documentation, path);
});

// Create a data file with details of every module.
buildDocumentationDataFile(documentation, metadataJson);
}

/**
* Produces documentation for a single file/module.
*/
function buildSingleModuleDocumentation(documentation: IDocumentation, modulePath: string): Metadata {
// Load the module.
// tslint:disable-next-line:no-var-requires
const module = require(modulePath);
const DocumentedItem = module[documentation.exportName] as Documented;
if (DocumentedItem !== null && DocumentedItem.metadata !== null) {
// Build the module's page.
const { metadata } = DocumentedItem;
const fileData = documentation.pageGenerator(metadata);

// Ensure a directory exists and write the module's file.
const moduleName = (metadata as any)[documentation.nameMetadataKey];
const fileDirectory = path.join(documentation.subDirectory, moduleName);
if (!fs.existsSync(documentation.subDirectory)) {
fs.mkdirSync(documentation.subDirectory);
}
if (!fs.existsSync(fileDirectory)) {
fs.mkdirSync(fileDirectory);
}
fs.writeFileSync(path.join(fileDirectory, 'index.html'), fileData);

return metadata;
}
}

function buildDocumentationDataFile(documentation: IDocumentation, metadataJson: any[]) {
const dataJson = JSON.stringify(metadataJson, undefined, 2);
fs.writeFileSync(path.join(DOCS_DIR, '_data', documentation.dataFileName), dataJson);
}

/**
* Generates Jekyll data from any item's metadata.
*/
function generateJekyllData(metadata: any, layout: string, type: string, name: string): any {
return {
...metadata,
layout,
title: `${type}: ${name}`,
};
}

/**
* Based off a rule's metadata, generates a Jekyll 'HTML' file
* that only consists of a YAML front matter block.
*/
function generateRuleFile(metadata: IRuleMetadata): string {
if (metadata.optionExamples) {
metadata = { ...metadata };
metadata.optionExamples = (metadata.optionExamples as any[]).map((example) =>
typeof example === 'string' ? example : stringify(example));
}

const yamlData = generateJekyllData(metadata, 'rule', 'Rule', metadata.ruleName);
yamlData.optionsJSON = JSON.stringify(metadata.options, undefined, 2);
return `---\n${yaml.safeDump(yamlData, {lineWidth: 140} as any)}---`;
}

/**
* Based off a formatter's metadata, generates a Jekyll 'HTML' file
* that only consists of a YAML front matter block.
*/
function generateFormatterFile(metadata: IFormatterMetadata): string {
const yamlData = generateJekyllData(metadata, 'formatter', 'TSLint formatter', metadata.formatterName);
return `---\n${yaml.safeDump(yamlData, {lineWidth: 140} as any)}---`;
}

buildDocumentation(ruleDocumentation);
buildDocumentation(formatterDocumentation);
32 changes: 32 additions & 0 deletions build/package.ts
@@ -0,0 +1,32 @@
process.stdin.setEncoding('utf8');

const blacklist = [
'scripts',
'devDependencies'
];

process.stdin.resume();
process.stdin.setEncoding('utf8');

let packageJson = '';
process.stdin.on('data', (chunk: string) => {
packageJson += chunk;
});
process.stdin.on('end', () => {
let parsed: any;
try {
parsed = JSON.parse(packageJson);
} catch (e) {
console.error('Cannot parse to JSON');
process.exit(1);
}
const result = {};
Object.keys(parsed).forEach((key: string) => {
if (blacklist.indexOf(key) < 0) {
result[key] = parsed[key];
}
});
process.stdout.write(JSON.stringify(result, null, 2));
packageJson = '';
});

0 comments on commit bdd7014

Please sign in to comment.