From 70d1e9c8d7d8518317819c1f42894b0cbecc9492 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CBugs5382=E2=80=9D?= Date: Sat, 30 Dec 2023 19:30:34 -0500 Subject: [PATCH] feat: git working now * removed clean-publish #18 * linted all files * git now does my git scheme and commits, clears, etc. correctly. * more refactoring as well Closes #18, #17 --- .eslintignore | 1 + release.config.cjs | 6 +- src/index.ts | 16 +++-- src/modules/constants.ts | 109 +++++++++++++++++++++++++++++ src/modules/dependencies.ts | 115 ++----------------------------- src/modules/git.ts | 20 +++++- src/modules/helpers.ts | 72 +++++++++++++++++++ src/modules/npm.ts | 37 ---------- template/vite/.eslintrc.cjs | 8 +-- template/vite/postcss.config.js | 4 +- template/vite/tailwind.config.js | 8 +-- 11 files changed, 228 insertions(+), 168 deletions(-) create mode 100644 .eslintignore diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..39d686b --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +/template/**/** \ No newline at end of file diff --git a/release.config.cjs b/release.config.cjs index 5a7d61b..a672346 100644 --- a/release.config.cjs +++ b/release.config.cjs @@ -1,6 +1,6 @@ module.exports = { - "extends": "@the-rabbit-hole/semantic-release-config", - "branches": [ - "main" + extends: '@the-rabbit-hole/semantic-release-config', + branches: [ + 'main' ] } diff --git a/src/index.ts b/src/index.ts index bb82d12..df9c57d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,9 +8,9 @@ import path from 'node:path' import { DEFAULT_NPM, isProd } from './modules/constants.js' import { returnDependencies } from './modules/dependencies.js' import * as git from './modules/git.js' -import { getProjectName, parseOptions } from './modules/helpers.js' +import { getProjectName, installDeps, parseOptions } from './modules/helpers.js' import { generateLicense, licenseChoices } from './modules/license.js' -import { generatePackageJson, installDeps } from './modules/npm.js' +import { generatePackageJson } from './modules/npm.js' import { generateTemplate } from './modules/template.js' /** @@ -138,17 +138,16 @@ export const main = async (): Promise => { type: 'list' }]) as Partial - const temp: string = process.env.NODE_ENV === 'test' ? 'temp/' : '' - - // create folder + const temp: string = !isProd() ? 'temp/' : '' + // Create folder const folder: string = typeof npmName !== 'undefined' ? npmName : npm const cwd = path.join(process.cwd(), `${temp}/${folder}`) fs.mkdirSync(cwd, { recursive: true }) process.chdir(cwd) - // git stuff - await git.init(cwd) + // GIT: Initial + await git.init(cwd, 'initial') if (gitLocation === 'github' && typeof repoOwner !== 'undefined' && typeof repoName !== 'undefined') { await git.addRemote(cwd, repoOwner, repoName) } @@ -208,6 +207,9 @@ export const main = async (): Promise => { vite }) + // GIT: Post Step + await git.init(cwd, 'post') + // Install Dependencies await installDeps(packages.dependencies) await installDeps(packages.devDependencies, { dev: true }) diff --git a/src/modules/constants.ts b/src/modules/constants.ts index e9b2ffb..a5ec338 100644 --- a/src/modules/constants.ts +++ b/src/modules/constants.ts @@ -1,3 +1,5 @@ +import { Dependencies } from './types' + export const DEFAULT_NPM = { author: { name: 'Shane Froebel' @@ -13,4 +15,111 @@ export const CLI_PROGRESS = (area: string): any => { } } +export const sharedDev: string[] = [ + '@semantic-release/changelog', + '@semantic-release/commit-analyzer', + '@semantic-release/git', + '@semantic-release/release-notes-generator', + '@the-rabbit-hole/semantic-release-config', + '@types/node', + 'npm-check-updates', + 'npm-package-json-lint', + 'pre-commit', + 'semantic-release', + 'snazzy', + 'ts-node', + 'ts-standard', + 'tsd', + 'typedoc', + 'typescript' +] + +export const FASTIFY_GRAPHQL_CONTROLLER: Dependencies = { + dependencies: [ + '@fastify/autoload', + '@fastify/cors', + '@mercuriusjs/gateway', + 'fastify', + 'fastify-cli', + 'fastify-custom-healthcheck', + 'fastify-plugin' + ], + devDependencies: [ + ...sharedDev + ] +} + +export const FASTIFY_GRAPHQL_MICROSERVICES: Dependencies = { + dependencies: [ + '@fastify/autoload', + '@fastify/mongodb', + '@mercuriusjs/federation', + 'fastify', + 'fastify-cli', + 'fastify-custom-healthcheck', + 'fastify-plugin', + 'fastify-rabbitmq', + 'mercurius-codegen' + ], + devDependencies: [ + ...sharedDev + ] +} + +export const FASTIFY_NPM_PACKAGE: Dependencies = { + dependencies: [ + '@fastify/error', + 'fastify-plugin' + ], + devDependencies: [ + ...sharedDev, + 'fastify', + 'ts-jest', + '@types/jest', + 'jest', + 'jest-ts-webcompat-resolver' + ] +} + +export const NPM_PACKAGE: Dependencies = { + dependencies: [], + devDependencies: [ + ...sharedDev, + 'ts-jest', + '@types/jest', + 'jest', + 'jest-ts-webcompat-resolver' + ] +} + +export const VITE_REACT_SWC: Dependencies = { + dependencies: [ + '@apollo/client', + '@fortawesome/fontawesome-svg-core', + '@fortawesome/free-regular-svg-icons', + '@fortawesome/free-solid-svg-icons', + '@fortawesome/react-fontawesome', + 'graphql', + 'i18next', + 'i18next-browser-languagedetector', + 'i18next-http-backend', + 'react', + 'react-dom', + 'react-i18next', + 'react-router-dom', + 'react-spinners', + 'react-toastify' + ], + devDependencies: [ + ...sharedDev, + '@types/react', + '@types/react-dom', + '@vitejs/plugin-react-swc', + 'autoprefixer', + 'prettier-plugin-tailwindcss', + 'tailwindcss', + 'vite' + ] +} + export const isProd = (): boolean => process.env.NODE_ENV !== 'test' diff --git a/src/modules/dependencies.ts b/src/modules/dependencies.ts index d626ca8..9612269 100644 --- a/src/modules/dependencies.ts +++ b/src/modules/dependencies.ts @@ -1,113 +1,12 @@ +import { + FASTIFY_GRAPHQL_CONTROLLER, + FASTIFY_GRAPHQL_MICROSERVICES, + FASTIFY_NPM_PACKAGE, + NPM_PACKAGE, + VITE_REACT_SWC +} from './constants.js' import { Dependencies, GenerateInput } from './types.js' -const sharedDev: string[] = [ - '@semantic-release/changelog', - '@semantic-release/commit-analyzer', - '@semantic-release/git', - '@semantic-release/release-notes-generator', - '@the-rabbit-hole/semantic-release-config', - '@types/node', - 'clean-publish', - 'npm-check-updates', - 'npm-package-json-lint', - 'pre-commit', - 'semantic-release', - 'snazzy', - 'ts-node', - 'ts-standard', - 'tsd', - 'typedoc', - 'typescript' -] - -const FASTIFY_GRAPHQL_CONTROLLER: Dependencies = { - dependencies: [ - '@fastify/autoload', - '@fastify/cors', - '@mercuriusjs/gateway', - 'fastify', - 'fastify-cli', - 'fastify-custom-healthcheck', - 'fastify-plugin' - ], - devDependencies: [ - ...sharedDev - ] -} - -const FASTIFY_GRAPHQL_MICROSERVICES: Dependencies = { - dependencies: [ - '@fastify/autoload', - '@fastify/mongodb', - '@mercuriusjs/federation', - 'fastify', - 'fastify-cli', - 'fastify-custom-healthcheck', - 'fastify-plugin', - 'fastify-rabbitmq', - 'mercurius-codegen' - ], - devDependencies: [ - ...sharedDev - ] -} - -const FASTIFY_NPM_PACKAGE: Dependencies = { - dependencies: [ - '@fastify/error', - 'fastify-plugin' - ], - devDependencies: [ - ...sharedDev, - 'fastify', - 'ts-jest', - '@types/jest', - 'jest', - 'jest-ts-webcompat-resolver' - ] -} - -const NPM_PACKAGE: Dependencies = { - dependencies: [], - devDependencies: [ - ...sharedDev, - 'ts-jest', - '@types/jest', - 'jest', - 'jest-ts-webcompat-resolver' - ] -} - -const VITE_REACT_SWC: Dependencies = { - dependencies: [ - '@apollo/client', - '@fortawesome/fontawesome-svg-core', - '@fortawesome/free-regular-svg-icons', - '@fortawesome/free-solid-svg-icons', - '@fortawesome/react-fontawesome', - 'graphql', - 'i18next', - 'i18next-browser-languagedetector', - 'i18next-http-backend', - 'react', - 'react-dom', - 'react-i18next', - 'react-router-dom', - 'react-spinners', - 'react-toastify' - ], - devDependencies: [ - ...sharedDev, - '@types/react', - '@types/react-dom', - '@vitejs/plugin-react-swc', - 'autoprefixer', - 'prettier-plugin-tailwindcss', - 'tailwindcss', - 'vite' - ] -} - /** * @since 1.0.0 * @param input diff --git a/src/modules/git.ts b/src/modules/git.ts index 83050cc..6013848 100644 --- a/src/modules/git.ts +++ b/src/modules/git.ts @@ -8,13 +8,27 @@ const execFile = promisify(childProcess.execFile) * Init Git * @since 1.5.0 * @param folder + * @param step */ -export async function init (folder: string): Promise { - await execFile('git', ['init'], { cwd: folder }) +export async function init (folder: string, step: string): Promise { + switch (step) { + case 'initial': { + await execFile('git', ['init', '--initial-branch=develop'], { cwd: folder }) + break + } + case 'post': { + await execFile('git', ['add', '.'], { cwd: folder }) + await execFile('git', ['commit', '-m', '"chore: initial creation [ci skip]"'], { cwd: folder }) + await execFile('git', ['switch', '--orphan', 'main'], { cwd: folder }) + await execFile('git', ['commit', '--allow-empty', '-m', '"chore: initial creation [ci skip]"'], { cwd: folder }) + break + } + } } /** - * Add Git Remote + * Add Git Remote for GitHub + * @since 1.5.0 * @param folder * @param repoOwner * @param repoName diff --git a/src/modules/helpers.ts b/src/modules/helpers.ts index 7b19e09..20e9323 100644 --- a/src/modules/helpers.ts +++ b/src/modules/helpers.ts @@ -1,9 +1,17 @@ import cliProgress from 'cli-progress' import fs from 'fs' +import inquirer from 'inquirer' +import askNpmName from 'inquirer-npm-name' +import childProcess from 'node:child_process' import path from 'node:path' +import { promisify } from 'node:util' +import yargs from 'yargs' +import { hideBin } from 'yargs/helpers' import { CLI_PROGRESS } from './constants.js' import { TemplateCopyOptions } from './types.js' +const execFile = promisify(childProcess.execFile) + /** * Recurse Dir * @since 1.0.0 @@ -150,3 +158,67 @@ export const copyTemplateFiles = async ( return filesAdded.sort() } + +/** + * Parse CLI options + * @since 1.5.0 + */ +export const parseOptions = async (): Promise<{ name: string }> => { + const options = await yargs(hideBin(process.argv)) + .strict() + .parseAsync() + + const project = options._.map(String) + + console.log(project) + + return { name: 'this is a test' } +} + +/** + * @since 1.0.0 + * @param defaultProjectName + */ +export const getProjectName = async (defaultProjectName: string): Promise => { + const { npmName } = await askNpmName( + { + default: defaultProjectName, + name: 'npmName', + message: 'Your Project NPM name?', + type: 'input' + }, + inquirer + ) + + return npmName +} + +/** + * @since 1.0.0 + * @param dependencies + * @param options + */ +export const installDeps = async (dependencies: string[], options: { dev?: boolean } = {}): Promise => { + const args: string[] = ['install'] + if (options.dev === true) { + args.push('--save-dev') + } + + if (dependencies.length > 0) { + const bar = new cliProgress.SingleBar({}, CLI_PROGRESS(options.dev === true ? 'NPM DEV' : 'NPM')) + bar.start(dependencies.length, 0) + + let value = 0 + + for (const depend of dependencies) { + value++ + if (typeof process.env.NODE_ENV === 'undefined') { + await execFile('npm', [...args, depend]) + } + bar.update(value) + if (value >= bar.getTotal()) { + bar.stop() + } + } + } +} diff --git a/src/modules/npm.ts b/src/modules/npm.ts index 6eb3d5c..f0e6f61 100644 --- a/src/modules/npm.ts +++ b/src/modules/npm.ts @@ -1,14 +1,8 @@ -import childProcess from 'node:child_process' -import { promisify } from 'node:util' -import cliProgress from 'cli-progress' -import { CLI_PROGRESS } from './constants.js' import { GeneratePackageJsonInputWithOptions, GeneratePackageJsonParams } from './types.js' -const execFile = promisify(childProcess.execFile) - /** * @since 1.0.0 * @param params @@ -74,7 +68,6 @@ export const generatePackageJson = (params: GeneratePackageJsonParams, input: Ge 'build:watch': 'tsc -p tsconfig.esm.json -w', ...sharedScripts, pack: 'npm pack', - publish: 'clean-publish', prepublishOnly: 'npm run clean && npm run build && npm run pack', test: 'jest', 'test:open': 'jest --detectOpenHandles', @@ -143,33 +136,3 @@ export const generatePackageJson = (params: GeneratePackageJsonParams, input: Ge return { ...packageJson } } - -/** - * @since 1.0.0 - * @param dependencies - * @param options - */ -export const installDeps = async (dependencies: string[], options: { dev?: boolean } = {}): Promise => { - const args: string[] = ['install'] - if (options.dev === true) { - args.push('--save-dev') - } - - if (dependencies.length > 0) { - const bar = new cliProgress.SingleBar({}, CLI_PROGRESS(options.dev === true ? 'NPM DEV' : 'NPM')) - bar.start(dependencies.length, 0) - - let value = 0 - - for (const depend of dependencies) { - value++ - if (typeof process.env.NODE_ENV === 'undefined') { - await execFile('npm', [...args, depend]) - } - bar.update(value) - if (value >= bar.getTotal()) { - bar.stop() - } - } - } -} diff --git a/template/vite/.eslintrc.cjs b/template/vite/.eslintrc.cjs index d6c9537..c579bc2 100644 --- a/template/vite/.eslintrc.cjs +++ b/template/vite/.eslintrc.cjs @@ -4,7 +4,7 @@ module.exports = { extends: [ 'eslint:recommended', 'plugin:@typescript-eslint/recommended', - 'plugin:react-hooks/recommended', + 'plugin:react-hooks/recommended' ], ignorePatterns: ['dist', '.eslintrc.cjs'], parser: '@typescript-eslint/parser', @@ -12,7 +12,7 @@ module.exports = { rules: { 'react-refresh/only-export-components': [ 'warn', - { allowConstantExport: true }, - ], - }, + { allowConstantExport: true } + ] + } } diff --git a/template/vite/postcss.config.js b/template/vite/postcss.config.js index 2e7af2b..2b75bd8 100644 --- a/template/vite/postcss.config.js +++ b/template/vite/postcss.config.js @@ -1,6 +1,6 @@ export default { plugins: { tailwindcss: {}, - autoprefixer: {}, - }, + autoprefixer: {} + } } diff --git a/template/vite/tailwind.config.js b/template/vite/tailwind.config.js index 9842bae..8cd22c7 100644 --- a/template/vite/tailwind.config.js +++ b/template/vite/tailwind.config.js @@ -1,12 +1,12 @@ /** @type {import('tailwindcss').Config} */ export default { content: [ - "./index.html", - "./src/**/*.{ts,jsx,tsx}", + './index.html', + './src/**/*.{ts,jsx,tsx}' ], theme: { extend: {}, textColor: {} }, - plugins: [], -} \ No newline at end of file + plugins: [] +}