Skip to content

Commit

Permalink
feat: add vscode extension
Browse files Browse the repository at this point in the history
  • Loading branch information
xiejay97 committed Aug 19, 2022
1 parent 6a9e9b5 commit 34501ec
Show file tree
Hide file tree
Showing 40 changed files with 725 additions and 968 deletions.
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"esbenp.prettier-vscode",
"firsttris.vscode-jest-runner",
"dbaeumer.vscode-eslint",
"stylelint.vscode-stylelint"
"stylelint.vscode-stylelint",
"xiejay97.react-devui"
]
}
5 changes: 0 additions & 5 deletions jest.config.js

This file was deleted.

5 changes: 5 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { getJestProjects } from '@nrwl/jest';

export default {
projects: getJestProjects(),
};
2 changes: 1 addition & 1 deletion jest.preset.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const nxPreset = require('@nrwl/jest/preset');
const nxPreset = require('@nrwl/jest/preset').default;

module.exports = { ...nxPreset };
1 change: 0 additions & 1 deletion jest.setup.js

This file was deleted.

20 changes: 12 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,21 @@
"@nrwl/tao": "14.5.6",
"@nrwl/web": "14.5.6",
"@nrwl/workspace": "14.5.6",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "13.3.0",
"@testing-library/react-hooks": "^8.0.1",
"@testing-library/react": "^13.3.0",
"@types/fs-extra": "^9.0.13",
"@types/jest": "^28.1.6",
"@types/glob": "^7.2.0",
"@types/jest": "^27.4.1",
"@types/lodash": "^4.14.182",
"@types/marked": "^4.0.3",
"@types/mocha": "^9.1.1",
"@types/node": "^18.7.3",
"@types/react": "^18.0.17",
"@types/react-dom": "^18.0.6",
"@types/vscode": "^1.70.0",
"@typescript-eslint/eslint-plugin": "^5.33.0",
"@typescript-eslint/parser": "^5.33.0",
"babel-jest": "^28.1.3",
"dotenv": "^16.0.1",
"@vscode/test-electron": "^2.1.5",
"babel-jest": "^27.5.1",
"eslint": "^8.22.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
Expand All @@ -86,9 +87,12 @@
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-tsdoc": "^0.2.16",
"fs-extra": "^10.1.0",
"glob": "^8.0.3",
"husky": "^8.0.1",
"jest": "^28.1.3",
"jest": "^27.5.1",
"lerna": "^5.4.2",
"mocha": "^10.0.0",
"nx": "14.5.6",
"postcss-html": "^1.5.0",
"postcss-markdown": "^1.2.0",
"prettier": "^2.7.1",
Expand All @@ -101,7 +105,7 @@
"stylelint-config-recommended-scss": "^7.0.0",
"stylelint-config-standard": "^27.0.0",
"stylelint-scss": "^4.3.0",
"ts-jest": "^28.0.8",
"ts-jest": "^27.1.4",
"ts-node": "^10.9.1",
"typescript": "~4.7.4",
"yaml-front-matter": "^4.1.1"
Expand Down
1 change: 0 additions & 1 deletion packages/hooks/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ export default {
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/packages/hooks',
setupFilesAfterEnv: ['../../jest.setup.js'],
};
4 changes: 1 addition & 3 deletions packages/hooks/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@
"outputs": ["coverage/packages/hooks"],
"options": {
"jestConfig": "packages/hooks/jest.config.ts",
"passWithNoTests": true,
"codeCoverage": true,
"coverageReporters": ["clover", "json", "lcov", "text"]
"passWithNoTests": true
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/hooks/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node", "@testing-library/jest-dom"]
"types": ["jest", "node"]
},
"include": [
"jest.config.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/icons/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export default {
'^.+\\.[tj]sx?$': 'babel-jest',
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
collectCoverageFrom: ['!./dist/**'],
coverageDirectory: '../../coverage/packages/icons',
setupFilesAfterEnv: ['../../jest.setup.js'],
};
4 changes: 1 addition & 3 deletions packages/icons/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@
"outputs": ["coverage/packages/icons"],
"options": {
"jestConfig": "packages/icons/jest.config.ts",
"passWithNoTests": true,
"codeCoverage": true,
"coverageReporters": ["clover", "json", "lcov", "text"]
"passWithNoTests": true
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/icons/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node", "@testing-library/jest-dom"]
"types": ["jest", "node"]
},
"include": [
"jest.config.ts",
Expand Down
1 change: 0 additions & 1 deletion packages/site/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ export default {
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/packages/site',
setupFilesAfterEnv: ['../../jest.setup.js'],
};
4 changes: 1 addition & 3 deletions packages/site/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@
"outputs": ["coverage/packages/site"],
"options": {
"jestConfig": "packages/site/jest.config.ts",
"passWithNoTests": true,
"codeCoverage": true,
"coverageReporters": ["clover", "json", "lcov", "text"]
"passWithNoTests": true
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/site/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node", "@testing-library/jest-dom"]
"types": ["jest", "node"]
},
"files": ["../../node_modules/@nrwl/react/typings/cssmodule.d.ts", "../../node_modules/@nrwl/react/typings/image.d.ts"],
"include": [
Expand Down
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions packages/ui/components/button/Button.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { DButtonProps } from './Button';
import type { RenderResult } from '@testing-library/react';

import { render } from '@testing-library/react';

import { PREFIX } from '../../__tests__';
import { DButton } from './Button';

describe('DButton', () => {
let buttonRender: (props: DButtonProps) => RenderResult;
let buttonEl: HTMLElement;

beforeEach(() => {
buttonRender = (props) => {
const renderResult = render(<DButton data-testid="button" {...props} />);
buttonEl = renderResult.getByTestId('button');
return renderResult;
};
});

it('should `dType` work', () => {
const type = 'secondary';
buttonRender({ dType: type });
expect(buttonEl.classList.contains(`${PREFIX}button--${type}`)).toBeTruthy();
});
});
2 changes: 1 addition & 1 deletion packages/ui/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export { DAlert } from './alert';
export type { DAnchorProps } from './anchor';
export { DAnchor } from './anchor';

export type { DAutoCompleteProps } from './auto-complete';
export { DAutoCompleteProps } from './auto-complete';
export { DAutoComplete } from './auto-complete';

export type { DAvatarProps } from './avatar';
Expand Down
4 changes: 3 additions & 1 deletion packages/ui/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export default {
'^.+\\.[tj]sx?$': 'babel-jest',
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
collectCoverage: true,
collectCoverageFrom: ['./components/**'],
coverageReporters: ['clover', 'json', 'lcov', 'text'],
coverageDirectory: '../../coverage/packages/ui',
setupFilesAfterEnv: ['../../jest.setup.js'],
};
4 changes: 1 addition & 3 deletions packages/ui/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@
"outputs": ["coverage/packages/ui"],
"options": {
"jestConfig": "packages/ui/jest.config.ts",
"passWithNoTests": true,
"codeCoverage": true,
"coverageReporters": ["clover", "json", "lcov", "text"]
"passWithNoTests": true
}
}
}
Expand Down
1 change: 0 additions & 1 deletion packages/ui/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"files": ["../../node_modules/@nrwl/react/typings/cssmodule.d.ts", "../../node_modules/@nrwl/react/typings/image.d.ts"],
"exclude": [
"jest.config.ts",
"src/tests/**",
"**/*.spec.ts",
"**/*.test.ts",
"**/*.spec.tsx",
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node", "@testing-library/jest-dom"]
"types": ["jest", "node"]
},
"include": [
"jest.config.ts",
Expand Down
1 change: 0 additions & 1 deletion packages/utils/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ export default {
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/packages/utils',
setupFilesAfterEnv: ['../../jest.setup.js'],
};
4 changes: 1 addition & 3 deletions packages/utils/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@
"outputs": ["coverage/packages/utils"],
"options": {
"jestConfig": "packages/utils/jest.config.ts",
"passWithNoTests": true,
"codeCoverage": true,
"coverageReporters": ["clover", "json", "lcov", "text"]
"passWithNoTests": true
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node", "@testing-library/jest-dom"]
"types": ["jest", "node"]
},
"include": [
"jest.config.ts",
Expand Down
10 changes: 10 additions & 0 deletions packages/vscode-extension/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"presets": [
[
"@nrwl/web/babel",
{
"useBuiltIns": "usage"
}
]
]
}
18 changes: 18 additions & 0 deletions packages/vscode-extension/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
10 changes: 10 additions & 0 deletions packages/vscode-extension/.vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.vscode/**
.vscode-test/**
src/**
.gitignore
.yarnrc
vsc-extension-quickstart.md
**/tsconfig.json
**/.eslintrc.json
**/*.map
**/*.ts
9 changes: 9 additions & 0 deletions packages/vscode-extension/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Change Log

All notable changes to the "react-devui" extension will be documented in this file.

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.

## [Unreleased]

- Initial release
3 changes: 3 additions & 0 deletions packages/vscode-extension/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# React DevUI

This is the extension for React DevUI development.
30 changes: 30 additions & 0 deletions packages/vscode-extension/extension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as vscode from 'vscode';

import { createTerminal, getJestConfigPath } from './utils';

export function activate(context: vscode.ExtensionContext) {
console.log('Congratulations, your extension "react-devui" is now active!');

const disposables = [
vscode.commands.registerCommand('run_jest', (uri) => {
const [jestConfigPath, folderPath] = getJestConfigPath(uri.path);
const terminal = createTerminal('react-devui:jest');
terminal.sendText(
String.raw`yarn jest "${uri.path}" --config='${jestConfigPath}' --collectCoverageFrom='[".${folderPath.replace(
/\.test\.|\.spec\./,
'.'
)}"]'`
);
}),
vscode.commands.registerCommand('run_jest_folder', (uri) => {
const [jestConfigPath, folderPath] = getJestConfigPath(uri.path);
const terminal = createTerminal('react-devui:jest');
terminal.sendText(String.raw`yarn jest "${uri.path}" --config='${jestConfigPath}' --collectCoverageFrom='[".${folderPath}/**"]'`);
}),
];

context.subscriptions.push(...disposables);
}

// eslint-disable-next-line @typescript-eslint/no-empty-function
export function deactivate() {}
Loading

0 comments on commit 34501ec

Please sign in to comment.