acp-push 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # acp-push
2
+
3
+ Stage, commit and push in one command.
4
+
5
+ ```bash
6
+ acp
7
+ ```
8
+
9
+ runs:
10
+
11
+ ```bash
12
+ git add .
13
+ git commit -m "<one of 25 random messages>"
14
+ git push origin main
15
+ ```
16
+
17
+ ## Install
18
+
19
+ ```bash
20
+ npm install -g acp-push
21
+ ```
22
+
23
+ ## Options
24
+
25
+ | Flag | Description |
26
+ | --- | --- |
27
+ | `-u`, `--upstream` | Push to the `upstream` remote instead of `origin` |
28
+ | `-b`, `--branch <name>` | Push to `<name>` instead of `main` |
29
+ | `-m`, `--message <text>` | Use your own commit message instead of a random one |
30
+ | `-h`, `--help` | Show help |
31
+ | `-v`, `--version` | Show version |
32
+
33
+ ## Examples
34
+
35
+ ```bash
36
+ acp # git push origin main
37
+ acp -u # git push upstream main
38
+ acp -b dev # git push origin dev
39
+ acp --branch=dev # same as above
40
+ acp -u -b staging # git push upstream staging
41
+ acp -m "Fix login bug" # custom message
42
+ ```
43
+
44
+ ## Notes
45
+
46
+ - If there is nothing new to commit, `acp` skips the commit and still pushes, so any commits you made earlier get sent.
47
+ - If you're on a different branch than the one you're pushing, `acp` warns you, since your new commit lives on your current branch.
48
+ - `-u` needs a remote called `upstream`. Add one with `git remote add upstream <url>`.
49
+
50
+ ## Custom messages
51
+
52
+ Edit the list in `lib/messages.js`.
53
+
54
+ ## License
55
+
56
+ MIT
package/bin/acp.js ADDED
@@ -0,0 +1,157 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const { spawnSync } = require('child_process');
5
+ const messages = require('../lib/messages');
6
+ const pkg = require('../package.json');
7
+
8
+ // ---------- output helpers ----------
9
+ const useColor = process.stdout.isTTY && !process.env.NO_COLOR;
10
+ const paint = (code) => (text) => (useColor ? `\x1b[${code}m${text}\x1b[0m` : text);
11
+ const red = paint('31');
12
+ const green = paint('32');
13
+ const yellow = paint('33');
14
+ const cyan = paint('36');
15
+ const dim = paint('2');
16
+
17
+ const HELP = `
18
+ ${cyan('acp')} — git add, commit and push in one go
19
+
20
+ Usage: acp [options]
21
+
22
+ Options:
23
+ -u, --upstream Push to the "upstream" remote instead of "origin"
24
+ -b, --branch <name> Push to <name> instead of "main"
25
+ -m, --message <text> Use your own commit message instead of a random one
26
+ -h, --help Show this help
27
+ -v, --version Show the version
28
+
29
+ Examples:
30
+ acp ${dim('# git push origin main')}
31
+ acp -u ${dim('# git push upstream main')}
32
+ acp -b dev ${dim('# git push origin dev')}
33
+ acp -u --branch staging ${dim('# git push upstream staging')}
34
+ acp -m "Fix login bug" ${dim('# custom message, git push origin main')}
35
+ `;
36
+
37
+ function fail(message) {
38
+ console.error(red(`✖ ${message}`));
39
+ process.exit(1);
40
+ }
41
+
42
+ // ---------- argument parsing ----------
43
+ function parseArgs(argv) {
44
+ const options = { remote: 'origin', branch: 'main', message: null };
45
+
46
+ for (let i = 0; i < argv.length; i++) {
47
+ let flag = argv[i];
48
+ let inlineValue;
49
+
50
+ // Support --branch=dev and --message="text"
51
+ if (flag.startsWith('--') && flag.includes('=')) {
52
+ inlineValue = flag.slice(flag.indexOf('=') + 1);
53
+ flag = flag.slice(0, flag.indexOf('='));
54
+ }
55
+
56
+ const takeValue = () => {
57
+ if (inlineValue !== undefined) {
58
+ if (!inlineValue) fail(`${flag} needs a value`);
59
+ return inlineValue;
60
+ }
61
+ const next = argv[i + 1];
62
+ if (next === undefined || next.startsWith('-')) fail(`${flag} needs a value`);
63
+ i++;
64
+ return next;
65
+ };
66
+
67
+ switch (flag) {
68
+ case '-u':
69
+ case '--upstream':
70
+ options.remote = 'upstream';
71
+ break;
72
+ case '-b':
73
+ case '--branch':
74
+ options.branch = takeValue();
75
+ break;
76
+ case '-m':
77
+ case '--message':
78
+ options.message = takeValue();
79
+ break;
80
+ case '-h':
81
+ case '--help':
82
+ console.log(HELP);
83
+ process.exit(0);
84
+ break;
85
+ case '-v':
86
+ case '--version':
87
+ console.log(pkg.version);
88
+ process.exit(0);
89
+ break;
90
+ default:
91
+ fail(`Unknown option "${flag}". Run "acp --help" to see all options.`);
92
+ }
93
+ }
94
+
95
+ return options;
96
+ }
97
+
98
+ // ---------- git helpers ----------
99
+ // Arguments are passed as an array (no shell), so commit messages with
100
+ // quotes, spaces or special characters are always safe.
101
+ function git(args, quiet = false) {
102
+ const result = spawnSync('git', args, {
103
+ stdio: quiet ? 'pipe' : 'inherit',
104
+ encoding: 'utf8',
105
+ });
106
+ if (result.error) {
107
+ if (result.error.code === 'ENOENT') fail('git is not installed or not on your PATH.');
108
+ fail(result.error.message);
109
+ }
110
+ return result;
111
+ }
112
+
113
+ function step(args) {
114
+ const shown = args.map((a) => (/[\s"']/.test(a) ? JSON.stringify(a) : a)).join(' ');
115
+ console.log(cyan(`› git ${shown}`));
116
+ const result = git(args);
117
+ if (result.status !== 0) fail(`"git ${args[0]}" failed (exit code ${result.status}).`);
118
+ }
119
+
120
+ function randomMessage() {
121
+ return messages[Math.floor(Math.random() * messages.length)];
122
+ }
123
+
124
+ // ---------- main ----------
125
+ function main() {
126
+ const { remote, branch, message } = parseArgs(process.argv.slice(2));
127
+
128
+ if (git(['rev-parse', '--is-inside-work-tree'], true).status !== 0) {
129
+ fail('Not inside a git repository.');
130
+ }
131
+
132
+ if (git(['remote', 'get-url', remote], true).status !== 0) {
133
+ fail(`Remote "${remote}" does not exist. Add it with: git remote add ${remote} <url>`);
134
+ }
135
+
136
+ const current = git(['rev-parse', '--abbrev-ref', 'HEAD'], true).stdout.trim();
137
+ if (current && current !== 'HEAD' && current !== branch) {
138
+ console.log(
139
+ yellow(`⚠ You are on "${current}" but pushing "${branch}". ` +
140
+ `Your new commit stays on "${current}" — use "acp -b ${current}" to push it.`)
141
+ );
142
+ }
143
+
144
+ step(['add', '.']);
145
+
146
+ // "git diff --cached --quiet" exits 0 when nothing is staged.
147
+ if (git(['diff', '--cached', '--quiet'], true).status === 0) {
148
+ console.log(yellow('• Nothing new to commit, pushing existing commits.'));
149
+ } else {
150
+ step(['commit', '-m', message || randomMessage()]);
151
+ }
152
+
153
+ step(['push', remote, branch]);
154
+ console.log(green(`✔ Pushed to ${remote}/${branch}`));
155
+ }
156
+
157
+ main();
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ // Edit this list freely — acp picks one at random for each commit.
4
+ module.exports = [
5
+ 'Update project files',
6
+ 'Minor improvements',
7
+ 'Small fixes and tweaks',
8
+ 'Code cleanup',
9
+ 'Refactor for readability',
10
+ 'Work in progress',
11
+ 'Quick update',
12
+ 'Polish things up',
13
+ 'Improve code structure',
14
+ 'Fix minor issues',
15
+ 'Tidy up the codebase',
16
+ 'Incremental progress',
17
+ 'Save progress',
18
+ 'Routine update',
19
+ 'Make small adjustments',
20
+ 'Keep moving forward',
21
+ 'Improve overall quality',
22
+ 'Housekeeping',
23
+ 'Sync latest changes',
24
+ 'Update content',
25
+ 'Various small improvements',
26
+ 'Clean up and reorganize',
27
+ 'Iterate on existing work',
28
+ 'Checkpoint commit',
29
+ 'Apply latest changes',
30
+ ];
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "acp-push",
3
+ "version": "1.0.0",
4
+ "description": "git add, commit (with a random message) and push in one command: acp",
5
+ "bin": {
6
+ "acp": "bin/acp.js"
7
+ },
8
+ "files": [
9
+ "bin",
10
+ "lib"
11
+ ],
12
+ "keywords": [
13
+ "git",
14
+ "cli",
15
+ "add",
16
+ "commit",
17
+ "push",
18
+ "acp"
19
+ ],
20
+ "engines": {
21
+ "node": ">=14"
22
+ },
23
+ "license": "MIT",
24
+ "main": "index.js",
25
+ "directories": {
26
+ "lib": "lib"
27
+ },
28
+ "scripts": {
29
+ "test": "echo \"Error: no test specified\" && exit 1"
30
+ },
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "https://SENODROOM/acp-push.git"
34
+ },
35
+ "author": "Muhammad Saad Amin"
36
+ }