@s0rt/3dvf 0.1.5 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli/index.js CHANGED
@@ -3608,7 +3608,7 @@ var package_default;
3608
3608
  var init_package = __esm(() => {
3609
3609
  package_default = {
3610
3610
  name: "@s0rt/3dvf",
3611
- version: "0.1.5",
3611
+ version: "0.2.1",
3612
3612
  description: "shadcn-style Three.js function library CLI",
3613
3613
  type: "module",
3614
3614
  bin: {
@@ -3629,15 +3629,17 @@ var init_package = __esm(() => {
3629
3629
  test: "bun test"
3630
3630
  },
3631
3631
  dependencies: {
3632
- "@types/three": "^0.183.1",
3633
3632
  commander: "^12.1.0",
3634
3633
  ora: "^8.1.1",
3635
3634
  picocolors: "^1.1.1",
3636
3635
  prompts: "^2.4.2"
3637
3636
  },
3638
3637
  devDependencies: {
3638
+ "@types/bun": "^1.3.10",
3639
3639
  "@types/prompts": "^2.4.9",
3640
- typescript: "^5.7.0"
3640
+ "@types/three": "^0.183.1",
3641
+ typescript: "^5.7.0",
3642
+ vite: "^7.3.1"
3641
3643
  }
3642
3644
  };
3643
3645
  });
@@ -10041,7 +10043,7 @@ function writeRegistryItem(item, outputDir, version, cwd = process.cwd()) {
10041
10043
  return written;
10042
10044
  }
10043
10045
 
10044
- // src/cli/utils/packageManager.ts
10046
+ // src/cli/utils/package-manager.ts
10045
10047
  import { existsSync as existsSync2 } from "fs";
10046
10048
  import { join as join3 } from "path";
10047
10049
  import { execSync } from "child_process";
@@ -10113,16 +10115,22 @@ Done!`) + ` Added ${items.length} function(s) to ${config.outputDir}`);
10113
10115
  }
10114
10116
 
10115
10117
  // src/cli/commands/create.ts
10116
- var import_prompts = __toESM(require_prompts3(), 1);
10117
- import { existsSync as existsSync4, readFileSync as readFileSync3, writeFileSync as writeFileSync3, mkdirSync as mkdirSync2 } from "fs";
10118
- import { join as join5, dirname as dirname3 } from "path";
10118
+ var import_prompts2 = __toESM(require_prompts3(), 1);
10119
+ import { existsSync as existsSync5, readFileSync as readFileSync4, writeFileSync as writeFileSync4, mkdirSync as mkdirSync2, rmSync } from "fs";
10120
+ import { join as join6, dirname as dirname3 } from "path";
10119
10121
  import { fileURLToPath as fileURLToPath2 } from "url";
10120
10122
  import { execSync as execSync2 } from "child_process";
10121
10123
  init_config();
10122
- var import_picocolors2 = __toESM(require_picocolors(), 1);
10124
+ var import_picocolors3 = __toESM(require_picocolors(), 1);
10125
+
10126
+ // src/cli/utils/init-project.ts
10127
+ var import_prompts = __toESM(require_prompts3(), 1);
10128
+ import { existsSync as existsSync4, readFileSync as readFileSync3, writeFileSync as writeFileSync3 } from "fs";
10129
+ import { join as join5 } from "path";
10123
10130
  init_config();
10131
+ var import_picocolors2 = __toESM(require_picocolors(), 1);
10124
10132
 
10125
- // src/cli/utils/ownPkg.ts
10133
+ // src/cli/utils/own-pkg.ts
10126
10134
  import { readFileSync as readFileSync2, existsSync as existsSync3 } from "fs";
10127
10135
  import { join as join4, dirname as dirname2 } from "path";
10128
10136
  import { fileURLToPath } from "url";
@@ -10137,17 +10145,73 @@ function findPkg(dir) {
10137
10145
  }
10138
10146
  var __dirname2 = dirname2(fileURLToPath(import.meta.url));
10139
10147
  var ownPkg = JSON.parse(readFileSync2(findPkg(__dirname2), "utf-8"));
10140
- var ownPkg_default = ownPkg;
10148
+ var own_pkg_default = ownPkg;
10149
+
10150
+ // src/cli/utils/init-project.ts
10151
+ var THREE_VERSION = (own_pkg_default.devDependencies?.["@types/three"]).replace(/^\^|~/, "");
10152
+ async function initProject(cwd) {
10153
+ let config;
10154
+ if (configExists(cwd)) {
10155
+ config = readConfig(cwd);
10156
+ console.log(import_picocolors2.default.dim("3dvf.json already exists, skipping config prompt"));
10157
+ } else {
10158
+ const answers = await import_prompts.default([
10159
+ {
10160
+ type: "text",
10161
+ name: "outputDir",
10162
+ message: "Where should functions be installed?",
10163
+ initial: DEFAULT_CONFIG.outputDir
10164
+ }
10165
+ ], { onCancel: () => process.exit(1) });
10166
+ config = {
10167
+ outputDir: answers.outputDir,
10168
+ registry: DEFAULT_CONFIG.registry,
10169
+ typescript: true
10170
+ };
10171
+ writeConfig(config, cwd);
10172
+ console.log(import_picocolors2.default.green("✓") + " Created 3dvf.json");
10173
+ console.log(import_picocolors2.default.dim(` outputDir: ${config.outputDir}`));
10174
+ }
10175
+ const spinner = ora(`Installing three@${THREE_VERSION}...`).start();
10176
+ try {
10177
+ installDeps([`three@${THREE_VERSION}`], [`@types/three@${THREE_VERSION}`], cwd);
10178
+ spinner.succeed(`Installed three@${THREE_VERSION}`);
10179
+ } catch (err) {
10180
+ spinner.fail("Failed to install three");
10181
+ console.error(import_picocolors2.default.red(err.message));
10182
+ process.exit(1);
10183
+ }
10184
+ const tsconfigPath = join5(cwd, "tsconfig.json");
10185
+ if (existsSync4(tsconfigPath)) {
10186
+ const raw = readFileSync3(tsconfigPath, "utf-8");
10187
+ const stripped = raw.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/[^\n]*/g, "");
10188
+ const tsconfig = JSON.parse(stripped);
10189
+ tsconfig.compilerOptions ??= {};
10190
+ tsconfig.compilerOptions.paths = {
10191
+ ...tsconfig.compilerOptions.paths,
10192
+ "@3dvf/*": [`./${config.outputDir}/*`]
10193
+ };
10194
+ tsconfig.compilerOptions.typeRoots = [
10195
+ "node_modules",
10196
+ "node_modules/@types"
10197
+ ];
10198
+ const tsconfigJson = JSON.stringify(tsconfig, null, 2).replace(/"typeRoots"/, `// Needed to get types from @types/three subfolders https://stackoverflow.com/a/78599968 & https://github.com/microsoft/TypeScript/issues/54629#issuecomment-1589593147
10199
+ "typeRoots"`);
10200
+ writeFileSync3(tsconfigPath, tsconfigJson + `
10201
+ `, "utf-8");
10202
+ console.log(import_picocolors2.default.green("✓") + " Updated tsconfig.json");
10203
+ }
10204
+ return config;
10205
+ }
10141
10206
 
10142
10207
  // src/cli/commands/create.ts
10143
- var THREE_VERSION = (ownPkg_default.dependencies?.["@types/three"]).replace(/^\^|~/, "");
10144
10208
  var __dirname3 = dirname3(fileURLToPath2(import.meta.url));
10145
- var TEMPLATES_DIR = join5(__dirname3, "./templates/create");
10209
+ var TEMPLATES_DIR = join6(__dirname3, "./templates/create");
10146
10210
  function readTemplate(file) {
10147
- return readFileSync3(join5(TEMPLATES_DIR, file), "utf-8");
10211
+ return readFileSync4(join6(TEMPLATES_DIR, file), "utf-8");
10148
10212
  }
10149
- async function createCommand2(projectName) {
10150
- const answers = await import_prompts.default([
10213
+ async function createCommand2(projectName, { cwd = process.cwd() } = {}) {
10214
+ const answers = await import_prompts2.default([
10151
10215
  {
10152
10216
  type: projectName ? null : "text",
10153
10217
  name: "name",
@@ -10157,44 +10221,45 @@ async function createCommand2(projectName) {
10157
10221
  }
10158
10222
  ], { onCancel: () => process.exit(1) });
10159
10223
  const name = projectName ?? answers.name;
10160
- const targetDir = join5(process.cwd(), name);
10161
- if (existsSync4(targetDir)) {
10162
- console.error(import_picocolors2.default.red(`Directory "${name}" already exists.`));
10224
+ const targetDir = join6(cwd, name);
10225
+ if (existsSync5(targetDir)) {
10226
+ console.error(import_picocolors3.default.red(`Directory "${name}" already exists.`));
10163
10227
  process.exit(1);
10164
10228
  }
10229
+ function cleanup() {
10230
+ if (existsSync5(targetDir)) {
10231
+ rmSync(targetDir, { recursive: true, force: true });
10232
+ console.error(import_picocolors3.default.dim(`Removed ${name}/`));
10233
+ }
10234
+ }
10165
10235
  const scaffoldSpinner = ora("Scaffolding Vite project...").start();
10166
10236
  try {
10167
10237
  execSync2(`npm create vite@latest ${name} -- --template vanilla-ts`, {
10238
+ cwd,
10168
10239
  stdio: "pipe"
10169
10240
  });
10170
10241
  scaffoldSpinner.succeed("Scaffolded Vite project");
10171
10242
  } catch (err) {
10172
10243
  scaffoldSpinner.fail("Failed to scaffold Vite project");
10173
- console.error(import_picocolors2.default.red(err.message));
10244
+ console.error(import_picocolors3.default.red(err.message));
10245
+ cleanup();
10174
10246
  process.exit(1);
10175
10247
  }
10176
- const config = {
10177
- outputDir: DEFAULT_CONFIG.outputDir,
10178
- registry: DEFAULT_CONFIG.registry,
10179
- typescript: true
10180
- };
10181
- writeConfig(config, targetDir);
10182
- console.log(import_picocolors2.default.green("✓") + " Created 3dvf.json");
10183
- const depsSpinner = ora(`Installing three@${THREE_VERSION}...`).start();
10248
+ let config;
10184
10249
  try {
10185
- installDeps([`three@${THREE_VERSION}`], [`@types/three@${THREE_VERSION}`], targetDir);
10186
- depsSpinner.succeed(`Installed three@${THREE_VERSION}`);
10250
+ config = await initProject(targetDir);
10187
10251
  } catch (err) {
10188
- depsSpinner.fail("Failed to install three");
10189
- console.error(import_picocolors2.default.red(err.message));
10252
+ console.error(import_picocolors3.default.red(err.message));
10253
+ cleanup();
10190
10254
  process.exit(1);
10191
10255
  }
10192
- const registrySpinner = ora("Adding get-webgpu-viewer...").start();
10256
+ const registrySpinner = ora("Adding create-viewer...").start();
10193
10257
  let tree;
10194
10258
  try {
10195
- tree = await resolveTree(["get-webgpu-viewer"], config.registry);
10259
+ tree = await resolveTree(["create-viewer"], config.registry);
10196
10260
  } catch (err) {
10197
10261
  registrySpinner.fail(err.message);
10262
+ cleanup();
10198
10263
  process.exit(1);
10199
10264
  return;
10200
10265
  }
@@ -10206,85 +10271,44 @@ async function createCommand2(projectName) {
10206
10271
  if (deps.length || devDeps.length) {
10207
10272
  installDeps(deps, devDeps, targetDir);
10208
10273
  }
10209
- registrySpinner.succeed("Added get-webgpu-viewer");
10274
+ registrySpinner.succeed("Added create-viewer");
10210
10275
  const pm = detectPackageManager(targetDir);
10211
10276
  const run = pm === "npm" ? "npm run" : pm;
10212
- writeFileSync3(join5(targetDir, "index.html"), readTemplate("index.html").replace("__PROJECT_NAME__", name), "utf-8");
10213
- console.log(import_picocolors2.default.green("") + " Created index.html");
10214
- mkdirSync2(join5(targetDir, "src"), { recursive: true });
10215
- writeFileSync3(join5(targetDir, "src", "main.ts"), readTemplate("main.ts"), "utf-8");
10216
- console.log(import_picocolors2.default.green("✓") + " Created src/main.ts");
10217
- writeFileSync3(join5(targetDir, "README.md"), readTemplate("README.md").replace("__PROJECT_NAME__", name).replace("__DEV_CMD__", `${run} dev`), "utf-8");
10218
- console.log(import_picocolors2.default.green("") + " Created README.md");
10277
+ writeFileSync4(join6(targetDir, "vite.config.ts"), readTemplate("vite.config.ts").replace("__OUTPUT_DIR__", config.outputDir), "utf-8");
10278
+ installDeps([], ["@types/node"], targetDir);
10279
+ console.log(import_picocolors3.default.green("") + " Created vite.config.ts");
10280
+ writeFileSync4(join6(targetDir, "index.html"), readTemplate("index.html").replace("__PROJECT_NAME__", name), "utf-8");
10281
+ console.log(import_picocolors3.default.green("✓") + " Created index.html");
10282
+ mkdirSync2(join6(targetDir, "src"), { recursive: true });
10283
+ writeFileSync4(join6(targetDir, "src", "main.ts"), readTemplate("main.ts"), "utf-8");
10284
+ console.log(import_picocolors3.default.green("✓") + " Created src/main.ts");
10285
+ writeFileSync4(join6(targetDir, "README.md"), readTemplate("README.md").replace("__PROJECT_NAME__", name).replace("__DEV_CMD__", `${run} dev`), "utf-8");
10286
+ console.log(import_picocolors3.default.green("✓") + " Created README.md");
10219
10287
  console.log(`
10220
- ${import_picocolors2.default.green("✓")} Created ${import_picocolors2.default.bold(name)}
10288
+ ${import_picocolors3.default.green("✓")} Created ${import_picocolors3.default.bold(name)}
10221
10289
 
10222
- ${import_picocolors2.default.bold("Next steps:")}
10290
+ ${import_picocolors3.default.bold("Next steps:")}
10223
10291
 
10224
- ${import_picocolors2.default.cyan(`cd ${name}`)}
10225
- ${import_picocolors2.default.cyan(`${run} dev`)}
10292
+ ${import_picocolors3.default.cyan(`cd ${name}`)}
10293
+ ${import_picocolors3.default.cyan(`${run} dev`)}
10226
10294
  `);
10227
10295
  }
10228
10296
 
10229
10297
  // src/cli/commands/init.ts
10230
- var import_prompts2 = __toESM(require_prompts3(), 1);
10231
- import { existsSync as existsSync5 } from "fs";
10232
- import { join as join6 } from "path";
10233
- init_config();
10234
- var import_picocolors3 = __toESM(require_picocolors(), 1);
10235
- var THREE_VERSION2 = (ownPkg_default.dependencies?.["@types/three"]).replace(/^\^|~/, "");
10298
+ var import_picocolors4 = __toESM(require_picocolors(), 1);
10299
+ import { existsSync as existsSync6 } from "fs";
10300
+ import { join as join7 } from "path";
10236
10301
  async function initCommand() {
10237
- if (!existsSync5(join6(process.cwd(), "package.json"))) {
10238
- console.error(import_picocolors3.default.red("No package.json found. Run `init` from the root of your project."));
10239
- process.exit(1);
10240
- }
10241
- if (configExists()) {
10242
- console.log(import_picocolors3.default.yellow("3dvf.json already exists. Skipping init."));
10243
- return;
10244
- }
10245
- const answers = await import_prompts2.default([
10246
- {
10247
- type: "text",
10248
- name: "outputDir",
10249
- message: "Where should functions be installed?",
10250
- initial: DEFAULT_CONFIG.outputDir
10251
- },
10252
- {
10253
- type: "toggle",
10254
- name: "typescript",
10255
- message: "Use TypeScript?",
10256
- initial: true,
10257
- active: "yes",
10258
- inactive: "no"
10259
- }
10260
- ]);
10261
- if (answers.outputDir === undefined) {
10262
- console.log(import_picocolors3.default.red("Cancelled."));
10263
- process.exit(1);
10264
- }
10265
- const config = {
10266
- outputDir: answers.outputDir,
10267
- registry: DEFAULT_CONFIG.registry,
10268
- typescript: answers.typescript
10269
- };
10270
- writeConfig(config);
10271
- console.log(import_picocolors3.default.green("✓") + " Created 3dvf.json");
10272
- console.log(import_picocolors3.default.dim(` outputDir: ${config.outputDir}`));
10273
- const spinner = ora(`Installing three@${THREE_VERSION2}...`).start();
10274
- try {
10275
- const devDeps = answers.typescript ? [`@types/three@${THREE_VERSION2}`] : [];
10276
- installDeps([`three@${THREE_VERSION2}`], devDeps);
10277
- spinner.succeed(`Installed three@${THREE_VERSION2}`);
10278
- } catch (err) {
10279
- spinner.fail("Failed to install three");
10280
- console.error(import_picocolors3.default.red(err.message));
10302
+ if (!existsSync6(join7(process.cwd(), "package.json"))) {
10303
+ console.error(import_picocolors4.default.red("No package.json found. Run `init` from the root of your project."));
10281
10304
  process.exit(1);
10282
10305
  }
10306
+ await initProject(process.cwd());
10283
10307
  }
10284
10308
 
10285
10309
  // src/cli/commands/list.ts
10286
10310
  init_config();
10287
- var import_picocolors4 = __toESM(require_picocolors(), 1);
10311
+ var import_picocolors5 = __toESM(require_picocolors(), 1);
10288
10312
  async function listCommand() {
10289
10313
  let config;
10290
10314
  try {
@@ -10297,11 +10321,11 @@ async function listCommand() {
10297
10321
  try {
10298
10322
  const index = await fetchRegistryIndex(config.registry);
10299
10323
  spinner.stop();
10300
- console.log(import_picocolors4.default.bold(`
10324
+ console.log(import_picocolors5.default.bold(`
10301
10325
  Available functions (${index.items.length}):
10302
10326
  `));
10303
10327
  for (const item of index.items) {
10304
- console.log(` ${import_picocolors4.default.cyan(item.name)}`);
10328
+ console.log(` ${import_picocolors5.default.cyan(item)}`);
10305
10329
  }
10306
10330
  console.log();
10307
10331
  } catch (err) {
@@ -1,6 +1,6 @@
1
1
  # __PROJECT_NAME__
2
2
 
3
- A Three.js WebGPU project scaffolded with [3dvf](https://github.com/s0rt/3dvf).
3
+ A Three.js project scaffolded with [3dvf](https://github.com/s0rt/3dvf).
4
4
 
5
5
  ## Getting started
6
6
 
@@ -1,29 +1,15 @@
1
1
  import {
2
- Scene,
3
- Color,
4
- PerspectiveCamera,
5
2
  BoxGeometry,
6
3
  MeshPhongMaterial,
7
4
  Mesh,
8
5
  AmbientLight,
9
6
  DirectionalLight,
10
7
  } from "three";
11
- import { getWebGPUViewer } from "./lib/3dvf/get-webgpu-viewer";
8
+ import { createViewer } from "@3dvf/create-viewer/create-viewer";
12
9
 
13
10
  const container = document.getElementById("app") as HTMLElement;
14
11
 
15
- const scene = new Scene();
16
- scene.background = new Color(0x1a1a2e);
17
-
18
- const camera = new PerspectiveCamera(
19
- 75,
20
- container.clientWidth / container.clientHeight,
21
- 0.1,
22
- 1000
23
- );
24
- camera.position.z = 3;
25
-
26
- const { dispose, renderer } = getWebGPUViewer(container);
12
+ const { scene, dispose, camera, launch } = createViewer(container);
27
13
 
28
14
  const geometry = new BoxGeometry(1.2, 1.2, 1.2);
29
15
  const material = new MeshPhongMaterial({ color: 0x4fc3f7 });
@@ -37,18 +23,9 @@ const directionalLight = new DirectionalLight(0xffffff, 1);
37
23
  directionalLight.position.set(5, 5, 5);
38
24
  scene.add(directionalLight);
39
25
 
40
- function animate() {
41
- cube.rotation.x += 0.005;
42
- cube.rotation.y += 0.01;
43
- renderer.render(scene, camera);
44
- }
45
-
46
- renderer.setAnimationLoop(animate);
26
+ camera.position.set(4, 4, 4);
47
27
 
48
- window.addEventListener("resize", () => {
49
- camera.aspect = container.clientWidth / container.clientHeight;
50
- camera.updateProjectionMatrix();
51
- });
28
+ launch();
52
29
 
53
30
  // HMR cleanup
54
31
  if (import.meta.hot) {
@@ -0,0 +1,15 @@
1
+ import { defineConfig } from "vite";
2
+
3
+ import { join, dirname } from "path";
4
+ import { fileURLToPath } from "url";
5
+
6
+ const __filename = fileURLToPath(import.meta.url);
7
+ const __dirname = dirname(__filename);
8
+
9
+ export default defineConfig({
10
+ resolve: {
11
+ alias: {
12
+ "@3dvf": join(__dirname, "./__OUTPUT_DIR__"),
13
+ },
14
+ },
15
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@s0rt/3dvf",
3
- "version": "0.1.5",
3
+ "version": "0.2.1",
4
4
  "description": "shadcn-style Three.js function library CLI",
5
5
  "type": "module",
6
6
  "bin": {
@@ -21,14 +21,16 @@
21
21
  "test": "bun test"
22
22
  },
23
23
  "dependencies": {
24
- "@types/three": "^0.183.1",
25
24
  "commander": "^12.1.0",
26
25
  "ora": "^8.1.1",
27
26
  "picocolors": "^1.1.1",
28
27
  "prompts": "^2.4.2"
29
28
  },
30
29
  "devDependencies": {
30
+ "@types/bun": "^1.3.10",
31
31
  "@types/prompts": "^2.4.9",
32
- "typescript": "^5.7.0"
32
+ "@types/three": "^0.183.1",
33
+ "typescript": "^5.7.0",
34
+ "vite": "^7.3.1"
33
35
  }
34
36
  }