Skip to content

Commit

Permalink
first commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlieGreenman committed Jan 22, 2023
0 parents commit 710ffa6
Show file tree
Hide file tree
Showing 206 changed files with 5,363 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
coverage
10 changes: 10 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "jest"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:jest/recommended"
]
}
21 changes: 21 additions & 0 deletions .github/workflows/pr-devops.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Run Unit Tests

on:
pull_request:
branches: [ main ]
workflow_dispatch:
jobs:
DevOpsPRUnitTests:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Login to DockerHub Registry
run: echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
- name: Build Private Dependencies And Test
run: |
sudo apt install -y jq
echo "//npm.pkg.github.com/:_authToken=${{ secrets.GitHubToken }}" >> ~/.npmrc
npm install
npm run build
npm test -- -u
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
dist
lib
.env
.DS_Store
8 changes: 8 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.vscode
node_modules
.env
.idea
lib
build
package-lock.json
yarn-lock
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"printWidth": 120,
"trailingComma": "all",
"singleQuote": true,
"tabWidth": 2
}
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"terminal.integrated.shellArgs.linux": [
"-i"
],
"terminal.integrated.shellArgs.windows": [
"-NoProfile"
]
}
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2013-present Pagar.me Pagamentos S/A

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.
102 changes: 102 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Razzle
Razzle is an extensible, easy to understand, easy contribute, easy to use Codemod library. Razzle-dazzle your codebase like you've never before.

# Novelty behind Razzle library

What the Razzle library does that is unique, is that it creates a unified interface across different programming languages. It uses a simple object to make modifications. e.g.

### Typescript
```
{
"import": '{ NgModule }',
"path": '@angular/core'
}
```

### SCSS
```
{
"import": '',
"path": 'libs/common/styles/razroo-styles.scss'
}
```

## Assumption Made
Razzle is always used in an editing circumstance. There is no need to speicify that file is being editied. Razzle will update the string

## Benefits of such
1. This will be consumer facing. By allowing a singular object, we can simplify the frontend shown to users in the content management system.
2. Developers don't have to dig into specifics for each programming language. They can simply keep an eye on the top level interface.

# Further reading via Razroo blog(soon to be it's own documentation site)

blog.razroo.com


# APIS Available

## Typescript

1. `import`
2. `editImport`
3. `classDeclaration`
4. `classMethod`
5. `addNgModuleImport`
6. `addNgModuleProvider`
7. `addNgModuleImportToSpec`
8. `addToVariableObject`
9. `addConstructorMethod`
```
{
nodeType: 'addConstructorMethod',
codeBlock: 'userService',
type: 'UserService'
}
```
10. addVariableDeclarationStatement
```
{
nodeType: 'addVariableDeclarationStatement',
codeBlock: 'gtag',
type: 'Function'
}
```

## JSON

1. `editJson`
2. `addJsonKeyValue`

## SCSS

1. `addScssBlock`
2. `import`


## Angular HTML + HTML

1. `editHtmlTag`
```
{
"nodeType": "editHtmlTag",
"codeBlock": "matSort",
"tagNameToModify": "mat-table"
}
```
2. `addSiblingHtml`
```
{
"nodeType": "addSiblingHtml",
"codeBlock": "<script async src=\"https://www.googletagmanager.com/gtag/js?id=G-YOUR-GOOGLE-ID\"></script>",
"tagNameToInsert": "script",
"siblingTagName": "link"
},
```
3. `insertIntoHtmlTag`
```
{
"nodeType": "insertIntoHtmlTag",
"codeBlock": "<div class=\"Toolbar__Icons\"><fa-icon [icon]=\"faBell\" aria-hidden=\"false\" aria-label=\"Notification Icon\"></fa-icon> <fa-icon [icon]=\"faQuestionCircle\" aria-hidden=\"false\" aria-label=\"Question Icon\"></fa-icon> <fa-icon [icon]=\"faUserCircle\" aria-hidden=\"false\" aria-label=\"Account Icon\"></fa-icon></div>",
"tagNameToInsertInto": "mat-toolbar"
}
```
15 changes: 15 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
preset: 'ts-jest/presets/default-esm',
testEnvironment: 'node',
transform: {
'^.+\\.(t|j)s$': 'ts-jest'
},
globals: {
'ts-jest': {
diagnostics: false,
useESM: true
}
},
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(t|j)s$',
moduleFileExtensions: ['ts', 'js', 'json', 'node'],
};
99 changes: 99 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
"name": "@razroo/razzle",
"version": "1.0.0",
"description": "Razzle is an extensible, easy to understand, easy contribute, easy to use Codemod library.",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"build": "tsc",
"format": "prettier --write \"src/**/*.(js|ts)\"",
"lint": "eslint src --ext .js,.ts",
"lint:fix": "eslint src --fix --ext .js,.ts",
"test": "jest --config jest.config.js",
"publish": "npm publish"
},
"publishConfig": {
"registry": "https://npm.pkg.github.com"
},
"repository": {
"type": "git",
"url": "https://github.com/razroo/razzle"
},
"keywords": [
"razroo",
"codemod"
],
"author": "Razroo",
"license": "RAZROO",
"bugs": {
"url": "https://github.com/razroo/razzle/issues"
},
"homepage": "https://github.com/razroo/razzle#readme",
"devDependencies": {
"@angular-devkit/build-angular": "~13.0.0",
"@angular-devkit/build-optimizer": "~0.1300.0",
"@angular-devkit/build-webpack": "~0.1300.0",
"@angular-devkit/schematics": "~13.0.0",
"@angular-eslint/eslint-plugin": "~13.0.1",
"@angular-eslint/eslint-plugin-template": "~13.0.1",
"@angular-eslint/template-parser": "~13.0.1",
"@angular/cli": "~13.0.0",
"@angular/common": "^13.0.0",
"@angular/compiler": "^13.0.0",
"@angular/compiler-cli": "^13.0.0",
"@angular/core": "^13.0.0",
"@angular/forms": "^13.0.0",
"@angular/platform-browser": "^13.0.0",
"@angular/platform-browser-dynamic": "^13.0.0",
"@angular/router": "^13.0.0",
"@angular/service-worker": "^13.0.0",
"@angular/upgrade": "^13.0.0",
"@angular-devkit/architect": "~0.1300.0",
"@angular-devkit/core": "~13.0.0",
"@types/jest": "^27.5.2",
"@types/tinycolor2": "^1.4.3",
"@typescript-eslint/eslint-plugin": "^4.5.0",
"@typescript-eslint/parser": "^4.5.0",
"babel-jest": "^27.4.6",
"eslint": "^7.11.0",
"eslint-plugin-jest": "^24.1.0",
"jest": "^27.0.7",
"ts-jest": "^27.1.5",
"tsup": "^6.2.3",
"typescript": "^4.0.3",
"yargs-parser": "20.0.0"
},
"dependencies": {
"@ctrl/tinycolor": "^3.4.1",
"chalk": "4.1.0",
"ejs": "^3.1.5",
"enquirer": "~2.3.6",
"fast-glob": "3.2.7",
"glob": "^8.0.3",
"hast-util-from-parse5": "6.0.1",
"hast-util-to-html": "7.1.3",
"ignore": "^5.0.4",
"json-pointer": "^0.6.2",
"json-to-ast": "^2.1.0",
"jsonc-parser": "3.0.0",
"jsonpath-plus": "^6.0.1",
"parse5": "^6.0.1",
"path": "^0.12.7",
"prettier": "^2.3.0",
"query-ast": "^1.0.4",
"rxjs": "^6.5.4",
"rxjs-for-await": "0.0.2",
"scss-parser": "^1.0.5",
"semver": "7.3.4",
"tmp": "~0.2.1",
"to-vfile": "^7.2.3",
"ts-morph": "^15.1.0",
"tslib": "^2.3.0",
"unist-util-visit": "2.0.3",
"unist-util-visit-parents": "3.1.1",
"yargs-parser": "20.0.0"
},
"files": [
"dist/**/*"
]
}
27 changes: 27 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// color related items
export { getPalette, createColorVariables } from './rz/global-variables';

// export { Blah as default } from './lib'
export { replaceTagParameters, replaceCurlyBrace } from './replace';

// general utils
export { getVersionAndNameString, determineType, determineFilePathParameter, readPackageJson, extractProjectName,
getAllDirectoriesFromVsCodeFolder, getProjectDependencies, determineLanguagesUsed, replaceCodeModEditsTemplateVariables } from './rz/utils';

// export typescript related edits
export { EditInput, EditFile, morphCode, effects, communityPaths, types } from './rz/morph';

// export typescript related edits
export { getCodeModParams, getCodeModOptions } from './rz/params';

// global variables
export { names, codeCmsVariablesToIgnore, powerUpVariables, powerUpVariablesFlatData } from './rz/global-variables';

// global variables interfaces
export { CodeCmsVariablesToIgnore, PowerUpVariables } from './rz/global-variables/interfaces';

// types for angular code generation side-effects
export { angularTypes, AngularTypeNames, defaultAngularTechnologies } from './rz/angular';

// types react code generation side-effects
export { reactTypes, ReactTypeNames } from './rz/react';
37 changes: 37 additions & 0 deletions src/replace.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { replaceCurlyBrace } from './replace';

describe('replaceCurlyBrace', () => {
it('should replaceCurlyBrace with respective parameters', () => {
const mockParameters = {
name: 'test',
selector: 'test-two',
className: ''
};
const mockFileStringWithCurlyBrace = 'src/{selector}/{name}.component.html';

const result = replaceCurlyBrace(mockParameters, mockFileStringWithCurlyBrace);
const expected = 'src/test-two/test.component.html';

expect(result).toEqual(expected);
});

it('should replace with curly braces if curly brace values shows up more than once', () => {
const mockParameters = {
nameFilePath:"libs/common/ui/src/lib/{name}-dialog",
name:"blue",
projectName:"razroo-angular-starter",
className:"Blue",
propertyName:"blue",
constantName:"BLUE",
fileName:"blue",
titleName:"Blue"
};
const mockFileStringWithCurlyBrace = '{nameFilePath}/{name}-dialog.component.ts';

const result = replaceCurlyBrace(mockParameters, mockFileStringWithCurlyBrace);
const expected = 'libs/common/ui/src/lib/blue-dialog/blue-dialog.component.ts';

expect(result).toEqual(expected);
})

});
Loading

0 comments on commit 710ffa6

Please sign in to comment.