Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A CLI to compile an entire folder with StyleX #491

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
77ffab2
Start working on cli
nmn Feb 1, 2024
aad664d
cli: basic nodejs cli setup
Jta26 Feb 9, 2024
c7502aa
[cli] very rough working stylex cli
Jta26 Feb 10, 2024
8647051
[cli] adding relative imports to compiled js files and basic watchman…
Jta26 Feb 12, 2024
31825cf
[cli] restore lockfile
Jta26 Feb 12, 2024
d7b431d
[cli] watch mode that recompiles entire directory on files changed
Jta26 Feb 13, 2024
1a97121
[cli] remove compiled example
Jta26 Feb 13, 2024
6b6b75e
[cli] add test verifying functionality of cli
Jta26 Feb 14, 2024
277d2d4
[cli] typos
Jta26 Feb 14, 2024
fee0a5e
[cli] cool ascii art
Jta26 Feb 14, 2024
24dc9a5
[cli] change bin to lib directory
Jta26 Feb 14, 2024
122ff51
[cli] ignore prettier, eslint in compiled test files
Jta26 Feb 14, 2024
20bf7b2
Fix type errors in CLI and minor tweaks
nmn Feb 21, 2024
025886d
Add syntax plugins
nmn Feb 21, 2024
d8d1ce8
[cli] handle top level dir edge case, clean up on compile failure, un…
Jta26 Feb 26, 2024
95fe6e0
[cli] next swc example
Jta26 Feb 27, 2024
6a2488e
[cli] better ascii art
Jta26 Feb 27, 2024
572a3c6
[cli] basic .stylex.json config file support
Jta26 Feb 27, 2024
222da1f
[cli] output all as .js, use mkdirp, use babel typescript plugin
Jta26 Feb 27, 2024
fbe1b84
cli-example w/ next -> pure stylex compile example
Jta26 Feb 29, 2024
f3a90ae
[cli] make watch mode only recompile changed files
Jta26 Mar 13, 2024
1686de2
[cli] fix tests
Jta26 Mar 13, 2024
0dd1ee7
Update apps/cli-example/package.json
Jta26 Mar 13, 2024
8e37c9d
Update apps/cli-example/package.json
Jta26 Mar 13, 2024
5cd198d
[cli] update README and fix test?
Jta26 Mar 13, 2024
2eed9ad
Merge branch 'feat/cli' of https://github.com/facebook/stylex into fe…
Jta26 Mar 13, 2024
7b74d88
[cli] typo and test fix?
Jta26 Mar 13, 2024
70db410
Fix watch mode test
Jta26 Mar 13, 2024
52d0967
[cli] remove watch test
Jta26 Mar 13, 2024
9d3c973
[cli] kinda working node_modules compilation
Jta26 Mar 19, 2024
6f77382
[cli] reset cli-example package.json to "transform" script
Jta26 Mar 19, 2024
45b2a3f
[cli] rewrite imports to compiled module directory
Jta26 Mar 23, 2024
8f25844
[cli] remove console logs
Jta26 Mar 23, 2024
4baa793
[cli] fix broken test
Jta26 Mar 23, 2024
f0378d4
[cli] spell-check
Jta26 Mar 23, 2024
0eed397
[cli] working node module compilation (failing tests)
Jta26 Mar 24, 2024
db04385
[cli] Fix broken tests and centralize cli input and json config input
Jta26 Mar 25, 2024
b1ed8de
[cli] improve readme
Jta26 Mar 25, 2024
4f1b79d
[cli] more readme
Jta26 Mar 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module.exports = {
'node_modules',
'next-env.d.ts',
'next.config.js',
'**/__mocks__/snapshot',
],
globals: {
$Call: 'readonly',
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ coverage
lib
node_modules
*.mdx
**/__mocks__/snapshot
4 changes: 4 additions & 0 deletions apps/cli-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# stylex compiled
src
7 changes: 7 additions & 0 deletions apps/cli-example/.stylex.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
input: './source',
output: './src',
// modules: [],
cssBundleName: 'stylex_bundle.css',
// mode: 'watch',
}
Empty file added apps/cli-example/README.md
Empty file.
19 changes: 19 additions & 0 deletions apps/cli-example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "next-swc-cli-example",
"version": "0.5.1",
"private": true,
"scripts": {
"transform": "stylex -c .stylex.json5"
},
"dependencies": {
"react": "^18",
"react-dom": "^18"
},
"devDependencies": {
"@stylexjs/cli": "0.5.1",
"@types/react": "^18",
"@types/react-dom": "^18",
"typescript": "^5"
}
Jta26 marked this conversation as resolved.
Show resolved Hide resolved

Jta26 marked this conversation as resolved.
Show resolved Hide resolved
}
14 changes: 14 additions & 0 deletions apps/cli-example/source/app/CardTokens.stylex.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/

import * as stylex from '@stylexjs/stylex';

export const tokens = stylex.defineVars({
arrowTransform: 'translateX(0)',
});
100 changes: 100 additions & 0 deletions apps/cli-example/source/app/Counter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/

'use client';

import * as stylex from '@stylexjs/stylex';
import { spacing, text, globalTokens as $ } from './globalTokens.stylex';
import { useState } from 'react';

export default function Counter() {
const [count, setCount] = useState(0);

return (
<div {...stylex.props(styles.container)}>
<button
{...stylex.props(styles.button)}
onClick={() => setCount((c) => c - 1)}
>
-
</button>
<div
{...stylex.props(
styles.count,
Math.abs(count) > 99 && styles.largeNumber,
)}
>
{count}
</div>
<button
{...stylex.props(styles.button)}
onClick={() => setCount((c) => c + 1)}
>
+
</button>
</div>
);
}

const DARK = '@media (prefers-color-scheme: dark)' as const;

const styles = stylex.create({
container: {
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
flexDirection: 'row',
borderRadius: spacing.md,
borderWidth: 1,
borderStyle: 'solid',
borderColor: 'blue',
padding: spacing.xxxs,
fontFamily: $.fontSans,
gap: spacing.xs,
},
button: {
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
height: '6rem',
aspectRatio: 1,
color: 'blue',
backgroundColor: {
default: 'blue',
':hover': 'blue',
[DARK]: {
default: 'blue',
':hover': 'blue',
},
},
borderWidth: 0,
borderStyle: 'none',
borderRadius: spacing.xs,
padding: spacing.xs,
margin: spacing.xs,
cursor: 'pointer',
fontSize: text.h2,
transform: {
default: null,
':hover': 'scale(1.025)',
':active': 'scale(0.975)',
},
},
count: {
fontSize: text.h2,
fontWeight: 100,
color: 'blue',
minWidth: '6rem',
textAlign: 'center',
fontFamily: $.fontMono,
},
largeNumber: {
fontSize: text.h3,
},
});
16 changes: 16 additions & 0 deletions apps/cli-example/source/app/error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/

'use client'

import React from 'react';

export default function Error() {
return <p>Error</p>
}
Binary file added apps/cli-example/source/app/favicon.ico
Binary file not shown.
Loading
Loading