Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git-flow CLI #10

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
"name": "nodegit-flow",
"version": "0.3.0",
"description": "nodegit-flow contains gitflow methods that aren't include in the vanilla nodegit package",
"main": "build/src/index.js",
"main": "build/index.js",
"scripts": {
"compile": "babel --sourceMaps --presets es2015 -d ./build/spec ./spec && babel --sourceMaps --presets es2015 -d ./build/src ./src",
"compile": "babel --presets es2015 --source-maps --debug 3050 ./spec --out-dir ./build/spec && babel --presets es2015 --source-maps --debug 3051 ./src --out-dir ./build",
"watch": "concurrently --raw \"babel --presets es2015 --source-maps --watch --debug 3050 ./spec --out-dir ./build/spec\" \"babel --presets es2015 --source-maps --watch --debug 3051 ./src --out-dir ./build\"",
"eslint": "./node_modules/.bin/eslint src spec",
"prepublish": "babel --presets es2015 -d ./build/src ./src",
"prepublish": "babel --presets es2015 ./src --out-dir ./build",
"debug-test": "npm run eslint && npm run compile && node-debug --debug-brk node_modules/.bin/jasmine-node build/spec/tests",
"test": "npm run eslint && npm run compile && node_modules/.bin/jasmine-node build/spec/tests"
},
"bin": {
"git-flow": "./build/bin/git-flow.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/smith-kyle/nodegit-flow.git"
Expand All @@ -31,13 +35,19 @@
"homepage": "https://github.com/smith-kyle/nodegit-flow#readme",
"devDependencies": {
"babel-cli": "^6.3.15",
"babel-preset-es2015": "^6.3.13",
"babel-preset-es2015": "^6.18.0",
"concurrently": "^3.1.0",
"eslint": "^1.9.0",
"fs-extra": "^0.26.2",
"jasmine-node": "mhevery/jasmine-node#Jasmine2.0",
"jsdoc-to-markdown": "^1.3.2"
},
"peerDependencies": {
"nodegit": ">=0.13.0"
},
"dependencies": {
"bluebird": "^3.4.6",
"prompt": "^1.0.0",
"yargs": "^6.3.0"
}
}
148 changes: 148 additions & 0 deletions src/bin/git-flow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
#!/usr/bin/env node

const promisify = require('../utils/Promisify');
const yargs = require('yargs');
const prompt = require('prompt');
const promptGet = promisify(prompt.get);
const Git = require('../');



const openRepoPromise = Git.Repository.open('./');

const getRepo = function() {
return openRepoPromise;
};


const flowVerbBuilder = function(type, yargs) {
yargs
.command('start <name>', 'Start', {}, (argv) => {
console.log('start', type, argv);
const { name } = argv;
return getRepo()
.then((repo) => {
if(type === 'feature') {
return Git.Flow.startFeature(repo, name);
}
else if(type === 'release') {
return Git.Flow.startRelease(repo, name);
}
else if(type === 'hotfix') {
return Git.Flow.startHotfix(repo, name);
}
})
.then((branch) => {
console.log('Branch created:', branch && branch.shorthand());
})
.catch((err) => {
console.log(`Error starting ${type}, ${name}`, err, err.stack);
});
})
.command('publish <name>', 'Start', {}, (argv) => {
console.log('publish', argv);
console.log('`publish` command is not supported yet');
/* * /
return getRepo()
.then((repo) => {
var config = repo.config();
var remoteOriginUrl = config.getString('remote.origin.url');

return Git.Remote.create(
repo,
'origin',
remoteOriginUrl
)
.then(function(remoteResult) {
remote = remoteResult;

// Create the push object for this remote
return remote.push(
// TODO: use proper ref
["refs/heads/master:refs/heads/master"],
{
callbacks: {
credentials: function(url, userName) {
return nodegit.Cred.sshKeyFromAgent(userName);
}
}
}
);
})
});
/* */
})
.command('finish <name>', 'Start', {}, (argv) => {
console.log('finish', argv);
const { name } = argv;
return getRepo()
.then((repo) => {
if(type === 'feature') {
return Git.Flow.finishFeature(repo, name);
}
else if(type === 'release') {
return Git.Flow.finishRelease(repo, name);
}
else if(type === 'hotfix') {
return Git.Flow.finishHotfix(repo, name);
}
})
.then(function(mergeCommit) {
console.log('asdf', arguments);
console.log('Branch finished:', mergeCommit && mergeCommit.id());
})
.catch((err) => {
console.log(`Error finishing ${type}, ${name}`, err, err.stack);
});
})
.command('pull <name>', 'Start', {}, (argv) => {
console.log('`pull` command is not supported yet');
})
.help('help')
.alias('help', 'h')
.argv;
};


const initHandler = function(argv) {
console.log('init', argv);

const defaultConfig = Git.Flow.getConfigDefault();
const promptSchema = Object.keys(defaultConfig).reduce((schema, propName) => {
schema.properties[propName] = {
default: defaultConfig[propName],
required: !!defaultConfig[propName]
};

return schema;
}, { properties: {} });

prompt.start();
return promptGet(promptSchema)
.catch((err) => {
console.log('Error prompting for response', err, err.stack);
})
.then((resultConfig) => {
return getRepo()
.then((repo) => {
return Git.Flow.init(repo, resultConfig);
})
.then(() => {
console.log('git-flow is now initialized.');
});
})
.catch((err) => {
console.log('Error initializing git-flow', err, err.stack);
});
};



yargs
.command('init', 'Initialize git-flow in repository', {}, initHandler)
.command('feature', 'Develop new features for upcoming releases', flowVerbBuilder.bind(null, 'feature'))
.command('release', 'Support preparation of a new production release', flowVerbBuilder.bind(null, 'release'))
.command('hotfix', 'Fix undesired state of a production release immediately ahead of a new production release', flowVerbBuilder.bind(null, 'hotfix'))
.help('help')
.alias('help', 'h')
.argv;
2 changes: 1 addition & 1 deletion src/utils/FolderLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function FolderLoader(absoluteFolder, onto, replace) {
const fileStats = fs.lstatSync(path.join(absoluteFolder, file));

// don't recurse down directories
if (file.indexOf('index.') && ~file.indexOf('.js') && !fileStats.isDirectory()) {
if (!(/index\.js$/).test(file) && (/.*?\.js$/).test(file) && !fileStats.isDirectory()) {
onto[file.replace(replace, '')] = require('./' + relative + '/' + file);
}
});
Expand Down