Skip to content

Commit

Permalink
#258: Add descriptions to Yeoman questions
Browse files Browse the repository at this point in the history
  • Loading branch information
spoenemann committed Jan 18, 2022
1 parent 221b8cf commit 38c5dab
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 16 deletions.
57 changes: 47 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions packages/generator-langium/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@
"publish:latest": "npm publish --tag latest"
},
"dependencies": {
"colors": "^1.4.0",
"lodash": "^4.17.21",
"yeoman-generator": "^5.3.0"
"yeoman-generator": "^5.5.2"
},
"devDependencies": {
"@types/lodash": "^4.14.170",
Expand Down
25 changes: 21 additions & 4 deletions packages/generator-langium/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import Generator from 'yeoman-generator';
import _ from 'lodash';
import chalk from 'chalk';
import path from 'path';
import 'colors';

const TEMPLATE_DIR = '../langium-template';
const USER_DIR = '.';
Expand Down Expand Up @@ -38,6 +38,10 @@ function printLogo(log: (message: string) => void): void {
log('');
}

function description(...d: string[]): string {
return chalk.reset(chalk.dim(d.join(' ') + '\n')) + chalk.green('?');
}

class LangiumGenerator extends Generator {
private answers: Answers;

Expand All @@ -51,12 +55,22 @@ class LangiumGenerator extends Generator {
{
type: 'input',
name: 'extensionName',
prefix: description(
'Welcome to Langium!',
'This tool generates a VS Code extension with a "Hello World" language to get started quickly.',
'The extension name is an identifier used in the extension marketplace or package registry.'
),
message: 'Your extension name:',
default: 'hello-world',
},
{
type: 'input',
name: 'rawLanguageName',
prefix: description(
'The language name is used to identify your language in VS Code.',
'You can write it normally (space separated).',
'CamelCase and kebab-case variants will be created and used in different parts of the extension and language server.'
),
message: 'Your language name:',
default: 'Hello World',
validate: (input: string): boolean | string =>
Expand All @@ -67,13 +81,16 @@ class LangiumGenerator extends Generator {
{
type: 'input',
name: 'fileExtensions',
message:
'File extensions of your language, separated by commas:',
prefix: description(
'Source files of your language are identified by their file name extension.',
'You can specify multiple file extensions separated by commas.'
),
message: 'File extensions:',
default: '.hello',
validate: (input: string): boolean | string =>
/^\.?\w+(\s*,\s*\.?\w+)*$/.test(input)
? true
: 'The file extension can start with . and must contain only letters and digits. Extensions must be separated by commas.',
: 'A file extension can start with . and must contain only letters and digits. Extensions must be separated by commas.',
},
]);
}
Expand Down

0 comments on commit 38c5dab

Please sign in to comment.