diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 1dfcfc4..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": ["oclif", "oclif-typescript", "prettier"] -} diff --git a/.gitignore b/.gitignore index acc2296..2a6b283 100644 --- a/.gitignore +++ b/.gitignore @@ -17,5 +17,5 @@ pnpm-lock.yaml !.yarn/sdks !.yarn/versions - +~~* diff --git a/.prettierrc.json b/.prettierrc.json deleted file mode 100644 index 6314335..0000000 --- a/.prettierrc.json +++ /dev/null @@ -1 +0,0 @@ -"@oclif/prettier-config" diff --git a/bin/run.ts b/bin/run.ts index 9f00b21..166e6a5 100755 --- a/bin/run.ts +++ b/bin/run.ts @@ -1,5 +1,11 @@ #!/usr/bin/env bun -import {execute} from '@oclif/core' + + +import {execute, settings} from '@oclif/core' +// process.env.DEBUG="" + + +settings.performanceEnabled = true await execute({dir: import.meta.url}) diff --git a/bun.lockb b/bun.lockb index 2809042..31bf609 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..7e1b7b4 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,43 @@ +// eslint.config.js +const prettierConfig = require("./prettier.config.js"); + +module.exports = { + extends: ["oclif", "oclif-typescript", "prettier"], + // Ignore specific folders to avoid unnecessary linting + ignores: ["node_modules", "dist", "build"], + // Specify the files to apply ESLint to + files: ["*.js", "*.jsx", "*.ts", "*.tsx"], + languageOptions: { + ecmaVersion: 2021, + sourceType: "module", + }, + plugins: { + prettier: require("eslint-plugin-prettier"), + }, + rules: { + ...require("eslint-config-prettier").rules, // Disable conflicting ESLint rules + "prettier/prettier": ["warn", prettierConfig], // Use Prettier as a rule + "no-restricted-syntax": "off", + "padding-line-between-statements": [ + "error", + { + blankLine: "always", + prev: "block", + next: "*", + }, + { + blankLine: "always", + prev: "block-like", + next: "*", + }, + ], + }, + // Set environments globally + languageOptions: { + globals: { + browser: true, + node: true, + es2021: true, + }, + }, +}; diff --git a/helpers/jjEnsure.ts b/helpers/jjEnsure.ts new file mode 100644 index 0000000..e772545 --- /dev/null +++ b/helpers/jjEnsure.ts @@ -0,0 +1,54 @@ +import { jjConfigs } from "@src/index"; +import path from "path"; +import fs from 'fs-extra'; +import inquirer from "inquirer"; +import * as YAML from "js-yaml" +import { _ } from "lodash"; + +export const srmFileName = 'package.json' + +export const srmFilePath = path.resolve(srmFileName); + + +export const jjEnsure = async (opts) => { + jjConfigs.modulePath = path.resolve(__dirname, "../") + jjConfigs.tmpDir = `${jjConfigs.modulePath}/~~tmp` + jjConfigs.configSaveFilePath = `${jjConfigs.tmpDir}/configSaveFilePath.txt` + if (!fs.existsSync(jjConfigs.tmpDir)) { + fs.mkdirSync(jjConfigs.tmpDir, { recursive: true }) + } + + if (!fs.existsSync(jjConfigs.configSaveFilePath)) { + + const answer: any = await inquirer.prompt([ + { + type: 'input', + name: 'jjYamlPath', + message: 'Please provide jj.yaml file absolute path', + }, + ]) + if (!fs.existsSync(answer.jjYamlPath)) { + opts.context.error(`can not find ${answer.jjYamlPath}`) + } + + const jjYamlRawContent = await fs.readFile(answer.jjYamlPath, "utf8") + const jjYamlObj: any = YAML.load(jjYamlRawContent) + if (_.isEmpty(jjYamlObj?.environments || {})) { + opts.context.error(`Wrong ${answer.jjYamlPath} file`) + } + + jjConfigs.jjYamlObj = jjYamlObj + + await fs.writeFile(jjConfigs.configSaveFilePath, answer.jjYamlPath, "utf8") + + } else { + jjConfigs.jjYamlPath = await fs.readFile(jjConfigs.configSaveFilePath, "utf8") + const jjYamlRawContent = await fs.readFile(jjConfigs.jjYamlPath, "utf8") + const jjYamlObj: any = YAML.load(jjYamlRawContent) + if (_.isEmpty(jjYamlObj?.environments || {})) { + opts.context.error(`Wrong ${jjConfigs.jjYamlPath} file`) + } + jjConfigs.jjYamlObj = jjYamlObj + } + +} \ No newline at end of file diff --git a/package.json b/package.json index e20725a..a36b56f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "jj-command-line", "description": "jj cli", - "version": "0.0.5", + "version": "0.0.7", "author": "Jason Jafari", "bin": { "jj": "./bin/run.ts" @@ -20,6 +20,7 @@ "@oclif/plugin-warn-if-update-available": "^3.1.21", "@oclif/plugin-which": "^3.2.17", "fs-extra": "^11.2.0", + "inquirer": "^12.0.1", "lodash": "^4.17.21" }, "devDependencies": { @@ -37,7 +38,7 @@ "oclif": "^4", "shx": "^0.3.3", "ts-node": "^10", - "typescript": "^5" + "typescript": "^5.6.3" }, "engines": { "node": ">=18.0.0" @@ -53,7 +54,7 @@ ], "license": "MIT", "main": "src/index.ts", - "type": "module", + "type": "commonjs", "oclif": { "bin": "jj", "dirname": "jj", @@ -74,9 +75,11 @@ "theme": "theme.json", "hooks": { "prerun": [ - "./src/hooks/postrun/customPostRun.ts" + "./src/hooks/prerun/customPreRun.ts" ], - "postrun": "./src/hooks/prerun/customPreRun.ts" + "postrun": [ + "./src/hooks/postrun/customPostRun.ts" + ] } }, "repository": "https://github.com/jafarijason/jj/jj", @@ -86,5 +89,8 @@ "test": "mocha --forbid-only \"test/**/*.test.ts\"", "pre-publish": "git add . && git push --follow-tags" }, - "types": "dist/index.d.ts" + "alias": { + "@helpers/*": "./helpers/$1", + "@src/*": "./src/$1" + } } \ No newline at end of file diff --git a/prettier.config.js b/prettier.config.js new file mode 100644 index 0000000..309bdca --- /dev/null +++ b/prettier.config.js @@ -0,0 +1,32 @@ +// "@oclif/prettier-config" + +const baseConfig = require("@oclif/prettier-config"); + +module.exports = { + ...baseConfig, + arrowParens: "always", + bracketSameLine: true, + bracketSpacing: true, + jsxSingleQuote: false, + printWidth: 150, + semi: true, + singleAttributePerLine: false, + singleQuote: false, + trailingComma: "es5", + tabWidth: 4, + useTabs: false, + overrides: [ + { + files: ["*.json"], + options: { + parser: "json", + }, + }, + { + files: ["*.ts", "*.mts", "*.tsx"], + options: { + parser: "typescript", + }, + }, + ], +}; diff --git a/src/commands/hello/world.ts b/src/commands/hello/world.ts index 8111043..a325e3b 100644 --- a/src/commands/hello/world.ts +++ b/src/commands/hello/world.ts @@ -1,4 +1,5 @@ import {Command} from '@oclif/core' +import { jjConfigs } from '@src/index' export default class World extends Command { static args = {} @@ -14,6 +15,9 @@ hello world! (./src/commands/hello/world.ts) static flags = {} async run(): Promise { + console.log(jjConfigs) this.log('hello world! (./src/commands/hello/world.ts)') + this.warn('warn') + this.debug('jjjjjjj') } } diff --git a/src/hooks/prerun/customPreRun.ts b/src/hooks/prerun/customPreRun.ts index be45d43..654ae21 100644 --- a/src/hooks/prerun/customPreRun.ts +++ b/src/hooks/prerun/customPreRun.ts @@ -1,10 +1,15 @@ import { Hook, Command } from '@oclif/core' import fs from 'fs-extra'; import _ from 'lodash'; +import { jjEnsure } from '@helpers/jjEnsure'; const hook: Hook<'prerun'> = async function (opts) { + + + await jjEnsure(opts) + // srmVersion // console.log(opts.Command.flags) diff --git a/src/index.ts b/src/index.ts index 3dee20b..cbb3748 100755 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,5 @@ #!/usr/bin/env bun -export {run} from '@oclif/core' +export const jjConfigs: any = {} + +export { run } from '@oclif/core' diff --git a/tsconfig.json b/tsconfig.json index e144b78..21134c4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,15 +1,23 @@ { + "ts-node": { + "require": ["tsconfig-paths/register"] + }, "compilerOptions": { "declaration": true, - "module": "Node16", - "outDir": "dist", - "rootDir": "src", - "strict": true, - "target": "es2022", - "moduleResolution": "node16" - }, - "include": ["./src/**/*"], - "ts-node": { - "esm": true + "module": "CommonJS", + "baseUrl": ".", + "target": "ES6", + "moduleResolution": "node", + "paths": { + "@helpers/*": ["./helpers/*"], + "@src/*": ["./src/*"], + }, + "jsx": "react-jsx", + "resolveJsonModule": true, + "allowJs": true, + "esModuleInterop": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "noImplicitAny": false, } -} +} \ No newline at end of file