Skip to content

Commit 79f67db

Browse files
authored
Merge pull request #8 from lokesh-coder/develop
Add support for workspace
2 parents 531a017 + 6a2018b commit 79f67db

File tree

58 files changed

+842
-236
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+842
-236
lines changed

docs/gatsby-config.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,8 @@ const githubAPIOptions = {
7070
issues {
7171
totalCount
7272
}
73-
stargazers(first: 100) {
74-
edges {
75-
node {
76-
name
77-
login
78-
avatarUrl
79-
}
80-
}
73+
stargazers {
74+
totalCount
8175
}
8276
collaborators(first: 100) {
8377
edges {

docs/src/components/sidebar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ const MenuLinks = ({ allContent }) => {
1212
<li className="mb-1">
1313
<Link
1414
to={`${fm.path}`}
15-
className="text-gray-600 font-medium flex text-base"
15+
className="text-gray-600 font-medium flex text-base hover:text-gray-800 group"
1616
activeClassName="active text-primary"
1717
partiallyActive={true}
1818
>
1919
<i
20-
className={`mr-3 text-lg text-gray-600 active:text-primary ri-${fm.icon}`}
20+
className={`mr-3 text-lg text-gray-600 active:text-primary group-hover:text-gray-800 ri-${fm.icon}`}
2121
></i>
2222
<span className="flex-1">{fields.title}</span>
2323
{fm.skip && <i class="ri-anchor-fill"></i>}

docs/src/markdown/docs/main/core/commands.md

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Command is a core part of lesy. You can create and add commands in multiple ways
1212
- Run multi-level sub commands
1313
- Run another command programatically
1414
- Parse and validate arguments and flags
15-
- Use features from app or plugins
15+
- Use features and utils from app or plugins
1616

1717
### Types of commands
1818

@@ -22,8 +22,8 @@ Command can be an `Object`, `Function` or `Class` .
2222

2323
```typescript
2424
{
25-
name:"hello",
26-
run:()=>console.log("Hello Buddy!")
25+
name: "hello",
26+
run: () => console.log("Hello Buddy!")
2727
}
2828
```
2929

@@ -92,21 +92,27 @@ export default {
9292
};
9393
```
9494

95+
> If you want to exclude one or more files, you can simply add `_` prefix to the file name. For example, `/commands/_greeting.js`
96+
9597
### Anatomy of command
9698

97-
The only required properties for a command is `name` and `run` . Everything else is optional and used for other purposes.
99+
The only required property for a command is `run` . Everything else is optional.
98100

99101
#### name
100102

101103
It refers the name of the command. It should be unique and short. Hyphen `-` is allowed.
102104

105+
#### description
106+
107+
This is a command description used by help and other plugins.
108+
103109
#### run
104110

105-
This function or method will be executed when this command is triggered.
111+
It is a function which will be executed when this command is triggered.
106112

107113
#### aliases
108114

109-
Command can have multiple alias. Please make sure you are not using the same alias in the another command
115+
Command can have multiple aliases. Please make sure you are not using the same alias in the another command
110116

111117
```typescript
112118
{
@@ -124,14 +130,15 @@ Command can have multiple alias. Please make sure you are not using the same ali
124130

125131
#### args
126132

127-
These are the arguments schema. This has inbuild validation. [refer](foobar) [](/)Validator helper.
133+
These are the arguments schema. This has inbuild validation. [refer](foobar) Validator helper.
128134

129135
```typescript
130136
{
131137
name:"hello",
132138
args:{
133139
username:{
134-
required:true
140+
required:true,
141+
requiredError:"Please provide username",
135142
},
136143
age:{}
137144
},
@@ -173,14 +180,14 @@ $ node bin/cmd hello // THROWS ERROR
173180
*/
174181
```
175182

176-
#### extra
183+
#### additionalInfo
177184

178-
This extra text will be used by other plugins and middlewares. Originally, use case is for showing extra info about the command in help or pilot command
185+
This extra text will be used by other plugins and middlewares. Originally, use case is for showing info about the command in help or pilot command
179186

180187
```typescript
181188
{
182189
name:"delete",
183-
extra:"this command will delete all files. run with caution.",
190+
additionalInfo:"this command will delete all files. run with caution.",
184191
run:()=>{}
185192
}
186193
```
@@ -201,10 +208,6 @@ $ node bin/cmd generate component
201208
*/
202209
```
203210

204-
#### description
205-
206-
This is a command description used by help and other plugins.
207-
208211
#### usage
209212

210213
Sample usage code shown in the help command
@@ -246,6 +249,10 @@ The `run` method provides various data about the command and app.
246249
}
247250
```
248251

252+
#### data.utils
253+
254+
todo
255+
249256
### Sub commands
250257

251258
Commands can be nested multiple levels. If you want to make a sub-command, just add the parent name in `main` property. Other features of the command remains same for sub commands.
@@ -298,7 +305,7 @@ Please dont use parent name aliases
298305

299306
### Default command
300307

301-
By default **lesy** look for command named `default` if no args supplied in the input. If you would like to run different command as a default command, set it in the config.
308+
By default **lesy** looks for command named `default` if no args supplied in the input. If you would like to run different command as a default command, set it in the config.
302309

303310
```typescript
304311
{

docs/src/markdown/docs/main/core/middlewares.md

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ path: /docs/core/middlewares
44
icon: fire-fill
55
---
66

7-
Middlewares are special type of hooks, to inject new functionality or change tge behaviour of the command flow. For instance, if you want to redirect the command, or validate the middleware can be hooked in to specific points in the flow. Basically, they are simple functions which will be execute at the runtime.
7+
Middlewares are special type of hooks, to inject new functionality or change the behaviour of the command flow. For instance, if you want to redirect the command or validate, the middleware can be hooked in to specific points in the flow. Basically, they are simple functions which will be execute at specific point during runtime.
88

99
### Hook points
1010

@@ -34,11 +34,10 @@ export default {
3434
Add the middleware file in the **index.ts** file.
3535

3636
```typescript
37-
let argv = process.argv.slice(2);
3837
let commands = [...];
3938
let middlewares = [`${__dirname}/middlewares/start.ts`];
4039

41-
export { argv, commands, middlewares };
40+
export { commands, middlewares };
4241
```
4342

4443
Middleware should return the input data to continue the flow.
@@ -76,9 +75,9 @@ This will run after loading all commands and plugins. The run context will have
7675
```typescript
7776
export default {
7877
on: "START",
79-
run: (data) => {
80-
console.log(data.cmds);
81-
return data;
78+
run: (ctx) => {
79+
console.log(ctx.cmds);
80+
return ctx;
8281
},
8382
};
8483
```
@@ -90,14 +89,14 @@ This will run before parsing raw argv input. At this point you can change **argv
9089
```typescript
9190
export default {
9291
on: "PRE_PARSE",
93-
run: (data) => {
94-
// data.argv - raw input argv values
95-
// data.root - root path
96-
// data.config - config object
97-
// data.utils - colors() and spinner() object
98-
// data.feature - all features
99-
// data.request - oject of dynamic actions
100-
return data;
92+
run: (ctx) => {
93+
// ctx.argv - raw input argv values
94+
// ctx.root - root path
95+
// ctx.config - config object
96+
// ctx.utils - colors() and spinner() object
97+
// ctx.feature - all features
98+
// ctx.request - oject of dynamic actions
99+
return ctx;
101100
},
102101
};
103102
```
@@ -109,17 +108,17 @@ Run after parsing raw argv values.
109108
```typescript
110109
export default {
111110
on: "PRE_PARSE",
112-
run: (data) => {
113-
// data.argv - raw input argv values
114-
// data.root - root path
115-
// data.config - config object
116-
// data.utils - colors() and spinner() object
117-
// data.feature - all features
118-
// data.request - oject of dynamic actions
119-
120-
// data.args - resolved args
121-
// data.flags - resolved flags
122-
return data;
111+
run: (ctx) => {
112+
// ctx.argv - raw input argv values
113+
// ctx.root - root path
114+
// ctx.config - config object
115+
// ctx.utils - colors() and spinner() object
116+
// ctx.feature - all features
117+
// ctx.request - oject of dynamic actions
118+
119+
// ctx.args - resolved args
120+
// ctx.flags - resolved flags
121+
return ctx;
123122
},
124123
};
125124
```
@@ -131,9 +130,9 @@ Once lesy found the right command to execute, it will pass the command object to
131130
```typescript
132131
export default {
133132
on: "PRE_VALIDATE",
134-
run: (data) => {
135-
console.log(data);
136-
return data;
133+
run: (ctx) => {
134+
console.log(ctx);
135+
return ctx;
137136
},
138137
};
139138
```
@@ -171,30 +170,31 @@ After validation passes, **pre_run** will be executed will all the necessary inf
171170
```typescript
172171
export default {
173172
on: "PRE_RUN",
174-
run: (data) => {
175-
// data.argv - raw input argv values
176-
// data.root - root path
177-
// data.config - config object
178-
// data.utils - colors() and spinner() object
179-
// data.feature - all features
180-
// data.request - oject of dynamic actions
181-
// data.args - resolved args
182-
// data.flags - resolved flags
183-
// data.rest - unknown args
184-
return data;
173+
run: (ctx) => {
174+
// ctx.argv - raw input argv values
175+
// ctx.root - root path
176+
// ctx.config - config object
177+
// ctx.utils - colors() and spinner() object
178+
// ctx.feature - all features
179+
// ctx.request - oject of dynamic actions
180+
// ctx.args - resolved args
181+
// ctx.flags - resolved flags
182+
// ctx.rest - unknown args
183+
return ctx;
185184
},
186185
};
187186
```
188187

189188
### END - Hook
190189

191-
This hook will run at the end of the command flow. There is no run context. Thus no need of return statement.
190+
This hook will run at the end of the command flow.
192191

193192
```typescript
194193
export default {
195194
on: "END",
196-
run: () => {
195+
run: (ctx) => {
197196
console.log("Command ran successfully!");
197+
return ctx;
198198
},
199199
};
200200
```

docs/src/markdown/docs/main/core/testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe("CLI", () => {
2828
});
2929
});
3030

31-
it("should log proper outout", async () => {
31+
it("should log proper output", async () => {
3232
let response = await testBed.run(["hello"]);
3333
expect(response).toContain("hello yoyo!");
3434
});

docs/src/markdown/docs/main/get-started/concepts.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ title: Concepts
33
path: /docs/get-started/concepts
44
icon: honour-fill
55
---
6+
7+
Lesy is build based on frictionless sleek middleware architecture, thus maintaining the each core components work independently as well as play together.
8+
9+
<img src="/images/concept.png" width="360"/>

docs/src/markdown/docs/main/get-started/installation.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ path: /docs/get-started/installation
44
icon: folder-download-fill
55
---
66

7-
Setting up Lesy is pretty simple and straightforward.
7+
Setting up Lesy is pretty simple and straightforward. And there are two ways to do that. Use **Lesy CLI** or do it manually.
88

9-
### Generate project with CLI
9+
### Scaffold project with CLI
1010

1111
One easy way is using `npx` to generate project boilerplate with one command.
1212

@@ -42,7 +42,7 @@ lesy my-cli --yes
4242

4343
### Project structure
4444

45-
Here's how the project structure look like, after the project is generated
45+
Here's how the project structure look like, after the project is created
4646

4747
```
4848
my-cli
@@ -61,7 +61,7 @@ my-cli
6161

6262
### Manual setup
6363

64-
Actually manual set up is also easy.
64+
If you are creating a simple CLI project and dont want too many directories, then its pretty simple.
6565

6666
**Step 1**: Create new node project:
6767

@@ -76,28 +76,35 @@ cd my-cli
7676
npm install @lesy/compiler
7777
```
7878

79-
**Step 3**: Create `executable` bin file `my-cli/bin/cmd`
79+
**Step 3**: Create main `index.(js|ts)` file
8080

8181
```js
8282
#!/usr/bin/env node
8383

84-
const path = require("path");
8584
const lesy = require("@lesy/compiler");
8685

8786
lesy({
88-
root: path.resolve(__dirname, "../"),
89-
commands:[...],
87+
root: __dirname,
88+
commands: [
89+
{
90+
name: "default",
91+
run: () => console.log("hello"),
92+
},
93+
"./src/commands",
94+
],
9095
/* ...other props */
9196
}).parse();
9297
```
9398

94-
**Step 4**: Update executable file name in `package.json` file
99+
**Step 4**: Update bin property in `package.json` file
95100

96101
```json
97102
{
98103
"name": "my-cli",
99104
"bin": {
100-
"mycli": "bin/cmd"
105+
"mycli": "index.js"
101106
}
102107
}
103108
```
109+
110+
its done!

0 commit comments

Comments
 (0)