Skip to content

Commit d1acb1c

Browse files
committed
Hello, cruel world!
0 parents  commit d1acb1c

13 files changed

+4440
-0
lines changed

Diff for: .gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
lib
3+
.vscode

Diff for: .prettierrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"singleQuote": true,
3+
"semi": false
4+
}

Diff for: Makefile

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.DEFAULT_GOAL := build
2+
.PHONY: build
3+
4+
SHELL := /bin/bash
5+
PATH := $(shell yarn bin):$(PATH)
6+
7+
test:
8+
jest
9+
.PHONY: test
10+
11+
test-watch:
12+
jest --watch
13+
14+
build:
15+
@rm -rf lib
16+
@tsc
17+
@prettier "**/*.[jt]s" --write --loglevel silent
18+
@node -e "require('fs').writeFileSync('./lib/package.json', JSON.stringify(Object.assign(require('./package.json'), { main: 'index.js' }), null, 2))"
19+
20+
publish: build
21+
cd lib && npm publish

Diff for: README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Nyan CSS CSS Modules
2+
3+
TODO

Diff for: babel.config.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
presets: [
3+
['@babel/preset-env', { targets: { node: 'current' } }],
4+
'@babel/preset-typescript'
5+
]
6+
}

Diff for: jest.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
roots: ['<rootDir>/src/']
3+
}

Diff for: package.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "@nyancss/css-modules",
3+
"version": "1.0.0",
4+
"description": "Converts CSS Modules into Nyan CSS",
5+
"main": "lib/index.js",
6+
"repository": "https://github.com/nyancss/nyancss-css-modules",
7+
"author": "Sasha Koss <[email protected]>",
8+
"license": "MIT",
9+
"dependencies": {
10+
"@nyancss/types": "../nyancss-types/lib",
11+
"@nyancss/utils": "../nyancss-utils/lib/"
12+
},
13+
"devDependencies": {
14+
"@babel/preset-env": "^7.4.5",
15+
"@babel/preset-typescript": "^7.3.3",
16+
"@types/jest": "^24.0.13",
17+
"@types/node": "^12.0.4",
18+
"jest": "^24.8.0",
19+
"prettier": "^1.17.1",
20+
"typescript": "^3.5.1"
21+
}
22+
}

Diff for: src/convert/index.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { NyanCSSMap } from '@nyancss/types'
2+
import {
3+
applyComponent,
4+
tryApplyBooleanProp,
5+
tryApplyEnumProp
6+
} from '@nyancss/utils'
7+
import { NyanCSSModules } from '../types'
8+
9+
export default function convert(cssModules: NyanCSSModules) {
10+
return Object.keys(cssModules).reduce(
11+
(map, className) => {
12+
const processedClassName = cssModules[className]
13+
tryApplyBooleanProp(map, className, processedClassName) ||
14+
tryApplyEnumProp(map, className, processedClassName) ||
15+
applyComponent(map, className, processedClassName)
16+
return map
17+
},
18+
{} as NyanCSSMap
19+
)
20+
}

Diff for: src/convert/test.ts

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import convert from '.'
2+
3+
describe('convert', () => {
4+
it('converts CSS components', () => {
5+
expect(convert({ Button: 'Button-xxx', Input: 'Input-xxx' })).toEqual({
6+
Button: {
7+
componentName: 'Button',
8+
tag: undefined,
9+
className: 'Button-xxx',
10+
props: {}
11+
},
12+
13+
Input: {
14+
componentName: 'Input',
15+
tag: undefined,
16+
className: 'Input-xxx',
17+
props: {}
18+
}
19+
})
20+
})
21+
22+
it('converts boolean props', () => {
23+
expect(
24+
convert({ Button: 'Button-xxx', 'Button-active': 'Button-active-xxx' })
25+
).toEqual({
26+
Button: {
27+
componentName: 'Button',
28+
tag: undefined,
29+
className: 'Button-xxx',
30+
props: {
31+
active: {
32+
propName: 'active',
33+
type: 'boolean',
34+
className: 'Button-active-xxx'
35+
}
36+
}
37+
}
38+
})
39+
})
40+
41+
it('parses enum props', () => {
42+
expect(
43+
convert({
44+
Text: 'Text-xxx',
45+
'Text-color-red': 'Text-color-red-xxx',
46+
'Text-color-green': 'Text-color-green-xxx'
47+
})
48+
).toEqual({
49+
Text: {
50+
componentName: 'Text',
51+
tag: undefined,
52+
className: 'Text-xxx',
53+
props: {
54+
color: {
55+
propName: 'color',
56+
type: 'enum',
57+
values: ['red', 'green'],
58+
classNames: {
59+
red: 'Text-color-red-xxx',
60+
green: 'Text-color-green-xxx'
61+
}
62+
}
63+
}
64+
}
65+
})
66+
})
67+
68+
it('converts enum props with boolean value', () => {
69+
expect(
70+
convert({
71+
'Spacing-padded': 'Spacing-padded-xxx',
72+
'Spacing-padded-small': 'Spacing-padded-small-xxx',
73+
'Spacing-padded-large': 'Spacing-padded-large-xxx',
74+
'Link-active-red': 'Link-active-red-xxx',
75+
'Link-active-green': 'Link-active-green-xxx',
76+
'Link-active': 'Link-active-xxx'
77+
})
78+
).toEqual({
79+
Spacing: {
80+
componentName: 'Spacing',
81+
tag: undefined,
82+
className: undefined,
83+
props: {
84+
padded: {
85+
propName: 'padded',
86+
type: 'enum',
87+
values: [true, 'small', 'large'],
88+
classNames: {
89+
true: 'Spacing-padded-xxx',
90+
small: 'Spacing-padded-small-xxx',
91+
large: 'Spacing-padded-large-xxx'
92+
}
93+
}
94+
}
95+
},
96+
97+
Link: {
98+
componentName: 'Link',
99+
tag: undefined,
100+
className: undefined,
101+
props: {
102+
active: {
103+
propName: 'active',
104+
type: 'enum',
105+
values: ['red', 'green', true],
106+
classNames: {
107+
red: 'Link-active-red-xxx',
108+
green: 'Link-active-green-xxx',
109+
true: 'Link-active-xxx'
110+
}
111+
}
112+
}
113+
}
114+
})
115+
})
116+
})

Diff for: src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as convert } from './convert'

Diff for: src/types.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export type NyanCSSModules = {
2+
[className: string]: string
3+
}

Diff for: tsconfig.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"compilerOptions": {
3+
"rootDirs": ["src"],
4+
"declaration": true,
5+
"target": "es6",
6+
"module": "commonjs",
7+
"sourceMap": true,
8+
"outDir": "lib",
9+
"strict": true,
10+
"noImplicitAny": true,
11+
"allowSyntheticDefaultImports": true
12+
},
13+
"exclude": ["**/test.ts", "lib", "node_modules"]
14+
}

0 commit comments

Comments
 (0)