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

feat/create-gluestack-v2 #91

Merged
merged 64 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
1ebc6d1
feat: added new flags in init
vaibhk20 Sep 26, 2024
e54a4cd
feat: added package manager flags
vaibhk20 Sep 26, 2024
9caa77d
v0.7.10-alpha.0.1
vaibhk20 Sep 27, 2024
e7ce6b3
feat: updated create gluestack flow
vaibhk20 Sep 27, 2024
1143ea5
v2.0.1-alpha.0.2
vaibhk20 Sep 27, 2024
ab3746a
v2.0.1-alpha.0.3
vaibhk20 Sep 27, 2024
b31ee86
feat: project types defined
vaibhk20 Sep 30, 2024
b337165
v2.0.1-alpha.0.4
vaibhk20 Sep 30, 2024
6e4bfb2
feat: create project command
vaibhk20 Sep 30, 2024
6ca96e6
v2.0.1-alpha.0.5
vaibhk20 Sep 30, 2024
1aa788c
fix: create project
vaibhk20 Sep 30, 2024
10e32b8
Merge branch 'patch' of https://github.com/gluestack/gluestack-ui-cli…
vaibhk20 Sep 30, 2024
9d79866
fix: code review
vaibhk20 Sep 30, 2024
817cffa
v2.0.1-alpha.0.6
vaibhk20 Oct 1, 2024
39e6d43
v0.7.10-alpha.0.2
vaibhk20 Oct 1, 2024
5e86a11
v2.0.1-alpha.0.7
vaibhk20 Oct 1, 2024
9c6dfea
v0.7.10-alpha.0.3
vaibhk20 Oct 1, 2024
34f5593
v0.7.10-alpha.0.4
vaibhk20 Oct 1, 2024
1a11526
v0.7.10-alpha.0.5
vaibhk20 Oct 1, 2024
9bce579
v2.0.1-alpha.0.8
vaibhk20 Oct 1, 2024
6f74359
v2.0.1-alpha.0.9
vaibhk20 Oct 1, 2024
d97b618
v2.0.1-alpha.1.0
vaibhk20 Oct 1, 2024
85380f3
fix: create gluestack tests
vaibhk20 Oct 1, 2024
3f2d6a4
v0.7.10-alpha.0.6
vaibhk20 Oct 1, 2024
de4c54f
v0.7.10-alpha.0.7
vaibhk20 Oct 1, 2024
5b9257a
v2.0.1-alpha.1.1
vaibhk20 Oct 1, 2024
080f3fc
feat: alpha release
vaibhk20 Oct 1, 2024
d8c665e
v2.0.1-alpha.1.2
vaibhk20 Oct 3, 2024
e150890
v0.7.10-alpha.0.8
vaibhk20 Oct 3, 2024
4c3175a
feat: using JSON from gluestack-ui
vaibhk20 Oct 4, 2024
18c09ac
v0.7.10-alpha.0.9
vaibhk20 Oct 4, 2024
af1c9d1
v2.0.1-alpha.1.3
vaibhk20 Oct 4, 2024
0dc0242
v2.0.1-alpha.1.5
vaibhk20 Oct 4, 2024
ecf37a2
v2.0.1-alpha.1.6
vaibhk20 Oct 4, 2024
2654b36
v2.0.1-alpha.1.7
vaibhk20 Oct 4, 2024
44f17e6
v2.0.1-alpha.1.8
vaibhk20 Oct 4, 2024
b17fa5d
v2.0.1-alpha.1.9
vaibhk20 Oct 4, 2024
94510e4
v2.0.1-alpha.2.0
vaibhk20 Oct 4, 2024
db9c7b6
fix: test fixes
vaibhk20 Oct 4, 2024
c83c237
feat: add multiple components
vaibhk20 Oct 4, 2024
d082c40
v2.0.1-alpha.2.1
vaibhk20 Oct 4, 2024
fbdb310
v0.7.10-alpha.1.0
vaibhk20 Oct 7, 2024
66207c3
feat: added templateFlag to add
vaibhk20 Oct 17, 2024
7166b64
feat: windows support
vaibhk20 Oct 22, 2024
ed25508
v0.7.10-alpha.1.1
vaibhk20 Oct 22, 2024
66122e1
fix: next initializer
vaibhk20 Oct 22, 2024
ef909fd
v0.7.10-alpha.1.2
vaibhk20 Oct 22, 2024
d9affb8
fix: next initializer
vaibhk20 Oct 22, 2024
d1fd4bc
v0.7.10-alpha.1.3
vaibhk20 Oct 22, 2024
d48ac86
fix: next config typescript
vaibhk20 Oct 22, 2024
6a51935
feat: issues resolve
vaibhk20 Oct 23, 2024
5af72d4
fix: jsxImportSorce fix in next
vaibhk20 Oct 23, 2024
eaa7ad6
v0.7.14
vaibhk20 Oct 23, 2024
1ed0b3d
v0.7.15-alpha.0
vaibhk20 Oct 23, 2024
698ef7d
feat: add use-client transformer
vaibhk20 Oct 23, 2024
2f098fd
v0.7.16
vaibhk20 Oct 23, 2024
288788c
Merge branch 'patch' of https://github.com/gluestack/gluestack-ui-cli…
vaibhk20 Oct 23, 2024
83d955c
Merge branch 'feat/create-expo-v2' of https://github.com/gluestack/gl…
vaibhk20 Oct 23, 2024
1380a23
fix: error handling
vaibhk20 Oct 28, 2024
518ae56
fix: tailwindConfig path contents
vaibhk20 Nov 5, 2024
31b2627
v0.7.16-alpha.0
vaibhk20 Nov 5, 2024
a0e1dd6
v0.7.16-alpha.1
vaibhk20 Nov 5, 2024
60ffae3
fix: react-native-cli babel transformer
vaibhk20 Nov 5, 2024
2bc7e93
Merge pull request #94 from gluestack/fix/windows-support
vaibhk20 Nov 5, 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
2 changes: 1 addition & 1 deletion packages/gluestack-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"cli"
],
"description": "A CLI tool for easily adding components from gluestack to your projects.",
"version": "0.7.13",
"version": "0.7.16-alpha.1",
"license": "MIT",
"main": "dist/index.js",
"files": [
Expand Down
76 changes: 44 additions & 32 deletions packages/gluestack-cli/src/commands/add.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
import { Command } from 'commander';
import { z } from 'zod';
import os from 'os';
import { join } from 'path';
import { handleError } from '../util/handle-error';
import { log } from '@clack/prompts';
import { componentAdder, hookAdder, isHookFromConfig } from '../util/add';
import { componentAdder } from '../util/add';
import { config } from '../config';
import {
checkWritablePath,
cloneRepositoryAtRoot,
getPackageMangerFlag,
isValidPath,
projectRootPath,
cloneRepositoryAtRoot,
} from '../util';
import { checkIfInitialized, getComponentsPath } from '../util/config';
import { join } from 'path';
import os from 'os';

const _homeDir = os.homedir();

const addOptionsSchema = z.object({
components: z.string().optional(),
components: z.array(z.string()),
all: z.boolean(),
useNpm: z.boolean(),
useYarn: z.boolean(),
usePnpm: z.boolean(),
useBun: z.boolean(),
path: z.string().optional(),
templateOnly: z.boolean(),
});

export const add = new Command()
Expand All @@ -33,22 +36,25 @@ export const add = new Command()
.option('--use-npm ,useNpm', 'use npm to install dependencies', false)
.option('--use-yarn, useYarn', 'use yarn to install dependencies', false)
.option('--use-pnpm, usePnpm', 'use pnpm to install dependencies', false)
.option('--use-bun, useBun', 'use bun to install dependencies', false)
.option('--path <path>', 'path to the components directory')
.option(
'--template-only templateOnly',
'Only install the template without installing dependencies',
false
)
.action(async (components, opts, command) => {
try {
if (command.args.length > 1) {
log.error(
'\x1b[31mOnly one component can be provided at a time, please provide the component name you want to add or --all.\x1b[0m'
);
process.exit(1);
}
const options = addOptionsSchema.parse({
components: components ?? '',
components: command.args.length > 0 ? command.args : [],
...opts,
});
const isTemplate = options.templateOnly;
!isTemplate && console.log('\n\x1b[1mWelcome to gluestack-ui!\x1b[0m\n');

if (
options.all === false &&
(options.components === '' || options.components === undefined)
(!options.all && options.components?.length === 0) ||
(options.all && options.components?.length > 0)
) {
log.error(
'\x1b[31mInvalid arguement, please provide the component/hook name you want to add or --all.\x1b[0m'
Expand All @@ -62,7 +68,19 @@ export const add = new Command()
);
process.exit(1);
}
await cloneRepositoryAtRoot(join(_homeDir, config.gluestackDir));
//if multiple package managers are used
if (
(options.useNpm && options.useYarn) ||
(options.useNpm && options.usePnpm) ||
(options.useYarn && options.usePnpm)
) {
log.error(
`\x1b[31mMultiple package managers selected. Please select only one package manager.\x1b[0m`
);
process.exit(1);
}
//define package manager
getPackageMangerFlag(options);
//function to get current path where GUIProvider is located
const currWritablePath = await getComponentsPath(projectRootPath);
if (currWritablePath) {
Expand All @@ -78,23 +96,17 @@ export const add = new Command()
await checkWritablePath(options.path);
config.writableComponentsPath = options.path;
}
if (options.all) {
try {
await componentAdder({
requestedComponent: '--all',
});
} catch (err) {
log.error(`\x1b[31mError: ${(err as Error).message}\x1b[0m`);
}
} else if (await isHookFromConfig(options.components)) {
options.components &&
(await hookAdder({
requestedHook: options.components,
}));
} else {
await componentAdder({
requestedComponent: options.components?.toLowerCase(),
});
!isTemplate &&
(await cloneRepositoryAtRoot(join(_homeDir, config.gluestackDir)));
// define args based on --all or components
const args = options.all
? { addAll: true }
: { componentArgs: options.components.map((c) => c.toLowerCase()) };

try {
await componentAdder(args);
} catch (err) {
log.error(`\x1b[31mError: ${(err as Error).message}\x1b[0m`);
}
} catch (err) {
handleError(err);
Expand Down
44 changes: 40 additions & 4 deletions packages/gluestack-cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,23 @@ import { handleError } from '../util/handle-error';
import { log } from '@clack/prompts';
import { InitializeGlueStack } from '../util/init';
import { config } from '../config';
import { checkWritablePath, detectProjectType, isValidPath } from '../util';
import {
checkWritablePath,
detectProjectType,
getPackageMangerFlag,
isValidPath,
} from '../util';
import path, { resolve } from 'path';
import fs from 'fs';

const initOptionsSchema = z.object({
useNpm: z.boolean(),
useYarn: z.boolean(),
usePnpm: z.boolean(),
useBun: z.boolean(),
path: z.string().optional(),
templateOnly: z.boolean(),
projectType: z.string(),
});

export const init = new Command()
Expand All @@ -21,13 +29,26 @@ export const init = new Command()
.option('--use-npm ,useNpm', 'use npm to install dependencies', false)
.option('--use-yarn, useYarn', 'use yarn to install dependencies', false)
.option('--use-pnpm, usePnpm', 'use pnpm to install dependencies', false)
.option('--use-bun, useBun', 'use bun to install dependencies', false)
.option(
'--path <path>',
'path to the components directory. defaults to components/ui'
)
.option(
'--template-only templateOnly',
'Only install the template without installing dependencies',
false
)
.option(
'--projectType <projectType>',
'Type of project to initialize',
'library'
)
.action(async (opts) => {
try {
const options = initOptionsSchema.parse({ ...opts });
const isTemplate = options.templateOnly;
console.log('\n\x1b[1mWelcome to gluestack-ui!\x1b[0m\n');
const cwd = process.cwd();
//if cwd doesn't have package.json file
if (!fs.existsSync(path.join(cwd, 'package.json'))) {
Expand All @@ -36,6 +57,19 @@ export const init = new Command()
);
process.exit(1);
}
//if multiple package managers are used
if (
(options.useNpm && options.useYarn) ||
(options.useNpm && options.usePnpm) ||
(options.useYarn && options.usePnpm)
) {
log.error(
`\x1b[31mMultiple package managers selected. Please select only one package manager.\x1b[0m`
);
process.exit(1);
}
//define package manager
getPackageMangerFlag(options);
//if path option is used
if (options.path) {
// Check if the string starts with "/" or "."
Expand All @@ -48,13 +82,15 @@ export const init = new Command()
if (options.path !== config.writableComponentsPath) {
await checkWritablePath(options.path);
//check this change with all project types
config.writableComponentsPath = resolve(cwd, options.path);
config.writableComponentsPath = options.path;
}
}
// Detect project type
const projectType = await detectProjectType(cwd);
const projectType = isTemplate
? options.projectType
: await detectProjectType(cwd);
// Initialize the gluestack
InitializeGlueStack({ projectType });
InitializeGlueStack({ projectType, isTemplate });
} catch (err) {
handleError(err);
}
Expand Down
7 changes: 3 additions & 4 deletions packages/gluestack-cli/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@ const config = {
gluestackDir: '.gluestack/cache/gluestack-ui',
componentsResourcePath: 'example/storybook-nativewind/src/core-components',
hooksResourcePath: 'example/storybook-nativewind/src/core-components/hooks',
gluestackStyleRootPath: 'themed',
dependencyConfigPath:
'example/storybook-nativewind/src/core-components/nativewind/dependencies.json',
nativeWindRootPath: 'nativewind',
expoProject: 'expo',
nextJsProject: 'nextjs',
reactNativeCLIProject: 'react-native-cli',
tailwindConfigRootPath: 'example/storybook-nativewind/src/tailwind.config.js',
UIconfigPath: 'gluestack-ui-provider/config.ts',
writableComponentsPath: 'components/ui',
branchName: 'patch',
tagName: '@gluestack-ui/[email protected]',
style: 'nativewind',
providerComponent: 'gluestack-ui-provider',
configFileName: 'config.ts',
nativewindUtilPattern: '@gluestack-ui/nativewind-utils/',
gluestackUIPattern: '@gluestack-ui/',
templatesDir: '../../../template',
codeModesDir: '../../../template/codemods',
packageManager: null as string | null,
};

export { config };
Loading