Skip to content

Commit c107e11

Browse files
committed
Updated generate command params support and docs
1 parent 8912e41 commit c107e11

File tree

5 files changed

+64
-22
lines changed

5 files changed

+64
-22
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@
1616
"files.exclude": {
1717
".yarn/*": true
1818
},
19+
"files.eol": "\n",
1920
}

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,21 @@ cca --boilerplate telescope
126126

127127
Then, you'll navigate into `./your-project/packages/telescope` package for the next steps.
128128

129-
### Download with CLI
129+
You can also use `telescope generate` command to generate package according to the prompt or terminal command params such as:
130+
`telescope generate --access public --userfullname testname --useremail [email protected] --module-desc test --username salkfl --license MIT --module-name test --chain-name cosmos --use-npm-scoped`
131+
132+
The available options are:
133+
`--userfullname` `--useremail` `--module-desc` `--username` `--module-name` `--chain-name` `--access` `--use-npm-scoped` `--license`
134+
135+
If some required options are missing, it will prompt to ask for the info.
136+
137+
To be noted, `--use-npm-scoped` only works when `--access` is `public`
138+
139+
### Download protos with CLI
130140

131141
The old ` telescope install ` command has been deprecated
132142

133-
You can use our CLI for download. To download the proto files, `download` command.
143+
You can use our CLI to download protos by using `download` command.
134144

135145
```sh
136146
telescope download

packages/telescope/README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,21 @@ cca --boilerplate telescope
126126

127127
Then, you'll navigate into `./your-project/packages/telescope` package for the next steps.
128128

129-
### Download with CLI
129+
You can also use `telescope generate` command to generate package according to the prompt or terminal command params such as:
130+
`telescope generate --access public --userfullname testname --useremail [email protected] --module-desc test --username salkfl --license MIT --module-name test --chain-name cosmos --use-npm-scoped`
131+
132+
The available options are:
133+
`--userfullname` `--useremail` `--module-desc` `--username` `--module-name` `--chain-name` `--access` `--use-npm-scoped` `--license`
134+
135+
If some required options are missing, it will prompt to ask for the info.
136+
137+
To be noted, `--use-npm-scoped` only works when `--access` is `public`
138+
139+
### Download protos with CLI
130140

131141
The old ` telescope install ` command has been deprecated
132142

133-
You can use our CLI for download. To download the proto files, `download` command.
143+
You can use our CLI to download protos by using `download` command.
134144

135145
```sh
136146
telescope download

packages/telescope/src/commands/generate.ts

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,34 @@ export default async argv => {
1313
return shell.exit(1);
1414
}
1515

16-
const { name } = await prompt([
16+
let results: { [key: string]: any } = {};
17+
18+
const argsFromCommand = process.argv.slice(2);
19+
argsFromCommand.forEach((arg, index) => {
20+
if (arg.startsWith('--')) {
21+
let key = arg.slice(2).replace(/-/g, '').toUpperCase();
22+
key = `__${key}__`;
23+
const value = argsFromCommand[index + 1] && !argsFromCommand[index + 1].startsWith('--') ? argsFromCommand[index + 1] : '';
24+
25+
if (Array.isArray(value)) {
26+
results[key] = value.split(',');
27+
} else {
28+
results[key] = value;
29+
}
30+
}
31+
});
32+
const { name } = results.__MODULENAME__ ? { name: results.__MODULENAME__ } : await prompt([
1733
{
1834
type: 'string',
1935
name: 'name',
2036
message: 'Enter your new module name',
2137
}
2238
], argv);
23-
2439
shell.exec(`git clone ${repo} ${name}`);
2540
shell.cd(name);
2641

27-
const questions = JSON.parse(fs.readFileSync(`.questions.json`));
42+
let questions = JSON.parse(fs.readFileSync(`.questions.json`));
43+
questions = questions.filter(question => !(question.name in results));
2844

2945
const fullname = shell
3046
.exec('git config --global user.name', { silent: true })
@@ -46,10 +62,10 @@ export default async argv => {
4662
{ allowCamelCase: true }
4763
);
4864

49-
const results = await prompt(questions, args);
50-
let scopedResults;
65+
const answerResults = await prompt(questions, args);
66+
results = { ...results, answerResults }
5167

52-
const license = await prompt(
68+
const license = results.__LICENSE__ ?? await prompt(
5369
[
5470
{
5571
name: '__LICENSE__',
@@ -62,18 +78,23 @@ export default async argv => {
6278
[]
6379
);
6480

81+
let scopedResults;
6582
if (results.__ACCESS__ === 'public') {
66-
scopedResults = await prompt(
67-
[
68-
{
69-
type: 'confirm',
70-
name: 'scoped',
71-
message: 'use npm scopes?',
72-
required: true,
73-
},
74-
],
75-
[]
76-
);
83+
if (results.__USENPMSCOPED__ !== undefined) {
84+
scopedResults = { scoped: true }
85+
} else {
86+
scopedResults = await prompt(
87+
[
88+
{
89+
type: 'confirm',
90+
name: 'scoped',
91+
message: 'use npm scopes?',
92+
required: true,
93+
},
94+
],
95+
[]
96+
);
97+
}
7798
}
7899

79100
const files = []
@@ -99,7 +120,6 @@ Proprietary and confidential`;
99120
content = content.replace(new RegExp(key, 'g'), results[key]);
100121
}
101122
});
102-
103123
if (results.__ACCESS__ === 'public') {
104124
if (scopedResults.scoped) {
105125
content = content.replace(
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 35d63d3ed3da09e0dc55e4d4beb537bd4f59391a

0 commit comments

Comments
 (0)