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 20, 2022
1 parent 221b8cf commit 0809b6a
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 18 deletions.
59 changes: 49 additions & 10 deletions package-lock.json

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

8 changes: 4 additions & 4 deletions packages/generator-langium/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
"publish:latest": "npm publish --tag latest"
},
"dependencies": {
"colors": "^1.4.0",
"chalk": "^4.1.2",
"lodash": "^4.17.21",
"yeoman-generator": "^5.3.0"
"yeoman-generator": "^5.5.2"
},
"devDependencies": {
"@types/lodash": "^4.14.170",
Expand All @@ -53,7 +53,7 @@
},
"bugs": "https://github.com/langium/langium/issues",
"author": {
"name": "TypeFox",
"url": "https://www.typefox.io"
"name": "TypeFox",
"url": "https://www.typefox.io"
}
}
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.',
'Please provide a name to be shown in the UI.',
'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 0809b6a

Please sign in to comment.