Skip to content

Commit 691c6d9

Browse files
authored
Merge pull request Soomgo-Mobile#33 from Soomgo-Mobile/feature/issue-28
Initialized CLI (PR re-opened)
2 parents b739380 + 4c2122b commit 691c6d9

File tree

6 files changed

+207
-53
lines changed

6 files changed

+207
-53
lines changed

cli/constant.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
configFileName: "codepush.config.js",
3+
};

cli/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env node
2+
3+
const { program } = require("commander");
4+
const shell = require("shelljs");
5+
const { showLogo } = require("./utils/showLogo");
6+
const { findAndReadConfigFile } = require("./utils/fsUtils");
7+
8+
shell.set("-e");
9+
shell.set("-v");
10+
11+
program
12+
.name("@bravemobile/react-native-code-push CLI")
13+
.description("Command line interface for @bravemobile/react-native-code-push")
14+
.version("1.0.0")
15+
.action(async () => {
16+
showLogo();
17+
const config = findAndReadConfigFile(process.cwd());
18+
});
19+
20+
program.parse();

cli/utils/fsUtils.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
const { configFileName } = require("../constant");
4+
5+
function findAndReadConfigFile(startDir) {
6+
let dir = startDir;
7+
8+
while (dir !== path.parse(dir).root) {
9+
const configPath = path.join(dir, configFileName);
10+
if (fs.existsSync(configPath)) {
11+
const config = require(configPath);
12+
return config;
13+
}
14+
dir = path.dirname(dir);
15+
}
16+
17+
console.error(`${configFileName} not found.`);
18+
return null;
19+
}
20+
21+
module.exports = { findAndReadConfigFile };

cli/utils/showLogo.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function showLogo() {
2+
const logo = `
3+
4+
+------------------------------------------------------------------+
5+
| |
6+
| ______ __ ____ __ |
7+
| / ____/___ ____/ /__ / __ \\__ _______/ /_ |
8+
| / / / __ \\/ __ / _ \\/ /_/ / / / / ___/ __ \\ |
9+
| / /___/ /_/ / /_/ / __/ ____/ /_/ (__ ) / / / |
10+
| \\____/\\____/\\__,_/\\___/_/ \\__,_/____/_/ /_/ |
11+
| |
12+
| |
13+
| 🎉 @bravemobile/react-native-code-push |
14+
+------------------------------------------------------------------+
15+
16+
`;
17+
console.log(logo);
18+
}
19+
20+
module.exports = { showLogo };

0 commit comments

Comments
 (0)