@upskale/create-flux 0.0.0-stage → 0.1.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.
Files changed (3) hide show
  1. package/index.js +77 -0
  2. package/package.json +22 -4
  3. package/README.md +0 -3
package/index.js ADDED
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env node
2
+ // npm create @upskale/flux@latest [name] [-- --template site|app|store]
3
+ //
4
+ // Asks for what isn't given, makes the project with `flux new`, and adds
5
+ // @upskale/flux to it so `npx flux dev` runs the same version.
6
+ const { spawnSync } = require("node:child_process");
7
+ const { existsSync, readFileSync, writeFileSync } = require("node:fs");
8
+ const path = require("node:path");
9
+ const readline = require("node:readline/promises");
10
+
11
+ const templates = {
12
+ site: "a website",
13
+ app: "a Flutter app",
14
+ store: "a storefront on an Upskale business's API",
15
+ };
16
+
17
+ async function main() {
18
+ const args = process.argv.slice(2);
19
+ let name = args.find((arg) => !arg.startsWith("-"));
20
+ const flag = args.findIndex((arg) => arg === "--template" || arg === "-t");
21
+ let template = flag >= 0 ? args[flag + 1] : args.find((arg) => arg.startsWith("--template="))?.split("=")[1];
22
+ if (template === name) name = args.filter((arg) => !arg.startsWith("-") && arg !== template)[0];
23
+
24
+ const interactive = process.stdin.isTTY && process.stdout.isTTY;
25
+ if (interactive && (!name || !template)) {
26
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
27
+ if (!name) name = (await rl.question("Project name: (my-flux-app) ")).trim() || "my-flux-app";
28
+ if (!template) {
29
+ const keys = Object.keys(templates);
30
+ keys.forEach((key, i) => console.log(` ${i + 1}. ${key}: ${templates[key]}`));
31
+ const answer = (await rl.question("Template: (1) ")).trim() || "1";
32
+ template = keys[Number(answer) - 1] ?? (keys.includes(answer) ? answer : "site");
33
+ }
34
+ rl.close();
35
+ }
36
+ name ??= "my-flux-app";
37
+ template ??= "site";
38
+ if (!templates[template]) {
39
+ console.error(`Unknown template ${template}: ${Object.keys(templates).join(", ")}`);
40
+ process.exit(1);
41
+ }
42
+
43
+ const cli = require.resolve("@upskale/flux/bin/flux.js");
44
+ const made = spawnSync(process.execPath, [cli, "new", name, "--template", template], {
45
+ stdio: "inherit",
46
+ env: { ...process.env, FLUX_CREATE: "1" },
47
+ });
48
+ if (made.status !== 0) process.exit(made.status ?? 1);
49
+
50
+ // The project pins the CLI it was made with.
51
+ const own = require("@upskale/flux/package.json").version;
52
+ const pkgPath = path.join(name, "package.json");
53
+ if (!existsSync(pkgPath)) {
54
+ const pkg = {
55
+ name: path.basename(path.resolve(name)),
56
+ private: true,
57
+ scripts: { dev: "flux dev", build: "flux build", check: "flux check" },
58
+ devDependencies: { "@upskale/flux": "^" + own },
59
+ };
60
+ writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
61
+ } else {
62
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
63
+ pkg.devDependencies = { ...pkg.devDependencies, "@upskale/flux": "^" + own };
64
+ writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
65
+ }
66
+ const steps = [`cd ${name}`, "npm install", template === "app" ? "npx flux build --target flutter" : "npm run dev"];
67
+ console.log(`\nNext:\n\n${steps.map((step) => " " + step).join("\n")}\n`);
68
+ if (template === "app") console.log("Then run the app from dist/flutter: flutter run.\n");
69
+ else console.log("On the page, press E to edit it in place.\n");
70
+ if (template === "store")
71
+ console.log("It runs on sample data until flux.json has your business's API address (providers.upskale.api).\n");
72
+ }
73
+
74
+ main().catch((error) => {
75
+ console.error(error.message ?? error);
76
+ process.exit(1);
77
+ });
package/package.json CHANGED
@@ -1,6 +1,24 @@
1
1
  {
2
2
  "name": "@upskale/create-flux",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "Start a Flux project: npm create @upskale/flux@latest",
5
+ "license": "MIT",
6
+ "homepage": "https://flux.upskalelabs.dev",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/iamsinyagepr/flux.git",
10
+ "directory": "npm/create-flux"
11
+ },
12
+ "bin": {
13
+ "create-flux": "index.js"
14
+ },
15
+ "files": [
16
+ "index.js"
17
+ ],
18
+ "engines": {
19
+ "node": ">=18"
20
+ },
21
+ "dependencies": {
22
+ "@upskale/flux": "0.1.1"
23
+ }
24
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.