Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
refactor 🔨: (cli) Use bundleDependencies instead of separated files
Browse files Browse the repository at this point in the history
  • Loading branch information
nachoaldamav committed Dec 17, 2022
1 parent ef895b7 commit 7c8353d
Show file tree
Hide file tree
Showing 154 changed files with 7,610 additions and 226 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ coverage
.next/
out/
build
dist

# misc
.DS_Store
Expand Down
190 changes: 190 additions & 0 deletions generate-package.mjs
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();
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:*",
Expand All @@ -34,4 +36,4 @@
"node": ">=14.0.0"
},
"packageManager": "[email protected]"
}
}
15 changes: 15 additions & 0 deletions packages/.swcrc
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
}
24 changes: 24 additions & 0 deletions packages/base.json
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"]
}
16 changes: 16 additions & 0 deletions packages/bun/.swcrc
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
}
Loading

1 comment on commit 7c8353d

@vercel
Copy link

@vercel vercel bot commented on 7c8353d Dec 17, 2022

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

Please sign in to comment.