From 1dac2a8c5ab6a5e10b89a44075b80084a1709e48 Mon Sep 17 00:00:00 2001 From: Max T Date: Thu, 30 Jan 2025 12:34:55 -0500 Subject: [PATCH 01/15] Updating config files --- .eslintrc.json | 26 -------------- .gitignore | 3 +- .vscode-test.mjs | 11 ++++++ .vscode/extensions.json | 2 +- .vscode/launch.json | 21 ++++++++--- .vscode/settings.json | 11 ++++++ .vscode/tasks.json | 67 ++++++++++++++++++++++++++++++++++++ .vscodeignore | 15 +++++++- eslint.config.mjs | 49 ++++++++++++++++++++++++++ package.json | 38 +++++++++++--------- tsconfig.generate.types.json | 2 +- tsconfig.test.json | 14 ++++++++ 12 files changed, 208 insertions(+), 51 deletions(-) delete mode 100644 .eslintrc.json create mode 100644 .vscode-test.mjs create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json create mode 100644 eslint.config.mjs create mode 100644 tsconfig.test.json diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 056858e..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "env": { - "browser": false, - "commonjs": true, - "es6": true, - "node": true, - "mocha": true - }, - "parserOptions": { - "ecmaVersion": "latest", - "ecmaFeatures": { - "jsx": true - }, - "sourceType": "module" - }, - "ignorePatterns": ["lib", "app", "out"], - "rules": { - "no-const-assign": "warn", - "no-this-before-super": "warn", - "no-undef": "error", - "no-unreachable": "warn", - "no-unused-vars": "error", - "constructor-super": "warn", - "valid-typeof": "warn" - } -} diff --git a/.gitignore b/.gitignore index 883967a..dbcf207 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules package-lock.json .vscode-test -out \ No newline at end of file +out +dist \ No newline at end of file diff --git a/.vscode-test.mjs b/.vscode-test.mjs new file mode 100644 index 0000000..2e005f8 --- /dev/null +++ b/.vscode-test.mjs @@ -0,0 +1,11 @@ +import {defineConfig} from "@vscode/test-cli"; + +export default defineConfig({ + label: "Unit Tests", + files: 'out/src/test/**/*.test.js', + workspaceFolder: "./example/app", + mocha: { + ui: 'tdd', + timeout: 10000 + } +}) \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json index e0607e8..f104abc 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,5 +1,5 @@ { // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the extensions.json format - "recommendations": ["dbaeumer.vscode-eslint"] + "recommendations": ["dbaeumer.vscode-eslint", "ms-vscode.extension-test-runner"] } diff --git a/.vscode/launch.json b/.vscode/launch.json index 0a9fe4e..1b772f5 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,18 +10,31 @@ "type": "extensionHost", "request": "launch", "args": [ + "--disable-extensions", "--extensionDevelopmentPath=${workspaceFolder}", - "${workspaceFolder}/test/app" - ] + "${workspaceFolder}/example/app", + ], + "outFiles": [ + "${workspaceFolder}/out/**/*.js", + "!**/node_modules/**" + ], + "cwd": "${workspaceFolder}/example/app", + "preLaunchTask": "tasks: dev" }, { "name": "Extension Tests", "type": "extensionHost", "request": "launch", "args": [ + "--disable-extensions", "--extensionDevelopmentPath=${workspaceFolder}", - "--extensionTestsPath=${workspaceFolder}/test/suite/index" - ] + "--extensionTestsPath=${workspaceFolder}/out/src/test/suite/index", + "${workspaceFolder}/example/app", + ], + "testConfiguration": "${workspaceFolder}/.vscode-test.mjs", + "outFiles": ["${workspaceFolder}/out/test/**/*.js"], + "cwd": "${workspaceFolder}/example/app", + "preLaunchTask": "npm: watch-tests" } ] } diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..4cc3bbe --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,11 @@ +{ + "files.exclude": { + "out": false, // set this to true to hide the "out" folder with the compiled JS files + "dist": false // set this to true to hide the "dist" folder with the compiled JS files + }, + "search.exclude": { + "**/node_modules": true, // set this to false to include "node_modules" folder in search results + "out": true, // set this to false to include the "out" folder in search results + "dist": true // set this to false to include the "dist" folder in search results + } +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..c9dc1f0 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,67 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "npm", + "script": "build", + "problemMatcher": "$tsc", + "presentation": { + "reveal": "never" + }, + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "type": "npm", + "script": "dev", + "problemMatcher": "$tsc", + "presentation": { + "reveal": "never" + }, + "group": { + "kind": "build", + "isDefault": false + } + }, + { + "label": "tasks: dev", + "dependsOn": [ + "npm: dev" + ], + "problemMatcher": [] + }, + { + "type": "npm", + "script": "build:watch", + "problemMatcher": "$tsc-watch", + "presentation": { + "reveal": "never" + }, + "group": { + "kind": "build", + "isDefault": false + } + }, + { + "type": "npm", + "script": "watch-tests", + "problemMatcher": "$tsc-watch", + "isBackground": true, + "presentation": { + "reveal": "never", + "group": "watchers" + }, + "group": "build" + }, + { + "label": "tasks: watch-tests", + "dependsOn": [ + "npm: build:watch", + "npm: watch-tests" + ], + "problemMatcher": [] + } + ] +} \ No newline at end of file diff --git a/.vscodeignore b/.vscodeignore index d773361..b10336d 100644 --- a/.vscodeignore +++ b/.vscodeignore @@ -5,4 +5,17 @@ test/** .gitignore .yarnrc assets/videos -!node_modules/esbuild \ No newline at end of file +!node_modules/esbuild +**/*.js.map +scripts/** +out/** +.vscode-test.mjs +**/*.ts +**/tsconfig.* +**/eslint.config.* +example/** +src/** +utils/** +.gitattributes +jsconfig.json +.prettier* \ No newline at end of file diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 0000000..6ccd56e --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,49 @@ +/** + * ESLint configuration for the project. + * + * See https://eslint.style and https://typescript-eslint.io for additional linting options. + */ +// @ts-check +import js from '@eslint/js'; +import tseslint from 'typescript-eslint'; + +export default tseslint.config( + { + ignores: [ + "out", + "dist", + "scripts" + ] + }, + js.configs.recommended, + ...tseslint.configs.recommended, +); + + + +// { +// "env": { +// "browser": false, +// "commonjs": true, +// "es6": true, +// "node": true, +// "mocha": true +// }, +// "parserOptions": { +// "ecmaVersion": "latest", +// "ecmaFeatures": { +// "jsx": true +// }, +// "sourceType": "module" +// }, +// "ignorePatterns": ["lib", "app", "out"], +// "rules": { +// "no-const-assign": "warn", +// "no-this-before-super": "warn", +// "no-undef": "error", +// "no-unreachable": "warn", +// "no-unused-vars": "error", +// "constructor-super": "warn", +// "valid-typeof": "warn" +// } +// } diff --git a/package.json b/package.json index e877943..a2b5e6d 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "displayName": "Super Code Generator", "description": "A powerful, fast, and scalable code generator that saves you time", "publisher": "tenjojeremy", - "version": "3.31.0", + "version": "4.0.0", "engines": { "vscode": "^1.95.0" }, @@ -17,31 +17,31 @@ "vue", "template" ], - "main": "./out/index.js", - "types": "./out/src/index.d.ts", + "main": "./dist/index.js", + "types": "./dist/src/index.d.ts", "files": [ - "out" + "dist" ], "scripts": { - "dev": "npm run -S build -- --sourcemap --watch", - "build": "esbuild ./src/index.ts --bundle --outfile=out/index.js --external:vscode --external:esbuild --format=cjs --platform=node", - "lint": "eslint .", + "dev": "npm run -S build -- --sourcemap", + "build:watch": "npm run -S build -- --watch", + "build": "esbuild ./src/index.ts --bundle --outfile=dist/index.js --external:vscode --external:esbuild --format=cjs --platform=node", + "lint": "eslint", + "compile-tests": "tsc -p tsconfig.test.json", + "watch-tests": "tsc -p tsconfig.test.json -w", + "test": "vscode-test", "tests:ts-types": "tsc -p tsconfig.check.types.json", "types:generate": "tsc -p tsconfig.generate.types.json", - "pretest": "npm run lint", + "pretest": "npm run compile-tests", "prettify": "prettier --write '{**/*,*}.{js,jsx,json}'", "npm:publish": "node ./scripts/publishToNpm/publishToNpm.cjs", - "deploy": "npm run types:generate && npm run tests:ts-types && npm verison minor && vsce publish && npm run npm:publish" + "deploy": "npm run types:generate && npm run tests:ts-types && npm version minor && vsce publish && npm run npm:publish" }, "icon": "assets/images/logo.png", "repository": { "type": "git", "url": "https://github.com/jeremytenjo/super-code-generator" }, - "activationEvents": [ - "onCommand:superCodeGenerator.generateCode", - "onCommand:superCodeGenerator.generateCodeInFolder" - ], "contributes": { "configuration": { "title": "Super Code Generator", @@ -85,16 +85,20 @@ "prettier": "^2.3.0" }, "devDependencies": { - "@jeremytenjo/super-code-generator": "3.18.0", + "@eslint/js": "8.56.0", "@types/glob": "^7.1.3", - "@types/mocha": "^8.0.4", + "@types/mocha": "8.2.3", "@types/node": "^12.11.7", + "@types/prettier": "2.3.0", "@types/vscode": "^1.95.0", + "@vscode/test-cli": "0.0.10", + "@vscode/test-electron": "2.4.1", "eslint": "^8.56.0", "glob": "^7.1.7", - "mocha": "^8.2.1", + "mocha": "8.4.0", "typescript": "5.7.2", + "typescript-eslint": "7.2.0", "vsce": "2.15.0", "vscode-test": "^1.5.0" } -} \ No newline at end of file +} diff --git a/tsconfig.generate.types.json b/tsconfig.generate.types.json index 0282bf2..f40b55d 100644 --- a/tsconfig.generate.types.json +++ b/tsconfig.generate.types.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "outDir": "./out", + "outDir": "./dist", "declaration": true, "emitDeclarationOnly": true, "skipLibCheck": true, diff --git a/tsconfig.test.json b/tsconfig.test.json new file mode 100644 index 0000000..4b7b0e5 --- /dev/null +++ b/tsconfig.test.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es2020", + "lib": ["es2020"], + "outDir": "out", + "sourceMap": true, + "strict": true, + "skipLibCheck": true, + "esModuleInterop": true, + "rootDirs": ["src", "utils"], + }, + "exclude": ["node_modules", ".vscode-test", "example", "scripts"] +} \ No newline at end of file From 5a1061e2217d1e2d8f52434760af5c69c722a787 Mon Sep 17 00:00:00 2001 From: Max T Date: Thu, 30 Jan 2025 12:35:25 -0500 Subject: [PATCH 02/15] Renaming test to example --- {test => example}/app/.prettierrc.js | 0 {test => example}/app/.vscode/settings.json | 0 .../app/functions/src/functions.ts | 0 {test => example}/app/modal/modal.css | 0 {test => example}/app/modal/modal.jsx | 0 example/app/package.json | 14 +++++++++++++ {test => example}/app/superCodeGen.schema.ts | 21 +++++++++---------- 7 files changed, 24 insertions(+), 11 deletions(-) rename {test => example}/app/.prettierrc.js (100%) rename {test => example}/app/.vscode/settings.json (100%) rename {test => example}/app/functions/src/functions.ts (100%) rename {test => example}/app/modal/modal.css (100%) rename {test => example}/app/modal/modal.jsx (100%) create mode 100644 example/app/package.json rename {test => example}/app/superCodeGen.schema.ts (77%) diff --git a/test/app/.prettierrc.js b/example/app/.prettierrc.js similarity index 100% rename from test/app/.prettierrc.js rename to example/app/.prettierrc.js diff --git a/test/app/.vscode/settings.json b/example/app/.vscode/settings.json similarity index 100% rename from test/app/.vscode/settings.json rename to example/app/.vscode/settings.json diff --git a/test/app/functions/src/functions.ts b/example/app/functions/src/functions.ts similarity index 100% rename from test/app/functions/src/functions.ts rename to example/app/functions/src/functions.ts diff --git a/test/app/modal/modal.css b/example/app/modal/modal.css similarity index 100% rename from test/app/modal/modal.css rename to example/app/modal/modal.css diff --git a/test/app/modal/modal.jsx b/example/app/modal/modal.jsx similarity index 100% rename from test/app/modal/modal.jsx rename to example/app/modal/modal.jsx diff --git a/example/app/package.json b/example/app/package.json new file mode 100644 index 0000000..74466b2 --- /dev/null +++ b/example/app/package.json @@ -0,0 +1,14 @@ +{ + "name": "app", + "version": "1.0.0", + "description": "", + "main": ".prettierrc.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "@jeremytenjo/super-code-generator": "^3.31.0" + } +} diff --git a/test/app/superCodeGen.schema.ts b/example/app/superCodeGen.schema.ts similarity index 77% rename from test/app/superCodeGen.schema.ts rename to example/app/superCodeGen.schema.ts index 2949d40..324b08d 100644 --- a/test/app/superCodeGen.schema.ts +++ b/example/app/superCodeGen.schema.ts @@ -11,9 +11,8 @@ import type { const reactComponent: SuperCodeGeneratorTemplateSchema = { type: 'React Component', hooks: { - onCreate: async ({ outputPath }) => { - console.log(outputPath) - cp.exec(`cd ${outputPath} && touch file_name.txt`) + onCreate: async ({ outputPath, componentName }) => { + // do things here }, }, files: [ @@ -25,7 +24,7 @@ const reactComponent: SuperCodeGeneratorTemplateSchema = { export default function ${changeCase.pascalCase(name)}() { return ( -
+
${name}
); @@ -40,9 +39,8 @@ const reactComponent: SuperCodeGeneratorTemplateSchema = { } // Cloud function example -const functionsFolderPath = path.join(process.cwd(), 'functions') const cloudFunction = { - path: ({ name }) => path.join(functionsFolderPath, 'src', name, `${name}.ts`), + path: ({ name }) => path.join('functions', 'src', name, `${name}.ts`), template: ({ name, helpers }) => ` export default function ${helpers.changeCase.pascalCase(name)}() { return 'hello' @@ -53,20 +51,21 @@ const cloudFunctionTemplate: SuperCodeGeneratorTemplateSchema = { type: 'Cloud Function', files: [cloudFunction], hooks: { - onCreate: () => { - const functionsFile = path.join(functionsFolderPath, 'src', 'functions.ts') - fs.appendFileSync(functionsFile, 'data to append') + onCreate: ({outputPath, componentName}) => { + const functionsFile = path.join(outputPath, 'functions', 'src', 'functions.ts') + fs.appendFileSync(functionsFile, `export * as ${componentName} from "./${componentName}/${componentName}.js"\n`) }, }, options: { createNamedFolder: false, + outputInRootFolder: true, }, } // Story example const story: SuperCodeGeneratorTemplateSchema = { type: 'Story', - outputWithoutParentDir: true, + outputWithoutParentDir: false, files: [ { path: ({ name, helpers: { changeCase } }) => @@ -77,7 +76,7 @@ const story: SuperCodeGeneratorTemplateSchema = { export default function ${changeCase.pascalCase(name)}() { return ( -
+
${name}
); From a505399282b3050216f88ae557cb4d9a9103d68b Mon Sep 17 00:00:00 2001 From: Max T Date: Thu, 30 Jan 2025 12:35:52 -0500 Subject: [PATCH 03/15] Fixing to work on Windows --- src/commands/generateCodeCommand/index.ts | 4 +- .../handlers/genFolderSelectionList.ts | 6 +- .../handlers/useRecentSelectedPaths.ts | 10 +-- src/commands/generateCodeInFolder/index.ts | 8 +-- src/common/generateCode/handlers/create.ts | 19 ++--- .../handlers/importPrettierConfig.ts | 15 ++-- .../handlers/validateUserConfigFile.ts | 2 +- src/common/generateCode/index.ts | 72 ++++++++++++++----- src/index.ts | 9 +-- src/test/runTests.ts | 21 ++++++ src/test/suite/extension.test.ts | 15 ++++ src/test/suite/index.ts | 41 +++++++++++ utils/folderFiles/createFile.ts | 14 ++-- utils/folderFiles/createUri.ts | 10 +-- utils/folderFiles/doesFolderOrFileExist.ts | 2 +- utils/folderFiles/getActiveFileFolderPath.ts | 11 +-- utils/folderFiles/getActiveFilePath.ts | 2 +- utils/folderFiles/getFoldersInWorkspace.ts | 8 ++- utils/folderFiles/importFileInWorkspace.ts | 29 +++----- utils/folderFiles/isUriAFolder.ts | 5 +- utils/folderFiles/openFile.ts | 6 +- .../folderFiles/removeFirstCharacter/index.ts | 5 +- .../folderFiles/removeLastCharacter/index.ts | 5 +- utils/forwardSlash.ts | 5 -- .../getImportUserConfig.ts | 6 +- utils/isMac.ts | 3 - utils/log/assert.ts | 2 +- utils/log/logError.ts | 2 +- utils/openBrowserLink.ts | 2 +- utils/removeFromArray.ts | 15 ---- utils/splitPath.ts | 9 +-- utils/workspace/getWorkspacePath.ts | 42 ++++++++++- 32 files changed, 269 insertions(+), 136 deletions(-) create mode 100644 src/test/runTests.ts create mode 100644 src/test/suite/extension.test.ts create mode 100644 src/test/suite/index.ts delete mode 100644 utils/forwardSlash.ts delete mode 100644 utils/isMac.ts delete mode 100644 utils/removeFromArray.ts diff --git a/src/commands/generateCodeCommand/index.ts b/src/commands/generateCodeCommand/index.ts index 0acbe74..f344597 100644 --- a/src/commands/generateCodeCommand/index.ts +++ b/src/commands/generateCodeCommand/index.ts @@ -7,7 +7,7 @@ export default async function generateCodeCommand( ) { try { await generateCode({ outputPath: componentOutputPath }) - } catch (error) { - logError(error) + } catch (error: unknown) { + logError((error as Error).message) } } diff --git a/src/commands/generateCodeInFolder/handlers/genFolderSelectionList.ts b/src/commands/generateCodeInFolder/handlers/genFolderSelectionList.ts index c9dcd79..5a6657e 100644 --- a/src/commands/generateCodeInFolder/handlers/genFolderSelectionList.ts +++ b/src/commands/generateCodeInFolder/handlers/genFolderSelectionList.ts @@ -4,13 +4,13 @@ import getFoldersInWorkspace from '../../../../utils/folderFiles/getFoldersInWor import getWorkspacePath from '../../../../utils/workspace/getWorkspacePath' export default async function genFolderSelectionList() { - const workspacePath = await getWorkspacePath() + const workspacePath = getWorkspacePath() const workplaceFiles = await getFoldersInWorkspace() const folderSelectionList = workplaceFiles.map((wsFile) => ({ label: - wsFile.replace(workspacePath, '') === '/' + wsFile.replace(workspacePath.path, '') === '/' ? '/' - : removeFirstCharacter(removeLastCharacter(wsFile.replace(workspacePath, ''))), + : removeFirstCharacter(removeLastCharacter(wsFile.replace(workspacePath.path, ''))), path: wsFile, })) diff --git a/src/commands/generateCodeInFolder/handlers/useRecentSelectedPaths.ts b/src/commands/generateCodeInFolder/handlers/useRecentSelectedPaths.ts index 03edd33..d50bf6b 100644 --- a/src/commands/generateCodeInFolder/handlers/useRecentSelectedPaths.ts +++ b/src/commands/generateCodeInFolder/handlers/useRecentSelectedPaths.ts @@ -1,12 +1,14 @@ -export default function useRecentSelectedPaths(context) { +import type {ExtensionContext, QuickPickItem} from "vscode" + +export default function useRecentSelectedPaths(context: ExtensionContext) { // https://code.visualstudio.com/api/references/vscode-api#Memento - let recentSelectedPaths = context.workspaceState.get('recentSelectedPaths') || [] + let recentSelectedPaths = context.workspaceState.get('recentSelectedPaths') || [] return { - get() { + get(): QuickPickItem[] { return recentSelectedPaths }, - update(selectedFile) { + update(selectedFile: QuickPickItem): void { context.workspaceState.update('recentSelectedPaths', [ { ...selectedFile, detail: 'Recently Opened' }, ]) diff --git a/src/commands/generateCodeInFolder/index.ts b/src/commands/generateCodeInFolder/index.ts index 54eec9f..b9d1304 100644 --- a/src/commands/generateCodeInFolder/index.ts +++ b/src/commands/generateCodeInFolder/index.ts @@ -1,4 +1,4 @@ -import vscode from 'vscode' +import vscode, { ExtensionContext } from 'vscode' import logError from '../../../utils/log/logError' import generateCode from '../../common/generateCode' @@ -8,7 +8,7 @@ import useRecentSelectedPaths from './handlers/useRecentSelectedPaths' /** * User selects folder from a dropdown to put component in */ -export default async function generateCodeInFolder(context) { +export default async function generateCodeInFolder(context: ExtensionContext) { try { const folderSelectionList = await genFolderSelectionList() const recentSelectedPaths = useRecentSelectedPaths(context).get() @@ -28,7 +28,7 @@ export default async function generateCodeInFolder(context) { quickPick.title = 'Select folder to add component to' quickPick.placeholder = 'Type to filter' quickPick.show() - } catch (error) { - logError(error) + } catch (error: unknown) { + logError((error as Error).message) } } diff --git a/src/common/generateCode/handlers/create.ts b/src/common/generateCode/handlers/create.ts index 3b454ef..116e102 100644 --- a/src/common/generateCode/handlers/create.ts +++ b/src/common/generateCode/handlers/create.ts @@ -13,6 +13,7 @@ export default async function create(props: { helpers: SuperCodeGeneratorHelpersProps componentConfig: SuperCodeGeneratorConfigSchema[0] componentOutputPath: string + // eslint-disable-next-line @typescript-eslint/no-explicit-any prettierConfig: any }) { try { @@ -40,7 +41,7 @@ export default async function create(props: { type: props.componentConfig.type, } let parentFolderName = - file?.parentFolderName?.(fileProperties) || props.name || '' + file?.parentFolderName?.(fileProperties) || props.name || ''; // Format parentFolderName (optional) if (props.componentConfig?.options?.formatParentFolderName) { @@ -59,25 +60,27 @@ export default async function create(props: { outputPath: props.componentOutputPath, })?.newName } - + const outputPath = path.join( - !outputInRootFolder ? props.componentOutputPath : await getWorkspacePath(), + !outputInRootFolder ? props.componentOutputPath : getWorkspacePath().path, createNamedFolder ? parentFolderName : '', file.path(fileProperties), ) + const content = await prettifyFile({ content: file.template(fileProperties), prettierConfig: props.prettierConfig, }) - const doesExist = await doesFolderOrFileExist(outputPath) - - if (doesExist) logError(`${props.name} already exists`, { silent: true }) + if (doesFolderOrFileExist(outputPath)) logError(`${props.name} already exists`, { silent: true }) + await createFile(outputPath, content) if (openOnCreate) openFile(outputPath) + + }), ) - } catch (error) { - logError(error) + } catch (error: unknown) { + logError((error as Error).message) } } diff --git a/src/common/generateCode/handlers/importPrettierConfig.ts b/src/common/generateCode/handlers/importPrettierConfig.ts index cf903fa..7be4476 100644 --- a/src/common/generateCode/handlers/importPrettierConfig.ts +++ b/src/common/generateCode/handlers/importPrettierConfig.ts @@ -1,15 +1,20 @@ import getWorkspacePath from '../../../../utils/workspace/getWorkspacePath' -export default async function importPrettierConfig({ prettierConfigPath }) { - const workspacePath = await getWorkspacePath(prettierConfigPath) +interface importPrettierConfigProps { + prettierConfigPath: string +} + +export default async function importPrettierConfig({ prettierConfigPath }: importPrettierConfigProps) { + const workspacePath = getWorkspacePath(prettierConfigPath) let prettierConfig = false - const isJsFile = workspacePath.includes('.js') - if (isJsFile) { - prettierConfig = await import(workspacePath).then((p) => p.default) + if (workspacePath.hasExtension('.js')) { + prettierConfig = await import(workspacePath.getFileUri()).then((p) => p.default) } else { console.warn('Quick Component Create: Prettier config should be a JS file') } + console.log("prettier config loaded:", prettierConfig); + return prettierConfig } diff --git a/src/common/generateCode/handlers/validateUserConfigFile.ts b/src/common/generateCode/handlers/validateUserConfigFile.ts index 995ccdf..2e56622 100644 --- a/src/common/generateCode/handlers/validateUserConfigFile.ts +++ b/src/common/generateCode/handlers/validateUserConfigFile.ts @@ -1,4 +1,4 @@ -import { SuperCodeGeneratorConfigSchema } from '@jeremytenjo/super-code-generator' +import { SuperCodeGeneratorConfigSchema } from '../../..' import logError from '../../../../utils/log/logError' export default function validateUserConfigFile( diff --git a/src/common/generateCode/index.ts b/src/common/generateCode/index.ts index 73a0597..f68b613 100644 --- a/src/common/generateCode/index.ts +++ b/src/common/generateCode/index.ts @@ -6,11 +6,29 @@ import helpers from './handlers/helpers' import importPrettierConfig from './handlers/importPrettierConfig' import create from './handlers/create' import getImportUserConfig from '../../../utils/getImportUserConfig/getImportUserConfig' +import { platform } from 'process' +import splitPath, { StartsWithSlashRegex } from '../../../utils/splitPath' +import removeFirstCharacter from '../../../utils/folderFiles/removeFirstCharacter' -export default async function generateCode({ outputPath }) { - const { userConfig, configFile } = await getImportUserConfig() +interface generateCodeProps { + outputPath: string; +} + +export default async function generateCode({outputPath}: generateCodeProps) { + // Get the user config and schema config + const importedUsrCfg = await getImportUserConfig() + + // If the config file is not found, show an error message + if(importedUsrCfg === undefined) { + vscode.window.showErrorMessage('Schema config file not found.') + return null; + } - const optionsList = configFile.map((property, index) => { + // Destructure the user config and schema config + const { userConfig, configFile } = importedUsrCfg! + + // Make a list of the options from the schema + const optionsList = configFile.map((property: {type?: string}, index: number) => { if (!property.type) { logError(`Missing type property in config file array object index ${index}`) } @@ -18,19 +36,25 @@ export default async function generateCode({ outputPath }) { return { label: property.type } }) + // Import the prettier config const prettierConfig = await importPrettierConfig({ prettierConfigPath: userConfig.prettierConfigFilePath, }) - + + // Create a quick pick to select the component type const quickPick = vscode.window.createQuickPick() - quickPick.items = optionsList + quickPick.items = (optionsList as readonly vscode.QuickPickItem[]) + + // Add a handler for selection change event quickPick.onDidChangeSelection(async (selection) => { const [selectedComponentType] = selection + // Find the selected component's config from the schema const selectedComponentTypeConfig = configFile.find( - ({ type }) => type === selectedComponentType.label, + ({ type }: {type: string}) => type === selectedComponentType.label, ) + // Prompt the user for the name of the component const componentName = await vscode.window.showInputBox({ value: '', title: `${selectedComponentType.label} Name`, @@ -42,40 +66,56 @@ export default async function generateCode({ outputPath }) { prompt: selectedComponentTypeConfig?.usageInstructions, }) + // If the user cancels the input box, return null if (!componentName) return null + // Split the component names by commas const componentNames = componentName.split(',') + // If the user is on Windows, remove the first character of the output path if it starts with a slash + outputPath = platform == "win32" && StartsWithSlashRegex.test(outputPath) ? removeFirstCharacter(outputPath) : outputPath; + + // create the components try { await Promise.all( componentNames.map(async (componentName) => { - const componentNameTrimmed = componentName.trim() - const folderName = path.join(outputPath, componentNameTrimmed) - let componentOutputPath = outputPath + const componentNameTrimmed = componentName.trim(); + let componentOutputPath: string[] + if(!selectedComponentTypeConfig) { + logError(`No config found for ${selectedComponentType.label}`) + return null; + } if (selectedComponentTypeConfig.outputWithoutParentDir) { - componentOutputPath = componentOutputPath.split('/') + componentOutputPath = splitPath(outputPath) componentOutputPath.pop() - componentOutputPath = componentOutputPath.join('/') + const tmpOutputPath = componentOutputPath.join(path.sep) + const relativePath = path.relative(tmpOutputPath, outputPath); + if (relativePath.startsWith('..') && path.isAbsolute(relativePath)) { + outputPath = tmpOutputPath + } } + await create({ name: componentNameTrimmed, helpers, + // eslint-disable-next-line @typescript-eslint/no-explicit-any componentConfig: selectedComponentTypeConfig as any, - componentOutputPath, + componentOutputPath: outputPath, prettierConfig, }) - + if (selectedComponentTypeConfig?.hooks?.onCreate) { - await selectedComponentTypeConfig?.hooks?.onCreate({ outputPath: folderName }) + await selectedComponentTypeConfig?.hooks?.onCreate({ outputPath: outputPath, componentName: componentNameTrimmed }) } + }), ) vscode.window.showInformationMessage(`${componentName} created!`) - } catch (error) { - logError(error) + } catch (error: unknown) { + logError((error as Error).message) } finally { quickPick.dispose() } diff --git a/src/index.ts b/src/index.ts index a7eae32..928a822 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,7 +13,7 @@ export type SuperCodeGeneratorConfigSchema = { outputWithoutParentDir?: boolean usageInstructions?: string hooks?: { - onCreate: (props: { outputPath: string }) => void | Promise + onCreate: (props: { outputPath: string, componentName: string }) => void | Promise } options?: { createNamedFolder?: boolean @@ -52,13 +52,15 @@ const extensionName = 'superCodeGenerator' * @param {vscode.ExtensionContext} context * {@Link https://code.visualstudio.com/api/references/vscode-api#ExtensionContext|ExtensionContext API} */ -function activate(context) { +export function activate(context: vscode.ExtensionContext) { console.log(`${extensionName} activated!`) + // Register the generateCode command context.subscriptions.push( vscode.commands.registerCommand('superCodeGenerator.generateCode', generateCode), ) + // Register the generateCodeInFolder command context.subscriptions.push( vscode.commands.registerCommand('superCodeGenerator.generateCodeInFolder', () => generateCodeInFolder(context), @@ -67,8 +69,7 @@ function activate(context) { } // this method is called when your extension is deactivated -function deactivate() { +export function deactivate() { console.log(`${extensionName} deactivated!`) } -export { activate, deactivate } diff --git a/src/test/runTests.ts b/src/test/runTests.ts new file mode 100644 index 0000000..19e9b56 --- /dev/null +++ b/src/test/runTests.ts @@ -0,0 +1,21 @@ +import path from "path"; + +import { runTests } from "@vscode/test-electron"; + +async function main() { + try { + // The folder containing the Extension Manifest package.json + const extensionDevelopmentPath = path.resolve(__dirname, '../../'); + + // The path to the extension test script + const extensionTestsPath = path.resolve(__dirname, './suite/index'); + + // Download VS Code, unzip it and run the integration test + await runTests({ extensionDevelopmentPath, extensionTestsPath }); + } catch { + console.error("Failed to run tests"); + process.exit(1); + } +} + +main(); \ No newline at end of file diff --git a/src/test/suite/extension.test.ts b/src/test/suite/extension.test.ts new file mode 100644 index 0000000..e02d503 --- /dev/null +++ b/src/test/suite/extension.test.ts @@ -0,0 +1,15 @@ +//import * as assert from "assert"; + +import * as vscode from "vscode"; + + +suite("Extension Test Suite", () => { + + suiteTeardown(() => { + vscode.window.showInformationMessage("All tests done!"); + }) + + + + +}); \ No newline at end of file diff --git a/src/test/suite/index.ts b/src/test/suite/index.ts new file mode 100644 index 0000000..daac62b --- /dev/null +++ b/src/test/suite/index.ts @@ -0,0 +1,41 @@ +import path from 'path'; +import Mocha from 'mocha'; +import glob from 'glob'; +import vscode from 'vscode'; + +export function run(): Promise { + const outputChan = vscode.window.createOutputChannel("Test Suite"); + // Create the mocha test + const mocha = new Mocha({ + ui: 'tdd' + }); + + const testsRoot = path.resolve(__dirname, '..'); + + return new Promise((c, e) => { + glob('**/**.test.js', { cwd: testsRoot }, (err, files) => { + if(err) { + return e(err); + } + + files.forEach(f => { + const testFilePath = path.resolve(testsRoot, f); + outputChan.appendLine(`Adding test file: ${testFilePath}`); + mocha.addFile(testFilePath); + }); + + try { + mocha.run(failures => { + if(failures > 0) { + e(new Error(`${failures} tests failed.`)); + } else { + c(); + } + }); + } catch (err) { + console.error(err); + e(err); + } + }); + }); +} \ No newline at end of file diff --git a/utils/folderFiles/createFile.ts b/utils/folderFiles/createFile.ts index ae8fd46..e39e908 100644 --- a/utils/folderFiles/createFile.ts +++ b/utils/folderFiles/createFile.ts @@ -2,14 +2,18 @@ import vscode from 'vscode' import doesFolderOrFileExist from './doesFolderOrFileExist' import createUri from './createUri' import logError from '../log/logError' +import { platform } from 'process' +import { StartsWithSlashRegex } from '../splitPath' +import removeFirstCharacter from './removeFirstCharacter' -export default async function createFile(outputPath, content) { +export default async function createFile(outputPath: string, content: string) { const writeData = Buffer.from(content, 'utf8') + if(platform == "win32" && StartsWithSlashRegex.test(outputPath)) { + outputPath = removeFirstCharacter(outputPath) + } const folderUri = createUri(outputPath) - const doesExist = await doesFolderOrFileExist(outputPath) + if (doesFolderOrFileExist(outputPath)) logError(`${outputPath} already exists`) - if (doesExist) logError(`${outputPath} already exitsts`) - - await vscode.workspace.fs.writeFile(folderUri, writeData) + await vscode.workspace.fs.writeFile(folderUri, writeData); } diff --git a/utils/folderFiles/createUri.ts b/utils/folderFiles/createUri.ts index 58ec17c..5bfb765 100644 --- a/utils/folderFiles/createUri.ts +++ b/utils/folderFiles/createUri.ts @@ -1,10 +1,6 @@ +import { pathToFileURL } from 'url'; import vscode from 'vscode' -export default function createUri(uri) { - const folderUri = vscode.workspace.workspaceFolders[0].uri - const fileUri = folderUri.with({ - path: uri, - }) - - return fileUri +export default function createUri(uri: string) { + return vscode.Uri.parse(pathToFileURL(uri).toString()); } diff --git a/utils/folderFiles/doesFolderOrFileExist.ts b/utils/folderFiles/doesFolderOrFileExist.ts index 7a88ea4..10aa9bf 100644 --- a/utils/folderFiles/doesFolderOrFileExist.ts +++ b/utils/folderFiles/doesFolderOrFileExist.ts @@ -4,6 +4,6 @@ import fs from 'fs' * @example * doesFolderOrFileExist(dir) */ -export default function doesFolderOrFileExist(path) { +export default function doesFolderOrFileExist(path: string) { return fs.existsSync(path) } diff --git a/utils/folderFiles/getActiveFileFolderPath.ts b/utils/folderFiles/getActiveFileFolderPath.ts index 66b816e..62195f7 100644 --- a/utils/folderFiles/getActiveFileFolderPath.ts +++ b/utils/folderFiles/getActiveFileFolderPath.ts @@ -1,15 +1,16 @@ import getActiveFilePath from './getActiveFilePath' import splitPath from '../splitPath' +import { sep } from 'path' /** * Get the folder path of the currently open and active vscode file */ -export default function getActiveFileFolderPath() { +export default function getActiveFileFolderPath(): string { const activeFilePath = getActiveFilePath() - let activeFileFolder = splitPath(activeFilePath) - + // split the path into an array + const activeFileFolder: string[] = splitPath(activeFilePath) + // remove the last element activeFileFolder.pop() - activeFileFolder = activeFileFolder.join('/') - return activeFileFolder + return activeFileFolder.join(sep) } diff --git a/utils/folderFiles/getActiveFilePath.ts b/utils/folderFiles/getActiveFilePath.ts index b380574..6909e2c 100644 --- a/utils/folderFiles/getActiveFilePath.ts +++ b/utils/folderFiles/getActiveFilePath.ts @@ -1,5 +1,5 @@ import vscode from 'vscode' export default function getActiveFilePath() { - return vscode.window.activeTextEditor.document.uri.fsPath + return vscode.window.activeTextEditor!.document.uri.fsPath; } diff --git a/utils/folderFiles/getFoldersInWorkspace.ts b/utils/folderFiles/getFoldersInWorkspace.ts index 100db55..33ef47a 100644 --- a/utils/folderFiles/getFoldersInWorkspace.ts +++ b/utils/folderFiles/getFoldersInWorkspace.ts @@ -2,10 +2,14 @@ import { glob } from 'glob' import getWorkspacePath from '../workspace/getWorkspacePath' export default async function getFoldersInWorkspace() { - const workspacePath = await getWorkspacePath() - const foldersInWorkspace = await glob.sync(workspacePath + '/**/', { + // get the path of the workspace + const workspacePath = getWorkspacePath().path + + // get all the folders in the workspace, excluding node_modules + const foldersInWorkspace = glob.sync(workspacePath + '/**/', { ignore: ['**/node_modules/**', './node_modules/**'], }) + // return the folders in the workspace return foldersInWorkspace } diff --git a/utils/folderFiles/importFileInWorkspace.ts b/utils/folderFiles/importFileInWorkspace.ts index 6d148d5..555c042 100644 --- a/utils/folderFiles/importFileInWorkspace.ts +++ b/utils/folderFiles/importFileInWorkspace.ts @@ -1,28 +1,17 @@ -import vscode from 'vscode' -import path from 'path' import doesFileExist from './doesFolderOrFileExist' import assert from '../log/assert' import importTs from '../importTsFile/importTsFile' +import getWorkspacePath from '../workspace/getWorkspacePath' -export default async function importFileInWorkspace(uri) { - let uriPath = path.join(vscode.workspace.workspaceFolders[0].uri.path, uri) - const uriPathExists = doesFileExist(uriPath) +export default async function importFileInWorkspace(uri: string) { + // get the path of the file + const uriPath = getWorkspacePath(uri); + // check if the file exists + const uriPathExists = doesFileExist(uriPath.path); + // assert that the file exists assert(uriPathExists, `Schema not found at ${uriPath}`) - if (uriPath.startsWith('\\')) { - uriPath = uriPath.slice(0) - } - - if (uriPath.includes('.ts')) { - const fileData = await importTs({ - filePath: uriPath, - }) - - return fileData - } else { - const fileData = require(uriPath) - - return fileData - } + // return the file imported/required + return uriPath.hasExtension('.ts') ? await importTs({filePath: uriPath.path}) : require(uriPath.path) } diff --git a/utils/folderFiles/isUriAFolder.ts b/utils/folderFiles/isUriAFolder.ts index feecef4..8195367 100644 --- a/utils/folderFiles/isUriAFolder.ts +++ b/utils/folderFiles/isUriAFolder.ts @@ -1,8 +1,7 @@ import vscode from 'vscode' -export default async function isUriAFolder(uri) { +export default async function isUriAFolder(uri: vscode.Uri) { const itemStats = await vscode.workspace.fs.stat(uri) - const isFolder = itemStats.type === 2 - return isFolder + return itemStats.type === vscode.FileType.Directory } diff --git a/utils/folderFiles/openFile.ts b/utils/folderFiles/openFile.ts index 75a4364..8aea5c3 100644 --- a/utils/folderFiles/openFile.ts +++ b/utils/folderFiles/openFile.ts @@ -2,7 +2,7 @@ import vscode from 'vscode' import createUri from './createUri' -export default function openFile(filePath) { - const folderUri = createUri(filePath) - vscode.window.showTextDocument(folderUri) +export default async function openFile(filePath: string) { + // to open a file in vscode, we need to get the uri of the file, then open it + vscode.window.showTextDocument(await vscode.workspace.openTextDocument(createUri(filePath))) } diff --git a/utils/folderFiles/removeFirstCharacter/index.ts b/utils/folderFiles/removeFirstCharacter/index.ts index 5f61ef8..956df86 100644 --- a/utils/folderFiles/removeFirstCharacter/index.ts +++ b/utils/folderFiles/removeFirstCharacter/index.ts @@ -1,4 +1,3 @@ -export default function removeFirstCharacter(string) { - const firstCharacterRemoved = string.substring(1) - return firstCharacterRemoved +export default function removeFirstCharacter(str: string) { + return str.slice(1) } diff --git a/utils/folderFiles/removeLastCharacter/index.ts b/utils/folderFiles/removeLastCharacter/index.ts index 9694c19..7191478 100644 --- a/utils/folderFiles/removeLastCharacter/index.ts +++ b/utils/folderFiles/removeLastCharacter/index.ts @@ -1,4 +1,3 @@ -export default function removeLastCharacter(string) { - const lastCharacterRemoved = string.slice(0, -1) - return lastCharacterRemoved +export default function removeLastCharacter(str: string) { + return str.slice(0, -1) } diff --git a/utils/forwardSlash.ts b/utils/forwardSlash.ts deleted file mode 100644 index 880ca7d..0000000 --- a/utils/forwardSlash.ts +++ /dev/null @@ -1,5 +0,0 @@ -import isMac from './isMac' - -const splitValue = isMac() ? '/' : '\\' - -export default splitValue diff --git a/utils/getImportUserConfig/getImportUserConfig.ts b/utils/getImportUserConfig/getImportUserConfig.ts index 3e38ef1..67d7b9a 100644 --- a/utils/getImportUserConfig/getImportUserConfig.ts +++ b/utils/getImportUserConfig/getImportUserConfig.ts @@ -1,14 +1,14 @@ import vscode from 'vscode' import validateUserConfigFile from '../../src/common/generateCode/handlers/validateUserConfigFile' import importFileInWorkspace from '../folderFiles/importFileInWorkspace' -import { SuperCodeGeneratorConfigSchema } from '@jeremytenjo/super-code-generator' -import { SuperCodeGeneratorUserConfigSchema } from '../../src' +import { SuperCodeGeneratorConfigSchema, SuperCodeGeneratorUserConfigSchema } from '../../src' import logError from '../log/logError' export default async function getImportUserConfig() { const userConfig: SuperCodeGeneratorUserConfigSchema = + // eslint-disable-next-line @typescript-eslint/no-explicit-any vscode.workspace.getConfiguration('superCodeGenerator') as any - + const configFile = (await importFileInWorkspace(userConfig.schemaFilePath).then( (res) => res.default, )) as SuperCodeGeneratorConfigSchema diff --git a/utils/isMac.ts b/utils/isMac.ts deleted file mode 100644 index fe49a28..0000000 --- a/utils/isMac.ts +++ /dev/null @@ -1,3 +0,0 @@ -import os from 'os' - -export default () => os.type() === 'Darwin' diff --git a/utils/log/assert.ts b/utils/log/assert.ts index c9cb7e7..ca9c50e 100644 --- a/utils/log/assert.ts +++ b/utils/log/assert.ts @@ -1,6 +1,6 @@ import logError from './logError' -export default function assert(assertion, message) { +export default function assert(assertion: boolean, message: string) { if (!assertion) { return logError(message) } diff --git a/utils/log/logError.ts b/utils/log/logError.ts index 755d539..a1b1f03 100644 --- a/utils/log/logError.ts +++ b/utils/log/logError.ts @@ -1,6 +1,6 @@ import vscode from 'vscode' -export default function logError(errorMessage, options = { silent: false }) { +export default function logError(errorMessage: string, options = { silent: false }) { if (options.silent) { throw new Error(errorMessage) } else { diff --git a/utils/openBrowserLink.ts b/utils/openBrowserLink.ts index 0012caa..8cf836f 100644 --- a/utils/openBrowserLink.ts +++ b/utils/openBrowserLink.ts @@ -1,5 +1,5 @@ import vscode from 'vscode' -export default function openBrowserLink(url) { +export default function openBrowserLink(url: string) { vscode.env.openExternal(vscode.Uri.parse(url)) } diff --git a/utils/removeFromArray.ts b/utils/removeFromArray.ts deleted file mode 100644 index 68b7721..0000000 --- a/utils/removeFromArray.ts +++ /dev/null @@ -1,15 +0,0 @@ -export default function removeFromArray( - string, - word, - options = { - split: '/', - join: '', - }, -) { - const index = string.split('/').findIndex((i) => i === word) - - return string - .split(options.split) - .slice(index + 1) - .join(options.join) -} diff --git a/utils/splitPath.ts b/utils/splitPath.ts index 7880c1c..9f2c8c0 100644 --- a/utils/splitPath.ts +++ b/utils/splitPath.ts @@ -1,12 +1,13 @@ -import forwardSlash from './forwardSlash' +export const StartsWithSlashRegex = /^[\\/]/; /** - * Supports Mac and Windows + * Supports all operating systems * @example * splitPath('/project/heoo') * * returns ['project', 'heoo'] */ -export default function splitPath(path) { - return path.toString().split(forwardSlash) +export default function splitPath(path: string): string[] { + // Split by any type of slash + return path.toString().split(/[\\/]/) } diff --git a/utils/workspace/getWorkspacePath.ts b/utils/workspace/getWorkspacePath.ts index 800c907..4c1ed85 100644 --- a/utils/workspace/getWorkspacePath.ts +++ b/utils/workspace/getWorkspacePath.ts @@ -1,7 +1,43 @@ import vscode from 'vscode' import path from 'path' +import { platform } from 'process'; +import { StartsWithSlashRegex } from '../splitPath'; +import removeFirstCharacter from '../folderFiles/removeFirstCharacter'; -export default async function getWorkspacePath(add = '') { - const folderUri = vscode.workspace.workspaceFolders[0].uri - return path.join(folderUri.path, add) +interface FilePath { + path: string; + getFileUri(): string; + getExtension(): string; + hasExtension(ext: string): boolean; + addFile(dir: string): void; +} + +export default function getWorkspacePath(add = ''): FilePath { + // Get the workspace folder uri + const folderUri = vscode.workspace.workspaceFolders![0].uri + + // add the path to the workspace folder + let filePath = path.join(folderUri.path, add); + + // If the platform is windows and the path starts with a slash, remove the slash + if(platform == "win32" && StartsWithSlashRegex.test(filePath)) { + filePath = removeFirstCharacter(filePath) + } + + // Return the object + return { + path: filePath, + getFileUri() { + return `file:${path.sep.repeat(2)}${filePath}` + }, + getExtension(): string { + return path.extname(filePath) + }, + hasExtension(ext) { + return this.getExtension() === ext + }, + addFile(dir) { + this.path = path.join(this.path, dir) + }, + } } From be39e789b32341aaf0b70277758230056fe4b399 Mon Sep 17 00:00:00 2001 From: Max T Date: Thu, 30 Jan 2025 12:39:45 -0500 Subject: [PATCH 04/15] Changing package name --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a2b5e6d..8145060 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@jeremytenjo/super-code-generator", + "name": "super-code-generator", "displayName": "Super Code Generator", "description": "A powerful, fast, and scalable code generator that saves you time", "publisher": "tenjojeremy", From dba6a4b17abe443500c3a8072aea1a2bbca1d8ee Mon Sep 17 00:00:00 2001 From: Max T Date: Thu, 30 Jan 2025 12:43:23 -0500 Subject: [PATCH 05/15] Removing debug logs --- src/common/generateCode/handlers/importPrettierConfig.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/common/generateCode/handlers/importPrettierConfig.ts b/src/common/generateCode/handlers/importPrettierConfig.ts index 7be4476..ef1d877 100644 --- a/src/common/generateCode/handlers/importPrettierConfig.ts +++ b/src/common/generateCode/handlers/importPrettierConfig.ts @@ -14,7 +14,6 @@ export default async function importPrettierConfig({ prettierConfigPath }: impor console.warn('Quick Component Create: Prettier config should be a JS file') } - console.log("prettier config loaded:", prettierConfig); return prettierConfig } From 3fb6e7e1ecf6e7af03be61e8ae5e2836f81c4a30 Mon Sep 17 00:00:00 2001 From: Max T Date: Thu, 30 Jan 2025 12:44:08 -0500 Subject: [PATCH 06/15] Adding changes made by Jeremy --- .github/copilot-instructions.md | 15 +++++++++++++++ utils/folderFiles/importFileInWorkspace.ts | 8 +++++++- utils/getImportUserConfig/getImportUserConfig.ts | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 .github/copilot-instructions.md diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md new file mode 100644 index 0000000..1a41b22 --- /dev/null +++ b/.github/copilot-instructions.md @@ -0,0 +1,15 @@ +Start of javascript and typescript files instructions +- Always use objects as a functions arguments named props +- Format the Props type as `${functionName}Props`, make sure the name is pascal case +- Always export the props type +- Do not spread the props object in the function +Use the following structure when creating a function +``` +export type ${propsName} = {name: string} + export default async function ${camelCase}(props: ${propsName}) { + const data = props.name + return { data } + } + export type ${returnName} = ReturnType +``` +End of javascript and typescript files instructions \ No newline at end of file diff --git a/utils/folderFiles/importFileInWorkspace.ts b/utils/folderFiles/importFileInWorkspace.ts index 555c042..87165a4 100644 --- a/utils/folderFiles/importFileInWorkspace.ts +++ b/utils/folderFiles/importFileInWorkspace.ts @@ -3,7 +3,11 @@ import assert from '../log/assert' import importTs from '../importTsFile/importTsFile' import getWorkspacePath from '../workspace/getWorkspacePath' -export default async function importFileInWorkspace(uri: string) { +export type importFileInWorkspaceProps = { + uri: string; +} + +export default async function importFileInWorkspace({uri}: importFileInWorkspaceProps) { // get the path of the file const uriPath = getWorkspacePath(uri); // check if the file exists @@ -15,3 +19,5 @@ export default async function importFileInWorkspace(uri: string) { // return the file imported/required return uriPath.hasExtension('.ts') ? await importTs({filePath: uriPath.path}) : require(uriPath.path) } + +export type ImportFileInWorkspaceReturn = ReturnType \ No newline at end of file diff --git a/utils/getImportUserConfig/getImportUserConfig.ts b/utils/getImportUserConfig/getImportUserConfig.ts index 67d7b9a..6d5dc50 100644 --- a/utils/getImportUserConfig/getImportUserConfig.ts +++ b/utils/getImportUserConfig/getImportUserConfig.ts @@ -9,7 +9,7 @@ export default async function getImportUserConfig() { // eslint-disable-next-line @typescript-eslint/no-explicit-any vscode.workspace.getConfiguration('superCodeGenerator') as any - const configFile = (await importFileInWorkspace(userConfig.schemaFilePath).then( + const configFile = (await importFileInWorkspace({uri: userConfig.schemaFilePath}).then( (res) => res.default, )) as SuperCodeGeneratorConfigSchema From 9ddf42fc4b76309e74d2fe2a6e4e2d7e888fefcf Mon Sep 17 00:00:00 2001 From: Max T Date: Thu, 30 Jan 2025 13:47:47 -0500 Subject: [PATCH 07/15] Adding Testing on all OSes by Github --- .github/workflows/tests.yml | 31 +++++++++++++++++++++++++++++++ .vscode-test.mjs | 3 ++- src/test/suite/extension.test.ts | 4 +--- 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..52f102d --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,31 @@ +name: "Test Extension" +on: [push, pull_request] + +jobs: + build: + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macOS-latest] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Install Node.js + uses: actions/setup-node@v2 + with: + node-version: '18.17.1' + - run: npm install + - name: Install APT libraries + if: runner.os == 'Linux' + run: | + sudo apt-get update + sudo apt-get install -y build-essential xvfb clang libdbus-1-dev libgtk-3-dev \ + libnotify-dev libasound2-dev libcap-dev \ + libcups2-dev libxtst-dev \ + libxss1 libnss3-dev gcc-multilib g++-multilib curl \ + gperf bison python3-dbusmock openjdk-8-jre + - run: xvfb-run -a npm test + if: runner.os == 'Linux' + - run: npm test + if: runner.os != 'Linux' + \ No newline at end of file diff --git a/.vscode-test.mjs b/.vscode-test.mjs index 2e005f8..d4f7a2f 100644 --- a/.vscode-test.mjs +++ b/.vscode-test.mjs @@ -7,5 +7,6 @@ export default defineConfig({ mocha: { ui: 'tdd', timeout: 10000 - } + }, + launchArgs: ["--disable-extensions"] }) \ No newline at end of file diff --git a/src/test/suite/extension.test.ts b/src/test/suite/extension.test.ts index e02d503..f61e92b 100644 --- a/src/test/suite/extension.test.ts +++ b/src/test/suite/extension.test.ts @@ -1,5 +1,3 @@ -//import * as assert from "assert"; - import * as vscode from "vscode"; @@ -9,7 +7,7 @@ suite("Extension Test Suite", () => { vscode.window.showInformationMessage("All tests done!"); }) - + // TODO: Add tests }); \ No newline at end of file From 842f86e31cd6e066adbc8269ccedf2e31d58cb1d Mon Sep 17 00:00:00 2001 From: Max T Date: Thu, 30 Jan 2025 16:34:15 -0500 Subject: [PATCH 08/15] Changing wording of a comment --- src/test/suite/extension.test.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/test/suite/extension.test.ts b/src/test/suite/extension.test.ts index f61e92b..995a844 100644 --- a/src/test/suite/extension.test.ts +++ b/src/test/suite/extension.test.ts @@ -1,13 +1,11 @@ import * as vscode from "vscode"; - suite("Extension Test Suite", () => { suiteTeardown(() => { vscode.window.showInformationMessage("All tests done!"); }) - // TODO: Add tests - + // TODO: Write tests }); \ No newline at end of file From 483fffe87e65f144e44820d99976e882afb84516 Mon Sep 17 00:00:00 2001 From: Max T Date: Thu, 30 Jan 2025 17:48:32 -0500 Subject: [PATCH 09/15] Changing all interfaces to types for consistency --- src/common/generateCode/handlers/importPrettierConfig.ts | 2 +- src/common/generateCode/index.ts | 2 +- utils/workspace/getWorkspacePath.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common/generateCode/handlers/importPrettierConfig.ts b/src/common/generateCode/handlers/importPrettierConfig.ts index ef1d877..524ca99 100644 --- a/src/common/generateCode/handlers/importPrettierConfig.ts +++ b/src/common/generateCode/handlers/importPrettierConfig.ts @@ -1,6 +1,6 @@ import getWorkspacePath from '../../../../utils/workspace/getWorkspacePath' -interface importPrettierConfigProps { +export type importPrettierConfigProps = { prettierConfigPath: string } diff --git a/src/common/generateCode/index.ts b/src/common/generateCode/index.ts index f68b613..a6ef1c1 100644 --- a/src/common/generateCode/index.ts +++ b/src/common/generateCode/index.ts @@ -10,7 +10,7 @@ import { platform } from 'process' import splitPath, { StartsWithSlashRegex } from '../../../utils/splitPath' import removeFirstCharacter from '../../../utils/folderFiles/removeFirstCharacter' -interface generateCodeProps { +export type generateCodeProps = { outputPath: string; } diff --git a/utils/workspace/getWorkspacePath.ts b/utils/workspace/getWorkspacePath.ts index 4c1ed85..6e9fe7c 100644 --- a/utils/workspace/getWorkspacePath.ts +++ b/utils/workspace/getWorkspacePath.ts @@ -4,7 +4,7 @@ import { platform } from 'process'; import { StartsWithSlashRegex } from '../splitPath'; import removeFirstCharacter from '../folderFiles/removeFirstCharacter'; -interface FilePath { +export type FilePath = { path: string; getFileUri(): string; getExtension(): string; From f73c46f08ee9144f893bbfa8b89e34ca0adc6147 Mon Sep 17 00:00:00 2001 From: Jeremy Tenjo Date: Thu, 30 Jan 2025 18:45:08 -0500 Subject: [PATCH 10/15] 4.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8145060..0e3a0f7 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "displayName": "Super Code Generator", "description": "A powerful, fast, and scalable code generator that saves you time", "publisher": "tenjojeremy", - "version": "4.0.0", + "version": "4.1.0", "engines": { "vscode": "^1.95.0" }, From e7e692fe05f4e9e0e3a80f23f190e554eec16ba9 Mon Sep 17 00:00:00 2001 From: Jeremy Tenjo Date: Thu, 30 Jan 2025 18:46:56 -0500 Subject: [PATCH 11/15] activationEvents are required to publish even though it shows a warning in the package.json --- package.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/package.json b/package.json index 0e3a0f7..a2a52cc 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,10 @@ "type": "git", "url": "https://github.com/jeremytenjo/super-code-generator" }, + "activationEvents": [ + "onCommand:superCodeGenerator.generateCode", + "onCommand:superCodeGenerator.generateCodeInFolder" + ], "contributes": { "configuration": { "title": "Super Code Generator", From 6e5ba10fab294fb39255dacd717430b8c4ebf30d Mon Sep 17 00:00:00 2001 From: Jeremy Tenjo Date: Thu, 30 Jan 2025 18:47:00 -0500 Subject: [PATCH 12/15] 4.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a2a52cc..b910860 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "displayName": "Super Code Generator", "description": "A powerful, fast, and scalable code generator that saves you time", "publisher": "tenjojeremy", - "version": "4.1.0", + "version": "4.2.0", "engines": { "vscode": "^1.95.0" }, From 24094c733a367650a729657a7a8cb57c53bf11ae Mon Sep 17 00:00:00 2001 From: Jeremy Tenjo Date: Thu, 30 Jan 2025 18:47:32 -0500 Subject: [PATCH 13/15] 4.3.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b910860..a723600 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "displayName": "Super Code Generator", "description": "A powerful, fast, and scalable code generator that saves you time", "publisher": "tenjojeremy", - "version": "4.2.0", + "version": "4.3.0", "engines": { "vscode": "^1.95.0" }, From b8d995b5f2fa27913c8acd8e50ec5e1bc6d54794 Mon Sep 17 00:00:00 2001 From: Jeremy Tenjo Date: Thu, 30 Jan 2025 18:48:09 -0500 Subject: [PATCH 14/15] Refactor VSCode configuration files for improved formatting and consistency --- .vscode/launch.json | 9 +-- .vscode/settings.json | 20 +++---- .vscode/tasks.json | 127 ++++++++++++++++++++---------------------- package.json | 2 +- 4 files changed, 75 insertions(+), 83 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 1b772f5..c5f5208 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -12,12 +12,9 @@ "args": [ "--disable-extensions", "--extensionDevelopmentPath=${workspaceFolder}", - "${workspaceFolder}/example/app", - ], - "outFiles": [ - "${workspaceFolder}/out/**/*.js", - "!**/node_modules/**" + "${workspaceFolder}/example/app" ], + "outFiles": ["${workspaceFolder}/out/**/*.js", "!**/node_modules/**"], "cwd": "${workspaceFolder}/example/app", "preLaunchTask": "tasks: dev" }, @@ -29,7 +26,7 @@ "--disable-extensions", "--extensionDevelopmentPath=${workspaceFolder}", "--extensionTestsPath=${workspaceFolder}/out/src/test/suite/index", - "${workspaceFolder}/example/app", + "${workspaceFolder}/example/app" ], "testConfiguration": "${workspaceFolder}/.vscode-test.mjs", "outFiles": ["${workspaceFolder}/out/test/**/*.js"], diff --git a/.vscode/settings.json b/.vscode/settings.json index 4cc3bbe..bc5507e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,11 +1,11 @@ { - "files.exclude": { - "out": false, // set this to true to hide the "out" folder with the compiled JS files - "dist": false // set this to true to hide the "dist" folder with the compiled JS files - }, - "search.exclude": { - "**/node_modules": true, // set this to false to include "node_modules" folder in search results - "out": true, // set this to false to include the "out" folder in search results - "dist": true // set this to false to include the "dist" folder in search results - } -} \ No newline at end of file + "files.exclude": { + "out": false, // set this to true to hide the "out" folder with the compiled JS files + "dist": false // set this to true to hide the "dist" folder with the compiled JS files + }, + "search.exclude": { + "**/node_modules": true, // set this to false to include "node_modules" folder in search results + "out": true, // set this to false to include the "out" folder in search results + "dist": true // set this to false to include the "dist" folder in search results + } +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json index c9dc1f0..50d4dbf 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,67 +1,62 @@ { - "version": "2.0.0", - "tasks": [ - { - "type": "npm", - "script": "build", - "problemMatcher": "$tsc", - "presentation": { - "reveal": "never" - }, - "group": { - "kind": "build", - "isDefault": true - } - }, - { - "type": "npm", - "script": "dev", - "problemMatcher": "$tsc", - "presentation": { - "reveal": "never" - }, - "group": { - "kind": "build", - "isDefault": false - } - }, - { - "label": "tasks: dev", - "dependsOn": [ - "npm: dev" - ], - "problemMatcher": [] - }, - { - "type": "npm", - "script": "build:watch", - "problemMatcher": "$tsc-watch", - "presentation": { - "reveal": "never" - }, - "group": { - "kind": "build", - "isDefault": false - } - }, - { - "type": "npm", - "script": "watch-tests", - "problemMatcher": "$tsc-watch", - "isBackground": true, - "presentation": { - "reveal": "never", - "group": "watchers" - }, - "group": "build" - }, - { - "label": "tasks: watch-tests", - "dependsOn": [ - "npm: build:watch", - "npm: watch-tests" - ], - "problemMatcher": [] - } - ] -} \ No newline at end of file + "version": "2.0.0", + "tasks": [ + { + "type": "npm", + "script": "build", + "problemMatcher": "$tsc", + "presentation": { + "reveal": "never" + }, + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "type": "npm", + "script": "dev", + "problemMatcher": "$tsc", + "presentation": { + "reveal": "never" + }, + "group": { + "kind": "build", + "isDefault": false + } + }, + { + "label": "tasks: dev", + "dependsOn": ["npm: dev"], + "problemMatcher": [] + }, + { + "type": "npm", + "script": "build:watch", + "problemMatcher": "$tsc-watch", + "presentation": { + "reveal": "never" + }, + "group": { + "kind": "build", + "isDefault": false + } + }, + { + "type": "npm", + "script": "watch-tests", + "problemMatcher": "$tsc-watch", + "isBackground": true, + "presentation": { + "reveal": "never", + "group": "watchers" + }, + "group": "build" + }, + { + "label": "tasks: watch-tests", + "dependsOn": ["npm: build:watch", "npm: watch-tests"], + "problemMatcher": [] + } + ] +} diff --git a/package.json b/package.json index a723600..2c9e65e 100644 --- a/package.json +++ b/package.json @@ -105,4 +105,4 @@ "vsce": "2.15.0", "vscode-test": "^1.5.0" } -} +} \ No newline at end of file From f8be26300688720a221c9ee6d97f6f9613a368b7 Mon Sep 17 00:00:00 2001 From: Jeremy Tenjo Date: Thu, 30 Jan 2025 18:54:07 -0500 Subject: [PATCH 15/15] Format configuration files for improved readability and consistency --- example/app/.prettierrc.js | 15 +++++++-------- package.json | 2 +- tsconfig.test.json | 26 +++++++++++++------------- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/example/app/.prettierrc.js b/example/app/.prettierrc.js index 0ad663f..972d1c7 100644 --- a/example/app/.prettierrc.js +++ b/example/app/.prettierrc.js @@ -1,10 +1,9 @@ module.exports = { - "printWidth": 90, - "trailingComma": "all", - "tabWidth": 2, - "semi": false, - "singleQuote": true, - "jsxSingleQuote": true, - "arrowParens": "always" + printWidth: 90, + trailingComma: 'all', + tabWidth: 2, + semi: false, + singleQuote: true, + jsxSingleQuote: true, + arrowParens: 'always', } - \ No newline at end of file diff --git a/package.json b/package.json index 2c9e65e..a723600 100644 --- a/package.json +++ b/package.json @@ -105,4 +105,4 @@ "vsce": "2.15.0", "vscode-test": "^1.5.0" } -} \ No newline at end of file +} diff --git a/tsconfig.test.json b/tsconfig.test.json index 4b7b0e5..154608c 100644 --- a/tsconfig.test.json +++ b/tsconfig.test.json @@ -1,14 +1,14 @@ { - "compilerOptions": { - "module": "commonjs", - "target": "es2020", - "lib": ["es2020"], - "outDir": "out", - "sourceMap": true, - "strict": true, - "skipLibCheck": true, - "esModuleInterop": true, - "rootDirs": ["src", "utils"], - }, - "exclude": ["node_modules", ".vscode-test", "example", "scripts"] -} \ No newline at end of file + "compilerOptions": { + "module": "commonjs", + "target": "es2020", + "lib": ["es2020"], + "outDir": "out", + "sourceMap": true, + "strict": true, + "skipLibCheck": true, + "esModuleInterop": true, + "rootDirs": ["src", "utils"] + }, + "exclude": ["node_modules", ".vscode-test", "example", "scripts"] +}