Skip to content

Commit 9dbf807

Browse files
committed
add bun support, improve expo detection in v2 cli
1 parent dc9036a commit 9dbf807

File tree

29 files changed

+1392
-1906
lines changed

29 files changed

+1392
-1906
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ yarn-error.log*
3535
# vercel
3636
.vercel
3737
package-lock.json
38+
39+
# jetbrains
40+
.idea

packages/create-expo-app-with-gluestack-ui/src/index.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
#!/usr/bin/env node
22
const args = process.argv.slice(2);
33

4-
let supportedArgs = ['--use-npm', '--use-yarn', '--help', '-h', '--use-pnpm'];
4+
let supportedArgs = [
5+
'--use-npm',
6+
'--use-yarn',
7+
'--help',
8+
'-h',
9+
'--use-pnpm',
10+
'--use-bun',
11+
];
512

6-
import path from 'path';
7-
import fs from 'fs';
813
import { cancel, isCancel, log, text } from '@clack/prompts';
9-
import { installDependencies, getArgsData } from '@gluestack/cli-utils';
14+
import { getArgsData, installDependencies } from '@gluestack/cli-utils';
15+
import fs from 'fs';
16+
import path from 'path';
1017

1118
async function main() {
1219
let projectPath = path.join(path.resolve(__dirname, '..'), 'src', 'template');

packages/create-expo-router-app-with-gluestack-ui/src/index.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
#!/usr/bin/env node
22
const args = process.argv.slice(2);
33

4-
let supportedArgs = ['--use-npm', '--use-yarn', '--help', '-h', '--use-pnpm'];
4+
let supportedArgs = [
5+
'--use-npm',
6+
'--use-yarn',
7+
'--help',
8+
'-h',
9+
'--use-pnpm',
10+
'--use-bun',
11+
];
512

6-
import path from 'path';
7-
import fs from 'fs';
813
import { cancel, isCancel, log, text } from '@clack/prompts';
9-
import { installDependencies, getArgsData } from '@gluestack/cli-utils';
14+
import { getArgsData, installDependencies } from '@gluestack/cli-utils';
15+
import fs from 'fs';
16+
import path from 'path';
1017

1118
async function main() {
1219
let projectPath = path.join(path.resolve(__dirname, '..'), 'src', 'template');

packages/create-gluestack-v2-app/src/template/client/web/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ npm run dev
1010
yarn dev
1111
# or
1212
pnpm dev
13+
# or
14+
bun dev
1315
```
1416

1517
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

packages/create-next-app-with-gluestack-ui/src/app-router/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ npm run dev
1010
yarn dev
1111
# or
1212
pnpm dev
13+
# or
14+
bun dev
1315
```
1416

1517
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
@@ -29,9 +31,10 @@ To learn more about Next.js + Gluestack UI template, take a look at the followin
2931
- [Gluestack Style Documentaion](https://style.gluestack.io/docs/overview/introduction) - learn about the universal styling library that is used in Gluestack-ui
3032

3133
You can check out:
34+
3235
- [the gluestack-ui GitHub repository](https://github.com/gluestack/gluestack-ui)
3336
- [the gluestack-style GitHub repository](https://github.com/gluestack/gluestack-style)
34-
Your feedback and contributions are welcome!
37+
Your feedback and contributions are welcome!
3538

3639
## Deploy on Vercel
3740

packages/create-next-app-with-gluestack-ui/src/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ let supportedArgs = [
77
'--help',
88
'-h',
99
'--use-pnpm',
10+
'--use-bun',
1011
'--app',
1112
'--page',
1213
];
13-
import path from 'path';
14-
import fs from 'fs';
15-
import { cancel, isCancel, log, spinner, text, select } from '@clack/prompts';
14+
import { cancel, isCancel, log, select, spinner, text } from '@clack/prompts';
1615
import { spawnSync } from 'child_process';
16+
import fs from 'fs';
17+
import path from 'path';
1718

1819
function installDependencies(projectName: string, installationMethod: string) {
1920
const projectPath = path.join(process.cwd(), projectName);
@@ -81,6 +82,7 @@ async function main() {
8182
--use-npm use npm to install dependencies
8283
--use-yarn use yarn to install dependencies
8384
--use-pnpm use pnpm to install dependencies
85+
--use-bun use bun to install dependencies
8486
`
8587
);
8688
process.exit(0);
@@ -94,6 +96,8 @@ async function main() {
9496
useAppRouter = 'yes';
9597
} else if (args[i] === '--page') {
9698
useAppRouter = 'no';
99+
} else if (args[i] === '--use-bun') {
100+
installationMethod = 'bun i';
97101
}
98102
} else {
99103
log.warning(

packages/create-next-app-with-gluestack-ui/src/page-router/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ npm run dev
1010
yarn dev
1111
# or
1212
pnpm dev
13+
# or
14+
bun dev
1315
```
1416

1517
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
@@ -29,9 +31,10 @@ To learn more about Next.js + Gluestack UI template, take a look at the followin
2931
- [Gluestack Style Documentaion](https://style.gluestack.io/docs/overview/introduction) - learn about the universal styling library that is used in Gluestack-ui
3032

3133
You can check out:
34+
3235
- [the gluestack-ui GitHub repository](https://github.com/gluestack/gluestack-ui)
3336
- [the gluestack-style GitHub repository](https://github.com/gluestack/gluestack-style)
34-
Your feedback and contributions are welcome!
37+
Your feedback and contributions are welcome!
3538

3639
## Deploy on Vercel
3740

packages/create-react-native-app-with-gluestack-ui/src/index.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@
22

33
const args = process.argv.slice(2);
44

5-
let supportedArgs = ['--use-npm', '--use-yarn', '--help', '-h', '--use-pnpm'];
5+
let supportedArgs = [
6+
'--use-npm',
7+
'--use-yarn',
8+
'--help',
9+
'-h',
10+
'--use-pnpm',
11+
'--use-bun',
12+
];
613

7-
import path from 'path';
8-
import fs from 'fs';
914
import { cancel, isCancel, log, text } from '@clack/prompts';
10-
import { installDependencies, getArgsData } from '@gluestack/cli-utils';
15+
import { getArgsData, installDependencies } from '@gluestack/cli-utils';
16+
import fs from 'fs';
17+
import path from 'path';
1118

1219
async function main() {
1320
let projectPath = path.join(path.resolve(__dirname, '..'), 'src', 'template');

packages/gluestack-cli/src/commands/add.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1+
import { log } from '@clack/prompts';
12
import { Command } from 'commander';
23
import { z } from 'zod';
3-
import { handleError } from '../util/handle-error';
4-
import { log } from '@clack/prompts';
5-
import { componentAdder } from '../util/add';
64
import { config } from '../config';
75
import { checkWritablePath, isValidPath, projectRootPath } from '../util';
6+
import { componentAdder } from '../util/add';
87
import { checkIfInitialized, getComponentsPath } from '../util/config';
8+
import { handleError } from '../util/handle-error';
99

1010
const addOptionsSchema = z.object({
1111
components: z.string().optional(),
1212
all: z.boolean(),
1313
useNpm: z.boolean(),
1414
useYarn: z.boolean(),
1515
usePnpm: z.boolean(),
16+
useBun: z.boolean(),
1617
path: z.string().optional(),
1718
});
1819

@@ -24,6 +25,7 @@ export const add = new Command()
2425
.option('--use-npm ,useNpm', 'use npm to install dependencies', false)
2526
.option('--use-yarn, useYarn', 'use yarn to install dependencies', false)
2627
.option('--use-pnpm, usePnpm', 'use pnpm to install dependencies', false)
28+
.option('--use-bun, useBun', 'use bun to install dependencies', false)
2729
.option('--path <path>', 'path to the components directory')
2830
.action(async (components, opts, command) => {
2931
try {
@@ -70,10 +72,16 @@ export const add = new Command()
7072
process.exit(1);
7173
}
7274
let installationMethod;
73-
if (options.useNpm || options.useYarn || options.usePnpm) {
75+
if (
76+
options.useNpm ||
77+
options.useYarn ||
78+
options.usePnpm ||
79+
options.useBun
80+
) {
7481
if (options.useNpm) installationMethod = 'npm';
7582
if (options.usePnpm) installationMethod = 'pnpm';
7683
if (options.useYarn) installationMethod = 'yarn';
84+
if (options.useBun) installationMethod = 'bun';
7785
}
7886
if (options.all) {
7987
try {

packages/gluestack-cli/src/commands/init.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1+
import { log } from '@clack/prompts';
12
import { Command } from 'commander';
23
import { z } from 'zod';
3-
import { handleError } from '../util/handle-error';
4-
import { log } from '@clack/prompts';
5-
import { InitializeGlueStack } from '../util/init';
64
import { config } from '../config';
75
import {
86
checkWritablePath,
97
detectProjectType,
108
isValidPath,
119
projectRootPath,
1210
} from '../util';
11+
import { handleError } from '../util/handle-error';
12+
import { InitializeGlueStack } from '../util/init';
1313

1414
const initOptionsSchema = z.object({
1515
useNpm: z.boolean(),
1616
useYarn: z.boolean(),
1717
usePnpm: z.boolean(),
18+
useBun: z.boolean(),
1819
path: z.string().optional(),
1920
});
2021

@@ -24,6 +25,7 @@ export const init = new Command()
2425
.option('--use-npm ,useNpm', 'use npm to install dependencies', false)
2526
.option('--use-yarn, useYarn', 'use yarn to install dependencies', false)
2627
.option('--use-pnpm, usePnpm', 'use pnpm to install dependencies', false)
28+
.option('--use-bun, useBun', 'use bun to install dependencies', false)
2729
.option(
2830
'--path <path>',
2931
'path to the components directory. defaults to components/ui'
@@ -32,10 +34,16 @@ export const init = new Command()
3234
try {
3335
const options = initOptionsSchema.parse({ ...opts });
3436
let installationMethod;
35-
if (options.useNpm || options.useYarn || options.usePnpm) {
37+
if (
38+
options.useNpm ||
39+
options.useYarn ||
40+
options.usePnpm ||
41+
options.useBun
42+
) {
3643
if (options.useNpm) installationMethod = 'npm';
3744
if (options.usePnpm) installationMethod = 'pnpm';
3845
if (options.useYarn) installationMethod = 'yarn';
46+
if (options.useBun) installationMethod = 'bun';
3947
}
4048
// Check if the string starts with "/" or "."
4149
if (options.path && !isValidPath(options.path)) {

packages/gluestack-cli/src/util/add/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { confirm, log } from '@clack/prompts';
12
import fs from 'fs-extra';
2-
import { join } from 'path';
33
import os from 'os';
4-
import { log, confirm } from '@clack/prompts';
4+
import { join } from 'path';
55
import {
66
addDependencies,
77
cloneRepositoryAtRoot,
@@ -43,14 +43,15 @@ const componentAdder = async ({
4343
!existingComponentsChecked && showWarning && requestedComponent
4444
? await isComponentInConfig(requestedComponents)
4545
: requestedComponents;
46+
4647
await Promise.all(
4748
updatedComponents.map(async (component) => {
4849
const targetPath = join(
4950
projectRootPath,
5051
config.writableComponentsPath,
5152
component
5253
);
53-
54+
console.log(`writing component`, component, targetPath);
5455
await writeComponent(component, targetPath);
5556
})
5657
)

packages/gluestack-cli/src/util/config/expo-config-helper.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import * as path from 'path';
21
import fg from 'fast-glob';
2+
import * as fs from 'fs';
3+
import * as path from 'path';
4+
import { generateConfig, getConfigPath } from '.';
5+
import { projectRootPath } from '..';
6+
import { config } from '../../config';
37
import {
4-
RawConfig,
5-
PROJECT_SHARED_IGNORE,
68
ExpoResolvedConfig,
9+
PROJECT_SHARED_IGNORE,
10+
RawConfig,
711
} from './config-types';
8-
import { generateConfig, getConfigPath } from '.';
9-
import { config } from '../../config';
10-
import { projectRootPath } from '..';
1112

1213
// expo project type initialization
1314
async function getExpoProjectType(cwd: string): Promise<string | undefined> {
@@ -17,18 +18,29 @@ async function getExpoProjectType(cwd: string): Promise<string | undefined> {
1718
ignore: PROJECT_SHARED_IGNORE,
1819
});
1920

20-
const isExpoProject = files.find((file) => file.startsWith('app.json'));
21+
const isExpoProject = files.find(
22+
(file) =>
23+
file.startsWith('app.json') ||
24+
file.startsWith('app.config.js') ||
25+
file.startsWith('app.config.ts')
26+
);
2127
if (!isExpoProject) {
2228
return undefined;
2329
}
2430

25-
const isUsingExpoRouter = await getConfigPath(['app/_layout.*']);
31+
const expoLayoutPath = fs.existsSync('app')
32+
? 'app/_layout.*'
33+
: fs.existsSync('src/app')
34+
? 'src/app/_layout.*'
35+
: '**/*_layout.*';
36+
const isUsingExpoRouter = await getConfigPath([expoLayoutPath]);
2637
const isUsingDefaultExpo = await getConfigPath(['App.*']);
38+
2739
return isUsingExpoRouter
2840
? 'expo-router'
2941
: isUsingDefaultExpo
30-
? 'expo-default'
31-
: undefined;
42+
? 'expo-default'
43+
: undefined;
3244
}
3345

3446
async function resolvedExpoPaths(resultConfig: ExpoResolvedConfig) {

packages/gluestack-cli/src/util/config/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import fg from 'fast-glob';
12
import * as fs from 'fs';
23
import * as path from 'path';
3-
import { config } from '../../config';
44
import { projectRootPath } from '..';
5-
import fg from 'fast-glob';
6-
import { RawConfig, PROJECT_SHARED_IGNORE } from './config-types';
5+
import { config } from '../../config';
6+
import { PROJECT_SHARED_IGNORE, RawConfig } from './config-types';
77

88
const fileExtensions = ['.tsx', '.jsx', '.ts', '.js'];
99
const possibleIndexFiles = ['_app', 'index', 'App'];
@@ -124,10 +124,10 @@ async function generateGluestackConfig() {
124124

125125
export {
126126
checkIfInitialized,
127-
getEntryPathAndComponentsPath,
127+
findDirectory,
128128
generateConfig,
129-
getConfigPath,
130-
getComponentsPath,
131129
generateGluestackConfig,
132-
findDirectory,
130+
getComponentsPath,
131+
getConfigPath,
132+
getEntryPathAndComponentsPath,
133133
};

0 commit comments

Comments
 (0)