create-nube-app 0.0.2

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/biome.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
3
+ "organizeImports": {
4
+ "enabled": true
5
+ },
6
+ "linter": {
7
+ "enabled": true,
8
+ "rules": {
9
+ "recommended": true
10
+ }
11
+ }
12
+ }
package/index.js ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+
3
+ import './dist/index.js';
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "create-nube-app",
3
+ "description": "Create Nube App",
4
+ "author": "Tiendanube / Nuvemshop",
5
+ "license": "MIT",
6
+ "version": "0.0.2",
7
+ "bin": {
8
+ "create-nube-app": "index.js"
9
+ },
10
+ "scripts": {
11
+ "build": "tsup",
12
+ "check": "biome check src/*",
13
+ "check:fix": "biome check --write src/*"
14
+ },
15
+ "type": "module",
16
+ "devDependencies": {
17
+ "@clack/prompts": "^0.10.0",
18
+ "@types/fs-extra": "^11.0.4",
19
+ "@types/node": "^22.13.11",
20
+ "@types/prompts": "^2.4.9",
21
+ "fs-extra": "^11.1.1",
22
+ "prompts": "^2.4.2",
23
+ "tsup": "^8.4.0",
24
+ "typescript": "^5.6.2",
25
+ "@biomejs/biome": "1.8.3"
26
+ }
27
+ }
package/src/index.ts ADDED
@@ -0,0 +1,81 @@
1
+ import path from "node:path";
2
+ import { fileURLToPath } from "node:url";
3
+ import * as prompts from "@clack/prompts";
4
+ import fs from "fs-extra";
5
+
6
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
7
+
8
+ function toSlug(text: string): string {
9
+ return text.toLowerCase().replace(/\s+/g, "-");
10
+ }
11
+
12
+ interface PkgInfo {
13
+ name: string;
14
+ version: string;
15
+ }
16
+
17
+ function pkgFromUserAgent(userAgent: string | undefined): PkgInfo | undefined {
18
+ if (!userAgent) return undefined;
19
+ const pkgSpec = userAgent.split(" ")[0];
20
+ const pkgSpecArr = pkgSpec.split("/");
21
+ return {
22
+ name: pkgSpecArr[0],
23
+ version: pkgSpecArr[1],
24
+ };
25
+ }
26
+
27
+ function isEmpty(path: string) {
28
+ const files = fs.readdirSync(path);
29
+ return files.length === 0 || (files.length === 1 && files[0] === ".git");
30
+ }
31
+
32
+ async function main(): Promise<void> {
33
+ const defaultValue = "my-nube-app";
34
+ const pkgInfo = pkgFromUserAgent(process.env.npm_config_user_agent);
35
+ const cancel = (message = "Operation cancelled") => prompts.cancel(message);
36
+
37
+ const projectName = await prompts.text({
38
+ message: "What is the project's name?",
39
+ defaultValue,
40
+ placeholder: defaultValue,
41
+ });
42
+ if (prompts.isCancel(projectName)) return cancel();
43
+
44
+ const templateName = await prompts.select({
45
+ message: "Select a template:",
46
+ options: [
47
+ { label: "minimal", value: "minimal" },
48
+ { label: "minimal-ui", value: "minimal-ui" },
49
+ { label: "minimal-ui-jsx", value: "minimal-ui-jsx" },
50
+ ],
51
+ });
52
+ if (prompts.isCancel(templateName)) return cancel();
53
+
54
+ const dest = path.resolve(process.cwd(), toSlug(projectName as string));
55
+ const src = path.join(__dirname, `../templates/${templateName as string}`);
56
+
57
+ if (fs.existsSync(dest) && !isEmpty(dest)) {
58
+ cancel(`Template directory "${projectName}" is not empty.`);
59
+ return;
60
+ }
61
+
62
+ await fs.copy(src, dest);
63
+
64
+ const pkgManager = pkgInfo ? pkgInfo.name : "npm";
65
+ let doneMessage = "";
66
+ doneMessage += "Done. Now run:\n";
67
+ doneMessage += `\n cd ${projectName as string}`;
68
+ switch (pkgManager) {
69
+ case "yarn":
70
+ doneMessage += "\n yarn";
71
+ doneMessage += "\n yarn build";
72
+ break;
73
+ default:
74
+ doneMessage += `\n ${pkgManager} install`;
75
+ doneMessage += `\n ${pkgManager} run build`;
76
+ break;
77
+ }
78
+ prompts.outro(doneMessage);
79
+ }
80
+
81
+ main();
@@ -0,0 +1,11 @@
1
+ # Minimum setup for app development with NubeSDK
2
+
3
+ This project uses the type package in version `0.1.2-alpha` and `tsup` to compile typescript to javascript
4
+
5
+ # How to use
6
+
7
+ - install the development dependencies with the `npm install` command.
8
+ - Then start the development changing the `src/main.ts` file.
9
+ - To compile the project use the `npm run build` command.
10
+
11
+ The final script is created in the `dist` folder.