create-uix-app 1.2.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/package.json +3 -2
  2. package/src/index.js +120 -45
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "create-uix-app",
3
- "description": "Creates a starter project for UIx2 web app",
4
- "version": "1.2.2",
3
+ "description": "Creates a starter project for UIx web app",
4
+ "version": "1.3.0",
5
5
  "author": {
6
6
  "name": "Roman Liutikov"
7
7
  },
@@ -18,6 +18,7 @@
18
18
  "dependencies": {
19
19
  "axios": "^1.3.4",
20
20
  "commander": "^10.0.0",
21
+ "deepmerge": "^4.3.1",
21
22
  "prettier": "^2.8.7",
22
23
  "tar": "^6.1.13"
23
24
  }
package/src/index.js CHANGED
@@ -6,6 +6,7 @@ const axios = require("axios");
6
6
  const tar = require("tar");
7
7
  const { program } = require("commander");
8
8
  const prettier = require("prettier");
9
+ const deepmerge = require("deepmerge");
9
10
  const pkg = require("../package.json");
10
11
 
11
12
  program
@@ -13,21 +14,31 @@ program
13
14
  .description(pkg.description)
14
15
  .version(pkg.version)
15
16
  .argument("<project-name>", "directory where a project will be created")
16
- .option("--re-frame", "add re-frame setup");
17
+ .option("--re-frame", "add re-frame setup")
18
+ .option(
19
+ "--react-native <app-name>",
20
+ "setup in existing React Native project"
21
+ );
17
22
 
18
23
  program.parse();
19
24
 
20
25
  const [projectName] = program.args;
21
- const { reFrame } = program.opts();
26
+ const { reFrame, reactNative } = program.opts();
22
27
 
23
28
  const masterUrl =
24
29
  "https://github.com/pitch-io/uix-starter/archive/master.tar.gz";
25
30
  const reframeUrl =
26
31
  "https://github.com/pitch-io/uix-starter/archive/re-frame.tar.gz";
32
+ const reactNativeUrl =
33
+ "https://github.com/pitch-io/uix-starter/archive/react-native.tar.gz";
27
34
 
28
- const downloadUrl = reFrame ? reframeUrl : masterUrl;
35
+ const downloadUrl = reactNative
36
+ ? reactNativeUrl
37
+ : reFrame
38
+ ? reframeUrl
39
+ : masterUrl;
29
40
 
30
- if (!projectName) {
41
+ if (!projectName && !reactNative) {
31
42
  program.help();
32
43
  } else {
33
44
  console.log(
@@ -43,54 +54,118 @@ if (!projectName) {
43
54
  r.data
44
55
  .pipe(tar.extract({ cwd: process.cwd() }))
45
56
  .on("end", () => {
46
- fs.renameSync(
47
- path.join(
48
- process.cwd(),
49
- reFrame ? "uix-starter-re-frame" : "uix-starter-main"
50
- ),
51
- path.join(process.cwd(), projectName)
52
- );
57
+ if (!reactNative) {
58
+ fs.renameSync(
59
+ path.join(
60
+ process.cwd(),
61
+ reFrame ? "uix-starter-re-frame" : "uix-starter-main"
62
+ ),
63
+ path.join(process.cwd(), projectName)
64
+ );
65
+ }
53
66
  resolve();
54
67
  })
55
68
  .on("error", (err) => reject(err));
56
69
  })
57
70
  )
58
71
  .then(() => {
59
- const pkgjson = JSON.parse(
60
- fs.readFileSync(
72
+ if (reactNative) {
73
+ const pkgjsonTmpl = JSON.parse(
74
+ fs.readFileSync(
75
+ path.join(
76
+ process.cwd(),
77
+ "uix-starter-react-native",
78
+ "package.json"
79
+ ),
80
+ "utf8"
81
+ )
82
+ );
83
+ const pkgjsonPrjct = JSON.parse(
84
+ fs.readFileSync(
85
+ path.join(
86
+ process.cwd(),
87
+ "uix-starter-react-native",
88
+ "package.json"
89
+ ),
90
+ "utf8"
91
+ )
92
+ );
93
+
94
+ // update package.json
95
+ fs.writeFileSync(
96
+ path.join(process.cwd(), "package.json"),
97
+ prettier.format(
98
+ JSON.stringify(deepmerge(pkgjsonPrjct, pkgjsonTmpl)),
99
+ {
100
+ parser: "json",
101
+ }
102
+ )
103
+ );
104
+
105
+ fs.renameSync(
106
+ path.join(process.cwd(), "uix-starter-react-native", "src"),
107
+ path.join(process.cwd(), "src")
108
+ );
109
+
110
+ fs.renameSync(
111
+ path.join(process.cwd(), "uix-starter-react-native", "dev"),
112
+ path.join(process.cwd(), "dev")
113
+ );
114
+
115
+ fs.renameSync(
116
+ path.join(process.cwd(), "uix-starter-react-native", "deps.edn"),
117
+ path.join(process.cwd(), "deps.edn")
118
+ );
119
+
120
+ fs.renameSync(
121
+ path.join(
122
+ process.cwd(),
123
+ "uix-starter-react-native",
124
+ "shadow-cljs.edn"
125
+ ),
126
+ path.join(process.cwd(), "shadow-cljs.edn")
127
+ );
128
+
129
+ fs.rmdirSync("uix-starter-react-native", { recursive: true });
130
+ } else {
131
+ const pkgjson = JSON.parse(
132
+ fs.readFileSync(
133
+ path.join(process.cwd(), projectName, "package.json"),
134
+ "utf8"
135
+ )
136
+ );
137
+ pkgjson.name = projectName;
138
+ fs.writeFileSync(
61
139
  path.join(process.cwd(), projectName, "package.json"),
140
+ prettier.format(JSON.stringify(pkgjson), {
141
+ parser: "json",
142
+ })
143
+ );
144
+ const readme = fs.readFileSync(
145
+ path.join(process.cwd(), projectName, "README.md"),
62
146
  "utf8"
63
- )
64
- );
65
- pkgjson.name = projectName;
66
- fs.writeFileSync(
67
- path.join(process.cwd(), projectName, "package.json"),
68
- prettier.format(JSON.stringify(pkgjson), {
69
- parser: "json",
70
- })
71
- );
72
- const readme = fs.readFileSync(
73
- path.join(process.cwd(), projectName, "README.md"),
74
- "utf8"
75
- );
76
- fs.writeFileSync(
77
- path.join(process.cwd(), projectName, "README.md"),
78
- readme
79
- .replace("uix-starter", projectName)
80
- .split("\n")
81
- .filter((l) => !l.startsWith("Template project"))
82
- .join("\n")
83
- );
84
- console.log("Installing dependencies...");
85
- exec(`cd ${projectName} && yarn install`, (err) => {
86
- if (err) {
87
- console.error(err);
88
- } else {
89
- console.log("Done.");
90
- console.log("\n");
91
- console.log("yarn dev # run dev build in watch mode with CLJS REPL");
92
- console.log("yarn release # build production bundle");
93
- }
94
- });
147
+ );
148
+ fs.writeFileSync(
149
+ path.join(process.cwd(), projectName, "README.md"),
150
+ readme
151
+ .replace("uix-starter", projectName)
152
+ .split("\n")
153
+ .filter((l) => !l.startsWith("Template project"))
154
+ .join("\n")
155
+ );
156
+ console.log("Installing dependencies...");
157
+ exec(`cd ${projectName} && yarn install`, (err) => {
158
+ if (err) {
159
+ console.error(err);
160
+ } else {
161
+ console.log("Done.");
162
+ console.log("\n");
163
+ console.log(
164
+ "yarn dev # run dev build in watch mode with CLJS REPL"
165
+ );
166
+ console.log("yarn release # build production bundle");
167
+ }
168
+ });
169
+ }
95
170
  });
96
171
  }