Skip to content

Commit

Permalink
fixed issues with commander
Browse files Browse the repository at this point in the history
- fixed args not being picked up
- fixed confusion over set / select command
- fixed some colour / error / warning issues
- bumped version numbers
- readme updates
  • Loading branch information
jasonkneen committed Nov 28, 2017
1 parent 7b6f6aa commit 1c10834
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 36 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
package-lock.json
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ $ tith
```
##Switch themes (Alloy)
```
$ tith select <name> <platform>
$ tith set <name> <platform>
```
(remember to do a ti clean)

if you omit a platform (ios or android) it'll default to **ios**.

##Theme-based tiapp.xml
Expand Down Expand Up @@ -59,7 +57,7 @@ app/themes/app1/DefaultIcon.png
Using the config above, the following will update the theme to **app1** and copy the tiapp.xml file from it's theme folder to the app root.

```
$ tith select app1 ios ;
$ tith set app1 ios ;
```

##Clearing themes
Expand Down
52 changes: 23 additions & 29 deletions bin/tith.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
var path = require('path');

var program = require('commander'),
chalk = require('chalk'),
updateNotifier = require('update-notifier'),
fs = require("fs"),
pkg = require('../package.json'),
exec = require('child_process').exec;
chalk = require('chalk'),
updateNotifier = require('update-notifier'),
fs = require("fs"),
pkg = require('../package.json'),
exec = require('child_process').exec;


// check if the TiApp.xml an TiCh config file exists
Expand All @@ -24,7 +24,7 @@ function createTiAppFile(fromPath) {
console.log(chalk.red('Ti Clean command failed'));
} else {
console.log(chalk.green(stdout));
console.log(chalk.cyan('Project clean and ready to build'));
console.log(chalk.green('Project cleaned and ready to build'));
}
});
}
Expand Down Expand Up @@ -53,11 +53,11 @@ function tith() {
if (name) {

if (name.substring(0, 1) == "_") {
alloyCfg.global.theme = ""
alloyCfg.global.theme = "";
console.log(chalk.yellow("\nClearing theme in config.json\n"));
} else {
alloyCfg.global.theme = name
console.log(chalk.yellow('\nUpdated Theme to ') + chalk.cyan(alloyCfg.global.theme) + "\n");
alloyCfg.global.theme = name;
console.log(chalk.green('\nUpdated Theme to ') + chalk.cyan(alloyCfg.global.theme) + "\n");
}

fs.writeFileSync("./app/config.json", JSON.stringify(alloyCfg, null, 4));
Expand Down Expand Up @@ -86,36 +86,27 @@ function tith() {
// check if we havea DefaultIcon.png
if (fs.existsSync("./app/themes/" + name + "/" + platform + "/" + iconName + ".png")) {
// if it exists in the themes folder, in a platform subfolder
console.log(chalk.blue('Found a ' + iconName + '.png in the theme platform folder\n'));
console.log(chalk.green('Found a ' + iconName + '.png in the theme platform folder\n'));
copyFile("./app/themes/" + name + "/" + platform + "/" + iconName + ".png", "./" + iconName + ".png");
} else if (fs.existsSync("./app/themes/" + name + "/" + iconName + ".png")) {
// if it exists in the top level theme folder
console.log(chalk.blue('Found a ' + iconName + '.png in the theme folder\n'));
console.log(chalk.green('Found a ' + iconName + '.png in the theme folder\n'));
copyFile("./app/themes/" + name + "/" + "/" + iconName + ".png", "./" + iconName + ".png");
} else {
console.log(chalk.red(iconName + '.png NOT Exists!\n'));
console.log(chalk.yellow(iconName + '.png does not exist for this theme.\n'));
}
}

if (fs.existsSync("./app/themes/" + name + "/" + platform)) {
console.log(chalk.blue('Fixing Resources Folder\n'));
var sourceDir = "./app/themes/" + name + "/" + platform;
var targetDir = "./app/assets/" + platform;
ncp(sourceDir, targetDir, function (err) {
if (err) {
return console.error(err);
}
console.log('done moving files!');
});
}
// if it exists in the themes folder, in a platform subfolder
console.log(chalk.green('Found a DefaultIcon.png in the theme platform folder\n'));
copyFile("./app/themes/" + name + "/" + platform + "/DefaultIcon.png", "./DefaultIcon.png");

function ncp(source, dest, options, callback) {
var cback = callback;

if (!callback) {
cback = options;
options = {};
}
// if it exists in the top level theme folder
console.log(chalk.green('Found a DefaultIcon.png in the theme folder\n'));
copyFile("./app/themes/" + name + "/" + "/DefaultIcon.png", "./DefaultIcon.png");

var basePath = process.cwd(),
currentPath = path.resolve(basePath, source),
Expand Down Expand Up @@ -363,7 +354,11 @@ function tith() {
}
var alloyCfg = JSON.parse(fs.readFileSync("./app/config.json", "utf-8"));
// setup CLI
program.version(pkg.version, '-v, --version').usage('[options]').description(pkg.description).option('-s, --set <name>', 'Updates config.json to use the theme specified by <name>')
program
.version(pkg.version, '-v, --version')
.usage('[options]')
.description(pkg.description)
.option('-s, set name platform', 'Updates config.json to use the theme specified by name and platform');

program.parse(process.argv);

Expand All @@ -379,4 +374,3 @@ function tith() {
status();
}
}

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tith",
"version": "1.1.3",
"version": "1.1.5",
"description": "TiTh (TiTheme) - allows you to switch Alloy themes via the terminal.",
"main": "index.js",
"bin": {
Expand Down Expand Up @@ -33,7 +33,7 @@
"homepage": "https://github.com/jasonkneen/tith",
"dependencies": {
"chalk": "^0.5.1",
"commander": "^2.6.0",
"commander": "^2.12.2",
"update-notifier": "^0.2.2"
}
}

0 comments on commit 1c10834

Please sign in to comment.