Skip to content

Commit c0bd5aa

Browse files
committed
Core.
1 parent 8b5467d commit c0bd5aa

14 files changed

+2763
-0
lines changed

.eslintrc.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
root: true,
3+
extends: ['@react-native-community', 'prettier'],
4+
parser: '@typescript-eslint/parser',
5+
plugins: ['@typescript-eslint', 'prettier'],
6+
env: {
7+
'jest/globals': true,
8+
},
9+
rules: {
10+
'no-shadow': 'off',
11+
curly: 'error',
12+
},
13+
ignorePatterns: ['jest/*'],
14+
globals: {},
15+
};

.gitignore

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
lib/
9+
# Diagnostic reports (https://nodejs.org/api/report.html)
10+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11+
12+
# Runtime data
13+
pids
14+
*.pid
15+
*.seed
16+
*.pid.lock
17+
18+
lib
19+
# Directory for instrumented libs generated by jscoverage/JSCover
20+
lib-cov
21+
22+
# Coverage directory used by tools like istanbul
23+
coverage
24+
*.lcov
25+
26+
# nyc test coverage
27+
.nyc_output
28+
29+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
30+
.grunt
31+
32+
# Bower dependency directory (https://bower.io/)
33+
bower_components
34+
35+
# node-waf configuration
36+
.lock-wscript
37+
38+
# Compiled binary addons (https://nodejs.org/api/addons.html)
39+
build/Release
40+
41+
# Dependency directories
42+
node_modules/
43+
jspm_packages/
44+
45+
# TypeScript v1 declaration files
46+
typings/
47+
48+
# TypeScript cache
49+
*.tsbuildinfo
50+
51+
# Optional npm cache directory
52+
.npm
53+
54+
# Optional eslint cache
55+
.eslintcache
56+
57+
# Microbundle cache
58+
.rpt2_cache/
59+
.rts2_cache_cjs/
60+
.rts2_cache_es/
61+
.rts2_cache_umd/
62+
63+
# Optional REPL history
64+
.node_repl_history
65+
66+
# Output of 'npm pack'
67+
*.tgz
68+
69+
# Yarn Integrity file
70+
.yarn-integrity
71+
72+
# dotenv environment variables file
73+
.env
74+
.env.test
75+
76+
# parcel-bundler cache (https://parceljs.org/)
77+
.cache
78+
79+
# Next.js build output
80+
.next
81+
82+
# Nuxt.js build / generate output
83+
.nuxt
84+
dist
85+
86+
# Gatsby files
87+
.cache/
88+
# Comment in the public line in if your project uses Gatsby and *not* Next.js
89+
# https://nextjs.org/blog/next-9-1#public-directory-support
90+
# public
91+
92+
# vuepress build output
93+
.vuepress/dist
94+
95+
# Serverless directories
96+
.serverless/
97+
98+
# FuseBox cache
99+
.fusebox/
100+
101+
# DynamoDB Local files
102+
.dynamodb/
103+
104+
# TernJS port file
105+
.tern-port

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
jest/cache
2+
jest/coverage

.prettierrc.cjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
arrowParens: 'avoid',
3+
bracketSameLine: true,
4+
bracketSpacing: false,
5+
singleQuote: true,
6+
trailingComma: 'all',
7+
printWidth: 120,
8+
useTabs: true,
9+
};

package.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "node-typescript-cli",
3+
"version": "1.0.0",
4+
"description": "A base for creating Node tools",
5+
"main": "./lib/index.js",
6+
"repository": "https://github.com/net-runner/node-typescript-cli",
7+
"author": "net-runner <slazynski.j@gmail.com>",
8+
"license": "MIT",
9+
"dependencies": {
10+
"chalk": "^5.2.0",
11+
"commander": "^9.4.1",
12+
"inquirer": "^9.1.4",
13+
"log-symbols": "^5.1.0",
14+
"meow": "^11.0.0",
15+
"nanospinner": "^1.1.0",
16+
"path": "^0.12.7",
17+
"replace-in-file": "^6.3.5"
18+
},
19+
"scripts": {
20+
"start": "node .",
21+
"build": "webpack",
22+
"run": "yarn build && yarn start"
23+
},
24+
"bin": "./lib/index.js",
25+
"devDependencies": {
26+
"@types/inquirer": "^9.0.3",
27+
"@types/node": "^18.11.18",
28+
"@typescript-eslint/eslint-plugin": "^5.47.1",
29+
"@typescript-eslint/parser": "^5.47.1",
30+
"eslint": "^8.31.0",
31+
"eslint-plugin-prettier": "^4.2.1",
32+
"prettier": "^2.8.1",
33+
"ts-loader": "^9.4.2",
34+
"ts-node": "^10.9.1",
35+
"typescript": "^4.9.4",
36+
"webpack": "^5.75.0",
37+
"webpack-cli": "^5.0.1"
38+
}
39+
}

src/directory.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import path, {dirname} from 'path';
2+
import {fileURLToPath} from 'url';
3+
4+
// /lib/index.js
5+
export const filename = fileURLToPath(import.meta.url);
6+
7+
export const currentWorkingDirectory = process.cwd();
8+
9+
export const directoryPath = (repoName: string) => path.join(currentWorkingDirectory, repoName);
10+
export const navigateToProjectFolder = (repoName: string) => `cd ${repoName} &&`;

src/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env node
2+
3+
import {Argument, program} from 'commander';
4+
5+
program
6+
.name('node-typescript-cli')
7+
.description('Base for creating Node tools with Typescript')
8+
.version('1.0.0')
9+
.action((str, options) => {
10+
//Do some work here
11+
});
12+
13+
program.parse();
14+

src/log.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import logSymbols from 'log-symbols';
2+
3+
export const log = console.log;
4+
5+
export const logError = (message: string | string[]) => console.error(logSymbols.error, message);

src/prompt.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import inquirer from 'inquirer';
2+
3+
export const prompt = inquirer.createPromptModule();

src/replace.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {replaceInFile, ReplaceInFileConfig} from 'replace-in-file';
2+
import {log} from './log';
3+
4+
export const replace = async (options: ReplaceInFileConfig) => {
5+
try {
6+
const results = await replaceInFile(options);
7+
log('Replacement results:', results);
8+
} catch (error) {
9+
console.error('Error occurred:', error);
10+
}
11+
};

src/runCommand.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import {execSync} from 'child_process';
2+
import logSymbols from 'log-symbols';
3+
import {navigateToProjectFolder} from './directory';
4+
5+
export const runCommand = (command: string, isVerbose: boolean, repoName: string) => {
6+
try {
7+
execSync(`${navigateToProjectFolder(repoName)} ${command}`, {stdio: isVerbose ? 'inherit' : 'ignore'});
8+
} catch (e) {
9+
console.error(logSymbols.error, `Failed to execute ${command}`, e);
10+
}
11+
return true;
12+
};
13+
14+
export const runCommandWithOutput = (command: string, isVerbose: boolean, repoName: string) => {
15+
try {
16+
return execSync(`${command}`).toString();
17+
} catch (e) {
18+
console.error(logSymbols.error, `Failed to execute ${command}`, e);
19+
}
20+
};

tsconfig.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2017",
4+
"module": "ESNext",
5+
"lib": ["es6", "es2015", "dom"],
6+
"declaration": true,
7+
"outDir": "lib",
8+
"rootDir": "./src",
9+
"strict": true,
10+
"types": ["node"],
11+
"esModuleInterop": true,
12+
"moduleResolution": "node",
13+
"resolveJsonModule": true
14+
}
15+
}

webpack.config.cjs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
const path = require('path');
3+
4+
module.exports = {
5+
mode: "development",
6+
devtool: "inline-source-map",
7+
target: 'node',
8+
entry: {
9+
main: "./src/index.ts",
10+
},
11+
output: {
12+
path: path.resolve(__dirname, './lib'),
13+
filename: "index.js" // <--- Will be compiled to this single file
14+
},
15+
resolve: {
16+
extensions: [".ts", ".tsx", ".js"],
17+
},
18+
module: {
19+
rules: [
20+
{
21+
test: /\.tsx?$/,
22+
loader: "ts-loader"
23+
}
24+
]
25+
}
26+
};

0 commit comments

Comments
 (0)