@blinkk/create-root 1.0.0-alpha.0

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.
Files changed (2) hide show
  1. package/dist/create-root.js +60 -0
  2. package/package.json +29 -0
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/create-root.ts
4
+ import { createRequire } from "module";
5
+ import path from "path";
6
+ import fs from "fs";
7
+ import { fileURLToPath } from "url";
8
+ import { Command } from "commander";
9
+ import degit from "degit";
10
+ var __dirname = path.dirname(fileURLToPath(import.meta.url));
11
+ var require2 = createRequire(import.meta.url);
12
+ var packageJson = require2(path.join(__dirname, "../package.json"));
13
+ async function main() {
14
+ const program = new Command("create-root");
15
+ program.version(packageJson.version);
16
+ program.argument("[dir]", "output dir");
17
+ program.option("--template [template]", "template to use", "starter");
18
+ program.option(
19
+ "--repo [repo]",
20
+ "github repo to pull from",
21
+ "blinkk/rootjs/examples"
22
+ );
23
+ program.action(async (dir, options) => {
24
+ if (!dir) {
25
+ dir = process.cwd();
26
+ }
27
+ const outputDir = path.resolve(dir || ".");
28
+ const repo = options.repo || "blinkk/rootjs/examples";
29
+ const template = options.template || "starter";
30
+ const githubPath = path.join(repo, template);
31
+ console.log(githubPath);
32
+ console.log(` github path: ${githubPath}`);
33
+ console.log(` output dir: ${maybeRelativePath(outputDir)}`);
34
+ const emitter = degit(githubPath, {
35
+ cache: false,
36
+ force: true,
37
+ verbose: false
38
+ });
39
+ await emitter.clone(outputDir);
40
+ await updatePackageJson(path.join(outputDir, "package.json"));
41
+ console.log("done!");
42
+ });
43
+ await program.parseAsync(process.argv);
44
+ }
45
+ async function updatePackageJson(packageJsonPath) {
46
+ const str = await fs.promises.readFile(packageJsonPath, "utf-8");
47
+ const packageJson2 = JSON.parse(str);
48
+ packageJson2.name = path.basename(path.dirname(packageJsonPath));
49
+ packageJson2.dependencies["@blinkk/root"] = "*";
50
+ console.log(packageJson2);
51
+ }
52
+ function maybeRelativePath(filePath) {
53
+ const cwd = process.cwd();
54
+ const fullPath = path.resolve(filePath);
55
+ if (fullPath.startsWith(cwd)) {
56
+ return `./${path.relative(cwd, fullPath)}`;
57
+ }
58
+ return fullPath;
59
+ }
60
+ main();
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@blinkk/create-root",
3
+ "version": "1.0.0-alpha.0",
4
+ "description": "",
5
+ "author": "s@blinkk.com",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/blinkk/rootjs.git",
10
+ "directory": "packages/create-root"
11
+ },
12
+ "files": [
13
+ "dist/*"
14
+ ],
15
+ "type": "module",
16
+ "bin": {
17
+ "create-root": "./dist/create-root.js"
18
+ },
19
+ "dependencies": {
20
+ "commander": "^10.0.0",
21
+ "degit": "^2.8.4"
22
+ },
23
+ "devDependencies": {
24
+ "tsup": "^6.6.3"
25
+ },
26
+ "scripts": {
27
+ "build": "tsup ./src/create-root.ts --format=esm"
28
+ }
29
+ }