Skip to content

Commit e723470

Browse files
committed
feat: create platform function from generator
1 parent 6e13ce6 commit e723470

File tree

6 files changed

+307
-0
lines changed

6 files changed

+307
-0
lines changed

.gitignore

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
lib/
2+
3+
# Logs
4+
logs
5+
*.log
6+
npm-debug.log*
7+
yarn-debug.log*
8+
yarn-error.log*
9+
lerna-debug.log*
10+
11+
# Diagnostic reports (https://nodejs.org/api/report.html)
12+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
13+
14+
# Runtime data
15+
pids
16+
*.pid
17+
*.seed
18+
*.pid.lock
19+
20+
# Directory for instrumented libs generated by jscoverage/JSCover
21+
lib-cov
22+
23+
# Coverage directory used by tools like istanbul
24+
coverage
25+
*.lcov
26+
27+
# nyc test coverage
28+
.nyc_output
29+
30+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
31+
.grunt
32+
33+
# Bower dependency directory (https://bower.io/)
34+
bower_components
35+
36+
# node-waf configuration
37+
.lock-wscript
38+
39+
# Compiled binary addons (https://nodejs.org/api/addons.html)
40+
build/Release
41+
42+
# Dependency directories
43+
node_modules/
44+
jspm_packages/
45+
46+
# TypeScript v1 declaration files
47+
typings/
48+
49+
# TypeScript cache
50+
*.tsbuildinfo
51+
52+
# Optional npm cache directory
53+
.npm
54+
55+
# Optional eslint cache
56+
.eslintcache
57+
58+
# Microbundle cache
59+
.rpt2_cache/
60+
.rts2_cache_cjs/
61+
.rts2_cache_es/
62+
.rts2_cache_umd/
63+
64+
# Optional REPL history
65+
.node_repl_history
66+
67+
# Output of 'npm pack'
68+
*.tgz
69+
70+
# Yarn Integrity file
71+
.yarn-integrity
72+
73+
# dotenv environment variables file
74+
.env
75+
.env.test
76+
77+
# parcel-bundler cache (https://parceljs.org/)
78+
.cache
79+
80+
# Next.js build output
81+
.next
82+
83+
# Nuxt.js build / generate output
84+
.nuxt
85+
dist
86+
87+
# Gatsby files
88+
.cache/
89+
# Comment in the public line in if your project uses Gatsby and *not* Next.js
90+
# https://nextjs.org/blog/next-9-1#public-directory-support
91+
# public
92+
93+
# vuepress build output
94+
.vuepress/dist
95+
96+
# Serverless directories
97+
.serverless/
98+
99+
# FuseBox cache
100+
.fusebox/
101+
102+
# DynamoDB Local files
103+
.dynamodb/
104+
105+
# TernJS port file
106+
.tern-port

package.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "styled-platform",
3+
"version": "0.0.1",
4+
"description": "Platform.select for native CSS-IN-JS solutions(styled-components, emotion, etc.)",
5+
"main": "lib/index.js",
6+
"types": "lib/index.d.ts",
7+
"typings": "lib/index.d.ts",
8+
"repository": "https://github.com/junhoyeo/styled-platform",
9+
"author": {
10+
"name": "JunhoYeo",
11+
"email": "hanaro0704@naver.com"
12+
},
13+
"license": "MIT",
14+
"scripts": {
15+
"build": "tsc",
16+
"install-peers": "install-peers -f"
17+
},
18+
"files": [
19+
"lib",
20+
"README.md",
21+
"LICENSE"
22+
],
23+
"peerDependencies": {
24+
"react": "^16.13.1",
25+
"react-native": "^0.62.2"
26+
},
27+
"devDependencies": {
28+
"@types/react": "^16.9.34",
29+
"@types/react-native": "^0.62.4",
30+
"install-peers-cli": "^2.2.0",
31+
"typescript": "^3.8.3"
32+
}
33+
}

src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export {
2+
platform as default,
3+
PlatformKey,
4+
PlatformSelectObject,
5+
} from './platform';

src/platform.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import type { ComponentType } from 'react';
2+
import { Platform } from 'react-native';
3+
4+
type Interpolation =
5+
| ((executionContext: Object) => Interpolation)
6+
| string
7+
| ComponentType
8+
| Array<Interpolation>;
9+
type RuleSet = Array<Interpolation>;
10+
11+
export interface PlatformSelectObject {
12+
ios?: RuleSet;
13+
android?: RuleSet;
14+
macos?: RuleSet;
15+
windows?: RuleSet;
16+
web?: RuleSet;
17+
}
18+
19+
export type PlatformKey = 'android' | 'ios';
20+
21+
const currentPlatform = Platform.OS;
22+
const platformKeys: PlatformKey[] = ['android', 'ios'];
23+
24+
function _platform_main(platformSelectObjectOrPlatformKeyString: PlatformSelectObject | PlatformKey, styles: RuleSet = []): RuleSet {
25+
if (typeof platformSelectObjectOrPlatformKeyString === 'string') {
26+
return styles;
27+
}
28+
29+
const platformSelectObject = platformSelectObjectOrPlatformKeyString;
30+
platformKeys.map((platformKey) => {
31+
if (currentPlatform === platformKey && platformKey in platformSelectObject) {
32+
return platformSelectObject[platformKey];
33+
}
34+
});
35+
36+
return [];
37+
}
38+
39+
interface platform {
40+
(platformSelectObjectOrPlatformKeyString: PlatformSelectObject | PlatformKey, styles?: RuleSet): RuleSet;
41+
android: (styles?: RuleSet) => RuleSet | void;
42+
}
43+
44+
const platformGenerator = (() => {
45+
const platformSolution: any = _platform_main;
46+
platformSolution.android = (styles: RuleSet) => styles;
47+
return _platform_main;
48+
})();
49+
50+
export const platform = platformGenerator as platform;

tsconfig.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"compilerOptions": {
3+
"allowSyntheticDefaultImports": true,
4+
"baseUrl": ".",
5+
"declaration": true,
6+
"esModuleInterop": true,
7+
"importHelpers": true,
8+
"jsx": "react",
9+
"module": "commonjs",
10+
"moduleResolution": "node",
11+
"paths": {
12+
"@/*": [
13+
"src/*"
14+
]
15+
},
16+
"rootDir": "src",
17+
"skipLibCheck": true,
18+
"sourceMap": true,
19+
"strict": true,
20+
"target": "esnext",
21+
"outDir": "lib"
22+
},
23+
"exclude": [
24+
"node_modules",
25+
"lib",
26+
"esm",
27+
"**/__tests__",
28+
"**/__test__",
29+
"example",
30+
]
31+
}

yarn.lock

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
"@types/jquery@^3.3.38":
6+
version "3.3.38"
7+
resolved "https://registry.yarnpkg.com/@types/jquery/-/jquery-3.3.38.tgz#6385f1e1b30bd2bff55ae8ee75ea42a999cc3608"
8+
integrity sha512-nkDvmx7x/6kDM5guu/YpXkGZ/Xj/IwGiLDdKM99YA5Vag7pjGyTJ8BNUh/6hxEn/sEu5DKtyRgnONJ7EmOoKrA==
9+
dependencies:
10+
"@types/sizzle" "*"
11+
12+
"@types/prop-types@*":
13+
version "15.7.3"
14+
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.3.tgz#2ab0d5da2e5815f94b0b9d4b95d1e5f243ab2ca7"
15+
integrity sha512-KfRL3PuHmqQLOG+2tGpRO26Ctg+Cq1E01D2DMriKEATHgWLfeNDmq9e29Q9WIky0dQ3NPkd1mzYH8Lm936Z9qw==
16+
17+
"@types/react-native@^0.62.4":
18+
version "0.62.10"
19+
resolved "https://registry.yarnpkg.com/@types/react-native/-/react-native-0.62.10.tgz#82c481df21db4e7460755dc3fc7091e333a1d2bd"
20+
integrity sha512-QR4PGrzZ3IvRIHlScyIPuv2GV8tD/BMICZz514KGvn3KHbh0mLphHHemtHZC1o8u4xM5LxwVpMpMYHQ+ncSfag==
21+
dependencies:
22+
"@types/react" "*"
23+
24+
"@types/react@*", "@types/react@^16.9.34":
25+
version "16.9.35"
26+
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.9.35.tgz#a0830d172e8aadd9bd41709ba2281a3124bbd368"
27+
integrity sha512-q0n0SsWcGc8nDqH2GJfWQWUOmZSJhXV64CjVN5SvcNti3TdEaA3AH0D8DwNmMdzjMAC/78tB8nAZIlV8yTz+zQ==
28+
dependencies:
29+
"@types/prop-types" "*"
30+
csstype "^2.2.0"
31+
32+
"@types/sizzle@*":
33+
version "2.3.2"
34+
resolved "https://registry.yarnpkg.com/@types/sizzle/-/sizzle-2.3.2.tgz#a811b8c18e2babab7d542b3365887ae2e4d9de47"
35+
integrity sha512-7EJYyKTL7tFR8+gDbB6Wwz/arpGa0Mywk1TJbNzKzHtzbwVmY4HR9WqS5VV7dsBUKQmPNr192jHr/VpBluj/hg==
36+
37+
commander@^2.20.0:
38+
version "2.20.3"
39+
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
40+
integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==
41+
42+
csstype@^2.2.0:
43+
version "2.6.10"
44+
resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.6.10.tgz#e63af50e66d7c266edb6b32909cfd0aabe03928b"
45+
integrity sha512-D34BqZU4cIlMCY93rZHbrq9pjTAQJ3U8S8rfBqjwHxkGPThWFjzZDQpgMJY0QViLxth6ZKYiwFBo14RdN44U/w==
46+
47+
executioner@^2.0.1:
48+
version "2.0.1"
49+
resolved "https://registry.yarnpkg.com/executioner/-/executioner-2.0.1.tgz#add328e03bc45dd598f358fbb529fc0be0ec6fcd"
50+
integrity sha1-rdMo4DvEXdWY81j7tSn8C+Dsb80=
51+
dependencies:
52+
mixly "^1.0.0"
53+
54+
fulcon@^1.0.1:
55+
version "1.0.2"
56+
resolved "https://registry.yarnpkg.com/fulcon/-/fulcon-1.0.2.tgz#8a4dfda4c73fcd9cc62a79d5045c392b45547320"
57+
integrity sha1-ik39pMc/zZzGKnnVBFw5K0VUcyA=
58+
59+
install-peers-cli@^2.2.0:
60+
version "2.2.0"
61+
resolved "https://registry.yarnpkg.com/install-peers-cli/-/install-peers-cli-2.2.0.tgz#f76f1ec8ac9fa7f920c05743e011554edad85f8d"
62+
integrity sha512-scSNvF49HDOLNm2xLFwST23g/OvfsceiA087bcGBgZP/ZNCrvpSaCn5IrWNZ2XYmFFykXF/6J1Zgm+D/JgRgtA==
63+
dependencies:
64+
commander "^2.20.0"
65+
executioner "^2.0.1"
66+
67+
jquery@^3.5.1:
68+
version "3.5.1"
69+
resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.5.1.tgz#d7b4d08e1bfdb86ad2f1a3d039ea17304717abb5"
70+
integrity sha512-XwIBPqcMn57FxfT+Go5pzySnm4KWkT1Tv7gjrpT1srtf8Weynl6R273VJ5GjkRb51IzMp5nbaPjJXMWeju2MKg==
71+
72+
mixly@^1.0.0:
73+
version "1.0.0"
74+
resolved "https://registry.yarnpkg.com/mixly/-/mixly-1.0.0.tgz#9b5a2e1f63e6dfba0d30e6797ffae62ab1dc24ef"
75+
integrity sha1-m1ouH2Pm37oNMOZ5f/rmKrHcJO8=
76+
dependencies:
77+
fulcon "^1.0.1"
78+
79+
typescript@^3.8.3:
80+
version "3.9.3"
81+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.3.tgz#d3ac8883a97c26139e42df5e93eeece33d610b8a"
82+
integrity sha512-D/wqnB2xzNFIcoBG9FG8cXRDjiqSTbG2wd8DMZeQyJlP1vfTkIxH4GKveWaEBYySKIg+USu+E+EDIR47SqnaMQ==

0 commit comments

Comments
 (0)