Skip to content

Commit 30edd2b

Browse files
authored
feat(Codebytes): move codebytes parent disc 351 (#11)
* move parent * remove extra assets * remove rendermode * remove consts * remove unused type * add babel config to package * fix prettier * remove unneccessary dependencies * change to codebyte editor * change name to code byte editor * update main.js * add webpack config * ignore dist files * move storybook outside package * remove codebyte-editor * update changelog * update styleguide package.json * run prettier * additional cleanup based on feedback * prettier * remove unused packages
1 parent f077870 commit 30edd2b

File tree

16 files changed

+8070
-229
lines changed

16 files changed

+8070
-229
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = {
1616
},
1717
},
1818
{
19-
files: ['**/jest/*'],
19+
files: ['**/jest/*', '**/*.stories.mdx'],
2020
rules: {
2121
'import/no-extraneous-dependencies': [
2222
'error',

.vscode/settings.json

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,40 @@
11
{
22
"eslint.options": {
3-
"extensions": [".js", ".jsx", ".md", ".ts", ".tsx"]
3+
"extensions": [".js", ".jsx", ".md", ".mdx", ".ts", ".tsx"]
44
},
55
"eslint.probe": [
6+
"mdx",
67
"markdown",
78
"javascript",
89
"javascriptreact",
910
"typescript",
1011
"typescriptreact",
1112
"html"
1213
],
13-
"eslint.rules.customizations": [{ "rule": "*", "severity": "downgrade" }],
1414
"eslint.validate": [
15+
"mdx",
1516
"markdown",
1617
"javascript",
1718
"javascriptreact",
1819
"typescript",
1920
"typescriptreact",
2021
"html"
2122
],
23+
"files.associations": {
24+
"*.md": "mdx"
25+
},
26+
"[mdx]": {
27+
"editor.wordWrap": "wordWrapColumn",
28+
"editor.wordWrapColumn": 120,
29+
"editor.codeActionsOnSave": {
30+
"source.fixAll": true
31+
}
32+
},
2233
"search.exclude": {
2334
"docs": true
2435
},
25-
"typescript.tsdk": "node_modules/typescript/lib"
36+
"typescript.tsdk": "node_modules/typescript/lib",
37+
"editor.codeActionsOnSave": {
38+
"source.fixAll.eslint": true
39+
}
2640
}

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
"verify-changed": "lerna run verify --since --include-dependencies",
2222
"clear-modules": "lerna clean -y && rm -rf node_modules",
2323
"build-all": "lerna run lernaBuildTask",
24-
"build-changed": "lerna run lernaBuildTask --since --include-dependencies"
24+
"build-changed": "lerna run lernaBuildTask --since --include-dependencies",
25+
"start:storybook": "cd ./packages/styleguide && yarn start",
26+
"start": "yarn && yarn start:storybook"
2527
},
2628
"lint-staged": {
2729
"**/*.{js,ts,tsx,json}": [
@@ -45,6 +47,7 @@
4547
"lerna": "3.22.1"
4648
},
4749
"devDependencies": {
50+
"@codecademy/webpack-config": "^6.0.0",
4851
"@babel/cli": "7.13.10",
4952
"@babel/core": "7.13.10",
5053
"@babel/preset-typescript": "^7.13.0",

packages/codebytes/babel.config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
presets: ['codecademy', '@babel/preset-typescript'],
3+
plugins: [
4+
[
5+
'@emotion',
6+
{
7+
sourceMap: true,
8+
autoLabel: 'always',
9+
labelFormat: '[local]',
10+
},
11+
],
12+
],
13+
include: ['./src/**/*'],
14+
ignore: ['__tests__', './**/*.d.ts'],
15+
};

packages/codebytes/package.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "@codecademy/codebytes",
3+
"description": "Codebytes Code Editor",
4+
"version": "0.0.1",
5+
"author": "Codecademy Engineering <[email protected]>",
6+
"sideEffects": [
7+
"**/*.css",
8+
"**/*.scss",
9+
"dist/**/[A-Z]**/[A-Z]*.js",
10+
"dist/**/[A-Z]**/index.js"
11+
],
12+
"module": "./dist/index.js",
13+
"main": "./dist/index.js",
14+
"repository": {
15+
"type": "git",
16+
"url": "[email protected]:Codecademy/client-modules.git"
17+
},
18+
"peerDependencies": {
19+
"react": ">=16.8.1",
20+
"react-dom": ">=16.8.1"
21+
},
22+
"dependencies": {
23+
"@codecademy/gamut": "*",
24+
"@codecademy/gamut-styles": "*",
25+
"@codecademy/gamut-icons": "*",
26+
"@emotion/react": "^11.4.0",
27+
"@emotion/styled": "^11.3.0"
28+
},
29+
"scripts": {
30+
"verify": "tsc --noEmit",
31+
"build:compile": "babel ./src --out-dir ./dist --copy-files --extensions \".ts,.tsx\"",
32+
"build:clean": "rm -rf dist",
33+
"build:types": "tsc --emitDeclarationOnly",
34+
"build": "yarn build:clean && yarn build:compile && yarn build:types",
35+
"build:watch": "yarn build && onchange ./src -- yarn build:compile && yarn build:types"
36+
},
37+
"license": "MIT",
38+
"devDependencies": {
39+
"@emotion/jest": "^11.3.0",
40+
"@testing-library/dom": "^7.31.2",
41+
"@testing-library/react": "^11.0.4"
42+
},
43+
"publishConfig": {
44+
"access": "public"
45+
}
46+
}

packages/codebytes/src/editor.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react';
2+
3+
type EditorProps = {
4+
text: string;
5+
onChange: (text: string) => void;
6+
};
7+
8+
export const Editor: React.FC<EditorProps> = ({ text, onChange }) => {
9+
return <textarea value={text} onChange={(e) => onChange(e.target.value)} />;
10+
};

packages/codebytes/src/index.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React, { useState } from 'react';
2+
3+
import { Editor } from './editor';
4+
5+
export interface CodeByteEditorProps {
6+
text: string;
7+
}
8+
9+
export const CodeByteEditor: React.FC<CodeByteEditorProps> = ({
10+
text: initialText,
11+
}) => {
12+
const [text, setText] = useState<string>(initialText);
13+
return (
14+
<>
15+
<Editor
16+
text={text}
17+
onChange={(newText: string) => {
18+
setText(newText);
19+
}}
20+
/>
21+
</>
22+
);
23+
};
24+
25+
export default CodeByteEditor;

packages/codebytes/tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"include": ["../../typings/*.d.ts", "./src/**/*.ts", "./src/**/*.tsx"]
4+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module.exports = {
2+
presets: ['codecademy', '@babel/preset-typescript'],
3+
plugins: [
4+
'macros',
5+
[
6+
'@emotion',
7+
{
8+
sourceMap: true,
9+
autoLabel: 'always',
10+
labelFormat: '[local]',
11+
cssPropOptimization: true,
12+
},
13+
],
14+
],
15+
ignore: [],
16+
env: {
17+
test: {
18+
plugins: ['require-context-hook'],
19+
},
20+
},
21+
};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const path = require('path');
2+
const { configs } = require('@codecademy/webpack-config');
3+
4+
// https://github.com/storybookjs/storybook/issues/12262#issuecomment-681953346
5+
// make a shallow copy of an object, rejecting keys that match /emotion/
6+
function emotionless<T extends Record<string, unknown>>(object: T) {
7+
let result = {} as T;
8+
for (let key in object) {
9+
if (!/emotion/.test(key)) {
10+
result[key] = object[key];
11+
}
12+
}
13+
return result;
14+
}
15+
16+
module.exports = {
17+
addons: [
18+
'@storybook/addon-essentials',
19+
'@storybook/addon-a11y',
20+
'@storybook/addon-links',
21+
'storybook-addon-designs',
22+
],
23+
stories: ['../stories/**/*.stories.mdx'],
24+
typescript: {
25+
reactDocgen: 'react-docgen-typescript',
26+
reactDocgenTypescriptOptions: {
27+
shouldExtractLiteralValuesFromEnum: true,
28+
shouldRemoveUndefinedFromOptional: true,
29+
},
30+
},
31+
32+
webpackFinal: (config: any) => {
33+
config.module.rules = config.module.rules.concat(
34+
configs.css().module.rules
35+
);
36+
37+
config.resolve = {
38+
...config.resolve,
39+
alias: emotionless(config.resolve.alias),
40+
};
41+
42+
return config;
43+
},
44+
};

0 commit comments

Comments
 (0)