This repository has been archived by the owner on Nov 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor 🔨: (cli) Use
bundleDependencies
instead of separated files
- Loading branch information
1 parent
ef895b7
commit 7c8353d
Showing
154 changed files
with
7,610 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ coverage | |
.next/ | ||
out/ | ||
build | ||
dist | ||
|
||
# misc | ||
.DS_Store | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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": "[email protected]" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
Oops, something went wrong.
7c8353d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
fnpm – ./
ultrapkg.dev
ultrapkg.vercel.app
fnpm-srdrabx.vercel.app
fnpm-git-main-srdrabx.vercel.app
www.ultrapkg.dev