create-uix-app 1.2.1 → 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 +126 -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.1",
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(
@@ -40,51 +51,121 @@ if (!projectName) {
40
51
  .then(
41
52
  (r) =>
42
53
  new Promise((resolve, reject) => {
43
- console.log(`Unpacking into ${projectName}...`);
44
- r.data.pipe(
45
- tar.extract({ file: projectName }, (err) => {
46
- if (err) {
47
- reject(err);
48
- } else {
49
- resolve();
54
+ r.data
55
+ .pipe(tar.extract({ cwd: process.cwd() }))
56
+ .on("end", () => {
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
+ );
50
65
  }
66
+ resolve();
51
67
  })
52
- );
68
+ .on("error", (err) => reject(err));
53
69
  })
54
70
  )
55
71
  .then(() => {
56
- const pkgjson = JSON.parse(
57
- fs.readFileSync(path.join(projectName, "package.json"), "utf8")
58
- );
59
- pkgjson.name = projectName;
60
- fs.writeFileSync(
61
- path.join(projectName, "package.json"),
62
- prettier.format(JSON.stringify(pkgjson), {
63
- parser: "json",
64
- })
65
- );
66
- const readme = fs.readFileSync(
67
- path.join(projectName, "README.md"),
68
- "utf8"
69
- );
70
- fs.writeFileSync(
71
- path.join(projectName, "README.md"),
72
- readme
73
- .replace("uix-starter", projectName)
74
- .split("\n")
75
- .filter((l) => !l.startsWith("Template project"))
76
- .join("\n")
77
- );
78
- console.log("Installing dependencies...");
79
- exec(`cd ${projectName} && yarn install`, (err) => {
80
- if (err) {
81
- console.error(err);
82
- } else {
83
- console.log("Done.");
84
- console.log("\n");
85
- console.log("yarn dev # run dev build in watch mode with CLJS REPL");
86
- console.log("yarn release # build production bundle");
87
- }
88
- });
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(
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"),
146
+ "utf8"
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
+ }
89
170
  });
90
171
  }