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: add eslint and prompt for options #68

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 7 additions & 17 deletions packages/@guidesmiths/cuckoojs-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,10 @@
},
"homepage": "https://github.com/guidesmiths/cuckoojs#readme",
"contributors": [
{
"name": "David Yusta",
"email": "[email protected]"
},
{
"name": "Laura Corbí",
"email": "[email protected]"
},
{
"name": "Adrián Rodríguez",
"email": "[email protected]"
},
{
"name": "Íñigo Marquínez",
"email": "[email protected]"
}
"David Yusta <[email protected]>",
"Laura Corbí <[email protected]>",
"Adrián Rodríguez <[email protected]>",
"Íñigo Marquínez <[email protected]>"
],
"main": "dist/src/cli.js",
"bin": {
Expand Down Expand Up @@ -71,5 +59,7 @@
"jest": "^29.3.1",
"ts-jest": "^29.0.3",
"typescript": "^4.9.4"
}
},
"types": "./dist/src/cli.d.ts",
"author": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class NewCommand extends AbstractCommand {
}

public async execute() {
const printer = new Printer({total: 8, step: 1});
const printer = new Printer({total: 9, step: 1});
this.printSuccess(messages.banner);

if (this.checkFileExists()) {
Expand Down Expand Up @@ -75,6 +75,10 @@ export class NewCommand extends AbstractCommand {
await this.bashRunnerHusky.addHuskyCommitMsg(this.name);
printer.endStep();

printer.startStep('Creating eslint configuration');
printer.endStep();
await this.schematicRunner.addESlint(this.name);

this.printSuccess(`\n 🐦 Your CuckooJS nest "${this.name}" is generated and ready to use 🐦`);
} catch (error: unknown) {
printer.load.fail(`Error generating new project: ${(error as Error).message}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ export class SchematicRunner extends GenericRunner {

public async addESlint(name: string) {
const args = [`@guidesmiths/cuckoojs-schematics:eslint --directory=${name}`];
await super.run({command: SchematicRunner.getSchematicsCliPath(), args, stdio: ['pipe', 'pipe', 'inherit']});
await super.run({command: SchematicRunner.getSchematicsCliPath(), args, stdio: ['inherit', 'inherit', 'inherit']});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ export const main = (options: any): Rule => (tree: Tree, context: SchematicConte
const path = normalize(options.directory);

const templateSource = apply(url('./files'), [
template({...options}),
template(
{
...options,
indentvalue: options.indent === 'tabs' ? '\'tabs\'' : 4,
}),
move(path),
renameFile(options),
]);
Expand All @@ -26,7 +30,7 @@ export const main = (options: any): Rule => (tree: Tree, context: SchematicConte
return chain([
merged,
updatePackageJson(path),
])(tree, context)
])(tree, context);
};

function renameFile(options: any): Rule {
Expand All @@ -47,16 +51,21 @@ function updatePackageJson(directory: string): Rule {
json.devDependencies = {};
}

json.devDependencies['eslint'] = '^8.29.0';
json.devDependencies.eslint = '^8.40.0';
json.devDependencies['eslint-config-airbnb-base'] = '^15.0.0';
json.devDependencies['eslint-plugin-import'] = '^2.26.0';
json.devDependencies['eslint-plugin-jest'] = '^27.1.6';
json.devDependencies['@typescript-eslint/eslint-plugin'] = '^5.59.6';
json.devDependencies['@typescript-eslint/parser'] = '^5.59.6';
json.devDependencies['eslint-plugin-promise'] = '^6.1.1';
json.devDependencies['eslint-config-standard-with-typescript'] = '^34.0.1';
json.devDependencies['eslint-plugin-n'] = '^15.7.0';

if(!json.scripts) {
json.scripts = {}
if (!json.scripts) {
json.scripts = {};
}

json.scripts['lint'] = 'eslint .';
json.scripts.lint = 'eslint .';
json.scripts['lint:fix'] = 'eslint . --fix';

tree.overwrite(path, JSON.stringify(json, null, 2));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
module.exports = {
env: {
commonjs: true,
es2021: true,
node: true,
'jest/globals': true
},
extends: 'airbnb-base',
overrides: [
],
parserOptions: {
ecmaVersion: 'latest',
},
plugins: ['jest'],
rules: {
},
env: {
commonjs: true,
es2021: true,
node: true,
'jest/globals': true,
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'airbnb-base',
],
overrides: [
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
plugins: ['jest', '@typescript-eslint'],
rules: {
indent: [
'error',
<%= indentvalue %>,
],
'linebreak-style': [
'error',
'<%= linebreakStyle %>',
],
quotes: [
'error',
'<%= quotes %>',
],
semi: [
'error',
'<%= semicolon %>',
],
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,59 @@
"description": "eslint config directory",
"default": ".",
"x-prompt": "Where do you want to setup eslint?"
},
"indent": {
"description": "identation style",
"type": "string",
"default": "tabs",
"x-prompt": {
"message": "What style of indentation do you use?",
"type": "list",
"items": [
{"label": "Tabs", "value": "tabs"},
{"label": "Spaces", "value": "spaces"}
]
}
},
"quotes": {
"description": "quote style",
"type": "string",
"default": "single",
"x-prompt": {
"message": "What quotes do you use for strings?",
"type": "list",
"items": [
{"label": "Double", "value": "double"},
{"label": "Single", "value": "single"}
]
}
},
"linebreakStyle": {
"description": "line-ending style",
"type": "string",
"default": "unix",
"x-prompt": {
"message": "What line endings do you use?",
"type": "list",
"items": [
{"label": "Unix", "value": "unix"},
{"label": "Windows", "value": "windows"}
]
}
},
"semicolon": {
"description": "semicolon yes or not",
"type": "string",
"default": "always",
"x-prompt": {
"message": "Do you require semicolons?",
"type": "list",
"items": [
{"label": "Yes", "value": "always"},
{"label": "No", "value": "never"}
]
}
}
},
"required": ["directory"]
"required": ["directory", "indent", "quotes", "linebreakStyle", "semicolon"]
}