diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index f6f208b..016fa93 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -28,7 +28,7 @@ jobs: - name: Install Dependencies run: pnpm install - name: Build CLI - run: pnpm run build --filter=ultra-pkg + run: pnpm run build - name: Create Release Pull Request or Publish to npm id: changesets uses: changesets/action@v1 diff --git a/.gitignore b/.gitignore index f86c8da..037366e 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ coverage .next/ out/ build +dist # misc .DS_Store diff --git a/generate-package.mjs b/generate-package.mjs new file mode 100644 index 0000000..529d492 --- /dev/null +++ b/generate-package.mjs @@ -0,0 +1,190 @@ +import inquirer from "inquirer"; +import fs from "fs"; +import { join } from "path"; +import { exec } from "child_process"; + +const DEFAULT_TSUP_CONFIG = `import { defineConfig } from "tsup"; + +export default defineConfig({ + entry: ["src/index.ts"], + sourcemap: true, + clean: true, + splitting: true, + dts: true, + outDir: "dist", + format: "esm", + outExtension() { + return { + js: ".js", + }; + }, +}); +`; + +const DEFAULT_SWC_CONFIG = `{ + "$schema": "https://json.schemastore.org/swcrc", + "jsc": { + "parser": { + "syntax": "typescript", + "tsx": false, + "decorators": false, + "dynamicImport": true + }, + "transform": null, + "target": "es2017", + "loose": true, + "externalHelpers": false + }, + "minify": false +} +`; + +const DEFAULT_PACKAGE_JSON = { + name: "name", + version: "0.0.1", + description: "", + main: "dist/index.js", + types: "dist/index.d.ts", + type: "module", + scripts: { + test: 'echo "Error: no test specified" && exit 1', + build: "tsup", + dev: "tsup --watch", + }, + keywords: [], + author: "", + license: "ISC", + devDependencies: { + "@ultrapkg/types": "workspace:*", + "@types/node": "^18.11.13", + tsup: "6.5.0", + }, + dependencies: {}, + bundledDependencies: ["@ultrapkg/types"], +}; + +const dirs = { + src: { + "index.ts": `export const name = "name";`, + }, + "tsup.config.ts": DEFAULT_TSUP_CONFIG, + "swc.config.json": DEFAULT_SWC_CONFIG, + "package.json": DEFAULT_PACKAGE_JSON, +}; + +const questions = [ + { + type: "input", + name: "name", + message: "What is the name of the package?", + }, + { + type: "confirm", + name: "scope", + message: "Is this package scoped?", + default: true, + }, + { + type: "input", + name: "folder", + message: "What is the folder name?", + default: (answers) => answers.name, + }, + { + type: "list", + name: "where", + message: "Where is the package?", + choices: ["packages", "apps"], + default: "packages", + }, + { + type: "list", + name: "type", + message: "What type of package is it?", + choices: ["swc", "tsup", "none"], + default: "tsup", + }, +]; + +async function main() { + const answers = await inquirer.prompt(questions); + let name = answers.name; + const simpleName = answers.name; + + if (answers.scope) { + name = `@ultrapkg/${answers.name}`; + } + + const { folder, where, type } = answers; + const path = `${where}/${folder}`; + + if (!fs.existsSync(join(path, "src"))) { + console.log(`Creating ${path}`); + fs.mkdirSync(join(path, "src"), { recursive: true }); + } + + const packageJson = { + ...DEFAULT_PACKAGE_JSON, + name, + }; + + console.log(`Creating package.json`); + // Create package.json + fs.writeFileSync( + `${path}/package.json`, + JSON.stringify(packageJson, null, 2) + ); + + // Create tsup.config.ts + if (type === "tsup") { + console.log(`Creating tsup.config.ts`); + fs.writeFileSync(`${path}/tsup.config.ts`, DEFAULT_TSUP_CONFIG); + } + + // Create .swcrc + if (type === "swc") { + console.log(`Creating .swcrc`); + fs.writeFileSync(`${path}/.swcrc`, DEFAULT_SWC_CONFIG); + } + + console.log(`Generating starter files...`); + + // Create src/name.ts + fs.writeFileSync( + `${path}/src/${simpleName}.ts`, + `export const name = "${simpleName}";` + ); + + // Create src/index.ts + fs.writeFileSync( + `${path}/src/index.ts`, + `export { name } from "./${simpleName}";` + ); + + // Create src/tsconfig.json + fs.writeFileSync( + `${path}/src/tsconfig.json`, + JSON.stringify( + { + extends: "../base.json", + include: ["src/**/*.ts"], + exclude: ["node_modules", "dist", "dist/types"], + }, + null, + 2 + ) + ); + + console.log(`Done!`); + + console.log(`Installing dependencies...`); + + exec("pnpm i", { + cwd: process.cwd() + `/${where}/${folder}`, + stdio: "inherit", + }); + + console.log(`Done!`); +} + +main(); diff --git a/package.json b/package.json index 6f767a3..d2d50d5 100644 --- a/package.json +++ b/package.json @@ -14,13 +14,15 @@ "build": "turbo run build", "dev": "turbo run dev --parallel", "lint": "turbo run lint", + "types": "turbo run types", "format": "prettier --write \"**/*.{ts,tsx,md}\"", "changeset": "changeset", "version-packages": "changeset version", "release": "turbo run build --filter=apps^... --filter=examples && changeset publish" }, "dependencies": { - "@changesets/cli": "2.25.0" + "@changesets/cli": "2.25.0", + "inquirer": "9.1.4" }, "devDependencies": { "eslint-config-custom": "workspace:*", @@ -34,4 +36,4 @@ "node": ">=14.0.0" }, "packageManager": "pnpm@7.11.0" -} \ No newline at end of file +} diff --git a/packages/.swcrc b/packages/.swcrc new file mode 100644 index 0000000..dc8d410 --- /dev/null +++ b/packages/.swcrc @@ -0,0 +1,15 @@ +{ + "$schema": "https://json.schemastore.org/swcrc", + "jsc": { + "parser": { + "syntax": "typescript", + "tsx": false, + "decorators": false, + "dynamicImport": true + }, + "target": "es2017", + "loose": true, + "externalHelpers": false + }, + "minify": false +} diff --git a/packages/base.json b/packages/base.json new file mode 100644 index 0000000..4b16170 --- /dev/null +++ b/packages/base.json @@ -0,0 +1,24 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "display": "Default", + "compilerOptions": { + "composite": false, + "declaration": true, + "declarationMap": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": false, + "inlineSources": false, + "isolatedModules": true, + "moduleResolution": "node", + "noUnusedLocals": false, + "noUnusedParameters": false, + "preserveWatchOutput": true, + "skipLibCheck": true, + "strict": true, + "lib": ["ES2021", "dom"], + "types": ["node", "@ultrapkg/types"], + "typeRoots": ["node_modules/@types"] + }, + "include": ["src/**/*.ts"], + "exclude": ["node_modules", "dist", "dist/types"] +} diff --git a/packages/bun/.swcrc b/packages/bun/.swcrc new file mode 100644 index 0000000..aa8cbc7 --- /dev/null +++ b/packages/bun/.swcrc @@ -0,0 +1,16 @@ +{ + "$schema": "https://json.schemastore.org/swcrc", + "jsc": { + "parser": { + "syntax": "typescript", + "tsx": false, + "decorators": false, + "dynamicImport": true + }, + "transform": null, + "target": "es2017", + "loose": true, + "externalHelpers": false + }, + "minify": false +} \ No newline at end of file diff --git a/packages/bun/README.md b/packages/bun/README.md new file mode 100644 index 0000000..f86d6a7 --- /dev/null +++ b/packages/bun/README.md @@ -0,0 +1,127 @@ +