@40q/40q-cli 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
package/Readme.md ADDED
@@ -0,0 +1,22 @@
1
+ # 40Q CLI
2
+
3
+ ## Installation
4
+ ```
5
+ yarn global add @40q/40q-cli
6
+ ```
7
+ or
8
+ ```
9
+ npm install -g @40q/40q-cli
10
+ ```
11
+
12
+ ## Commands
13
+
14
+ ### Setup
15
+ Setup is intended to scaffold tools configurations.
16
+
17
+ ```
18
+ 40q setup [tool]
19
+ ```
20
+
21
+ Supported Tools:
22
+ * eslint
package/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { q40Cli } from './src/40qCli';
4
+
5
+ q40Cli.init();
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@40q/40q-cli",
3
+ "version": "1.0.0",
4
+ "description": "40q CLI tool",
5
+ "main": "index.js",
6
+ "bin": {
7
+ "40q": "./dist/index.js"
8
+ },
9
+ "dependencies": {
10
+ "yargs": "^17.7.2"
11
+ },
12
+ "peerDependencies": {
13
+ "eslint": "^8.51.0"
14
+ },
15
+ "scripts": {
16
+ "build": "tsc",
17
+ "build-publish": "yarn build && yarn publish --access public"
18
+ },
19
+ "author": "40q <info@40q.agency> (https://40q.agency/)",
20
+ "license": "ISC",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "https://github.com/40Q/40q-cli.git"
24
+ },
25
+ "devDependencies": {
26
+ "@types/node": "^20.8.7",
27
+ "@types/yargs": "^17.0.29",
28
+ "ts-node": "^10.9.1",
29
+ "typescript": "^5.2.2"
30
+ }
31
+ }
package/src/40qCli.ts ADDED
@@ -0,0 +1,16 @@
1
+ import yargs from 'yargs';
2
+ import { hideBin } from 'yargs/helpers';
3
+ import { SetupCommand } from './commands/Setup.command';
4
+
5
+ export class q40Cli {
6
+ static init() {
7
+ yargs(hideBin(process.argv))
8
+ .command(
9
+ 'setup [tool]',
10
+ 'Setup a tool',
11
+ SetupCommand.builder,
12
+ SetupCommand.handler
13
+ )
14
+ .help().argv;
15
+ }
16
+ }
@@ -0,0 +1,6 @@
1
+ import { ArgumentsCamelCase, Argv } from 'yargs';
2
+
3
+ export abstract class Command {
4
+ static builder(yargs: Argv<{}>): void {}
5
+ static handler(argv: ArgumentsCamelCase<{}>): void {}
6
+ }
@@ -0,0 +1,65 @@
1
+ import { ArgumentsCamelCase, Argv } from 'yargs';
2
+ import { execSync } from 'child_process';
3
+ import { Command } from './Command';
4
+
5
+ const eslintrc = `
6
+ {
7
+ "extends": ["@40q/eslint-config"]
8
+ }
9
+ `;
10
+
11
+ const huskyrc = `
12
+ {
13
+ "hooks": {
14
+ "pre-commit": "lint-staged"
15
+ }
16
+ }
17
+ `;
18
+
19
+ const lintstagedrc = `
20
+ {
21
+ "*.{js,jsx,ts,tsx}": ["eslint --fix"]
22
+ }
23
+ `;
24
+
25
+ export class SetupCommand implements Command {
26
+ static builder(yargs: Argv<{}>) {
27
+ yargs.positional('tool', {
28
+ describe: 'Name of the tool to setup',
29
+ type: 'string',
30
+ });
31
+ }
32
+
33
+ static handler(argv: ArgumentsCamelCase<{}>) {
34
+ SetupCommand.setupTool(argv.tool as string);
35
+ }
36
+
37
+ static setupTool(tool: string) {
38
+ switch (tool) {
39
+ case 'eslint':
40
+ this.setupEslint();
41
+ break;
42
+
43
+ default:
44
+ console.error(
45
+ `Unknown tool: ${tool}. Please specify a supported tool.`
46
+ );
47
+ }
48
+ }
49
+
50
+ static setupEslint() {
51
+ console.log('Installing dependencies...');
52
+ execSync('yarn add --dev eslint @40q/eslint-config husky lint-staged');
53
+
54
+ console.log('Creating .eslintrc.json...');
55
+ execSync(`echo '${eslintrc}' > .eslintrc.json`);
56
+
57
+ console.log('Creating .huskyrc.json...');
58
+ execSync(`echo '${huskyrc}' > .huskyrc.json`);
59
+
60
+ console.log('Creating .lintstagedrc.json...');
61
+ execSync(`echo '${lintstagedrc}' > .lintstagedrc.json`);
62
+
63
+ console.log('Done!');
64
+ }
65
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2016",
4
+ "module": "commonjs",
5
+ "esModuleInterop": true,
6
+ "forceConsistentCasingInFileNames": true,
7
+ "strict": true,
8
+ "skipLibCheck": true,
9
+ "outDir": "./dist"
10
+ }
11
+ }