happy 0.13.0 → 0.13.4

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.
@@ -0,0 +1 @@
1
+ custom: https://www.paypal.me/franciscopresencia/19
package/README.md CHANGED
@@ -67,26 +67,122 @@ $ happy --help
67
67
 
68
68
  It makes sure your project is ready to deploy, and then deploy it. For this, these are the steps:
69
69
 
70
- - "Building project": run `npm run build` *if* the `"build"` script is found in your `package.json`.
71
- - "Linting": run `npm run lint` *if* the `"lint"` script is found in the project `package.json`.
72
- - "Testing project": run `npm test` *if* the `"test"` script is found in the project `package.json`.
73
- - "Saving changes": add all of the files with git, equivalent to `git add . && git commit -m "Saved on $TIME"`. Provide a message for a custom git message.
74
- - "Downloading latest": git pull
75
- - "Uploading changes": git push
76
- - "Publish to npm": _only_ if the `--publish` flag is passed, publish it to npm.
70
+ - ["Building project"](#building-project): run `npm run build` *if* the `"build"` script is found in your `package.json`.
71
+ - ["Linting"](#linting): run `npm run lint` *if* the `"lint"` script is found in the project `package.json`.
72
+ - ["Testing project"](#testing-project): run `npm test` *if* the `"test"` script is found in the project `package.json`.
73
+ - ["Saving changes"](#saving-changes): add all of the files with git, equivalent to `git add . && git commit -m "Saved on $TIME"`. Provide a message for a custom git message.
74
+ - ["Downloading latest"](#downloading-latest): git pull
75
+ - ["Uploading changes"](#uploading-changes): git push
76
+ - ["Publish to npm"](#publish-to-npm): _only_ if the `--publish` flag is passed, publish it to npm.
77
77
 
78
78
 
79
- Run it with a string to use it as a commit string:
79
+
80
+ ### Building project
81
+
82
+ Run the `npm run build` script *if* this script is found in your `package.json` configuration. Example:
83
+
84
+ ```json
85
+ {
86
+ "scripts": {
87
+ "build": "rollup -c"
88
+ }
89
+ }
90
+ ```
91
+
92
+ This step will be **skipped** if:
93
+ - The script `"build"` is not found in the project `package.json`.
94
+ - The flag `--now` was passed.
95
+
96
+
97
+
98
+ ### Linting
99
+
100
+ Run the `npm run lint` script *if* this script is found in your `package.json` configuration. Example:
101
+
102
+ ```json
103
+ {
104
+ "scripts": {
105
+ "lint": "eslint"
106
+ }
107
+ }
108
+ ```
109
+
110
+ This step will be **skipped** if:
111
+ - The script `"lint"` is not found in the project `package.json`.
112
+ - The flag `--now` was passed.
113
+
114
+
115
+
116
+ ### Testing project
117
+
118
+ Run the `npm test` script *if* this script is found in your `package.json` configuration. Example:
119
+
120
+ ```json
121
+ {
122
+ "scripts": {
123
+ "test": "jest"
124
+ }
125
+ }
126
+ ```
127
+
128
+ The test script will also set the environment variable CI=true to avoid [some common issues](https://stackoverflow.com/a/56917151/938236).
129
+
130
+ This step will be **skipped** if:
131
+ - The script `"test"` is not found in the project `package.json`.
132
+ - The flag `--now` was passed.
133
+
134
+
135
+
136
+ ### Saving Changes
137
+
138
+ This is the equivalent of _adding_ and _commiting_ the changed files to Git. The message for the commit is the string that you pass:
80
139
 
81
140
  ```bash
82
141
  happy "Added that new cool feature"
83
142
  ```
84
143
 
85
- Add a `--now` to skip building, linting and testing. It _only_ runs these if they are found, so no need for `--now` if you don't have any of these npm scripts:
144
+ When no string is provided, it will save the changes with a generic commit with the current timestamp like:
86
145
 
87
- ```bash
88
- happy --now
89
146
  ```
147
+ Saved on 2020-08-13T10:20:00Z
148
+ ```
149
+
150
+ This step will be **skipped** if:
151
+ - There are no changes to add or commit.
152
+ - The changes were already commited.
153
+
154
+
155
+
156
+ ### Downloading latest
157
+
158
+ Try to pull the latest changes from the remote repo to combine them locally. It will exit if there's a problem with the merge so that you can merge it manually.
159
+
160
+ > This step might take longer than the others since it talks to your git server.
161
+
162
+ This step will be **skipped** if:
163
+ - There were no changes in the remote repo (you are up to date).
164
+
165
+ This step will **throw an error** if:
166
+ - The origin is not set.
167
+
168
+ > TODO: ask/fix the origin if it's not set
169
+
170
+
171
+
172
+ ### Uploading changes
173
+
174
+ Take all of your changes and upload them to the `origin` that is set in your project. This is specially useful when combined with e.g. Heroku, and you set heroku as the origin, since it will also deploy the full website.
175
+
176
+ This step takes longer than the others since it's talking to your git server.
177
+
178
+ This step will be **skipped** if:
179
+ - There were no changes in the local repo.
180
+
181
+
182
+
183
+ ### Publish to npm
184
+
185
+ > You need to have the library `np` installed for this, please do `npm i np -g`
90
186
 
91
187
  Add a `--publish VERSION` flag to publish the current package to npm with [np](https://github.com/sindresorhus/np#readme):
92
188
 
@@ -107,3 +203,5 @@ happy --major
107
203
 
108
204
  happy --publish 5.0.0
109
205
  ```
206
+
207
+
package/index.js CHANGED
@@ -11,7 +11,7 @@ const {
11
11
  pull,
12
12
  push,
13
13
  save,
14
- test
14
+ test,
15
15
  } = require("./src/index.js");
16
16
 
17
17
  const { flags, input } = meow(
@@ -48,22 +48,22 @@ const { flags, input } = meow(
48
48
  flags: {
49
49
  now: {
50
50
  type: "boolean",
51
- alias: "n"
51
+ alias: "n",
52
52
  },
53
53
  publish: {
54
54
  type: "string",
55
- alias: "p"
55
+ alias: "p",
56
56
  },
57
57
  patch: {
58
- type: "boolean"
58
+ type: "boolean",
59
59
  },
60
60
  minor: {
61
- type: "boolean"
61
+ type: "boolean",
62
62
  },
63
63
  major: {
64
- type: "boolean"
65
- }
66
- }
64
+ type: "boolean",
65
+ },
66
+ },
67
67
  }
68
68
  );
69
69
 
@@ -86,8 +86,8 @@ if (flags.publish) {
86
86
  action.push(publish);
87
87
  }
88
88
 
89
- const tasks = new listr(action.map(task => task({ flags, input })));
89
+ const tasks = new listr(action.map((task) => task({ flags, input })));
90
90
 
91
91
  analyze()
92
- .then(ctx => tasks.run(ctx))
93
- .catch(error => console.error(error));
92
+ .then((ctx) => tasks.run(ctx))
93
+ .catch((error) => console.error(error));
package/package.json CHANGED
@@ -1,13 +1,16 @@
1
1
  {
2
2
  "name": "happy",
3
- "version": "0.13.0",
3
+ "version": "0.13.4",
4
4
  "description": "Happy simplifies your day-to-day git workflow",
5
5
  "author": "Francisco Presencia <public@francisco.io> (https://francisco.io/)",
6
- "main": "index.js",
7
- "scripts": {},
8
- "bin": {
9
- "happy": "index.js"
6
+ "funding": {
7
+ "url": "https://www.paypal.me/franciscopresencia/19"
10
8
  },
9
+ "license": "MIT",
10
+ "scripts": {},
11
+ "homepage": "https://github.com/franciscop/happy",
12
+ "repository": "https://github.com:franciscop/happy.git",
13
+ "bugs": "https://github.com/franciscop/happy/issues",
11
14
  "keywords": [
12
15
  "happy",
13
16
  "command",
@@ -16,11 +19,13 @@
16
19
  "save",
17
20
  "deploy"
18
21
  ],
19
- "homepage": "https://github.com/franciscop/happy",
20
- "repository": "git@github.com:franciscop/happy.git",
21
- "license": "MIT",
22
+ "bin": {
23
+ "happy": "index.js"
24
+ },
25
+ "main": "index.js",
22
26
  "dependencies": {
23
27
  "atocha": "^1.2.0",
28
+ "cross-env": "^7.0.2",
24
29
  "files": "^1.0.0",
25
30
  "listr": "^0.14.3",
26
31
  "meow": "^5.0.0"
package/src/analyze.js CHANGED
@@ -2,7 +2,7 @@
2
2
  const cmd = require("atocha");
3
3
  const { exists, read } = require("files");
4
4
 
5
- module.exports = async ctx => {
5
+ module.exports = async (ctx) => {
6
6
  if (!(await exists("package.json"))) return {};
7
7
  const pkg = await read("package.json");
8
8
  return { pkg: JSON.parse(pkg) };
package/src/build.js CHANGED
@@ -4,11 +4,11 @@ const { stderrok } = require("./helpers");
4
4
 
5
5
  let test = "jest";
6
6
 
7
- module.exports = cli => ({
7
+ module.exports = (cli) => ({
8
8
  title: "Building project",
9
- skip: async ctx => {
9
+ skip: async (ctx) => {
10
10
  if (!ctx.pkg) return true;
11
11
  if (!ctx.pkg.scripts.build) return true;
12
12
  },
13
- task: async ctx => cmd("npm run build").catch(stderrok)
13
+ task: async (ctx) => cmd("npm run build").catch(stderrok),
14
14
  });
package/src/helpers.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // Accept these errors
2
- exports.wtf = err => {
2
+ exports.wtf = (err) => {
3
3
  if (/branch\s+master\s+-> FETCH_HEAD/.test(err.message)) return;
4
4
  if (/master -> master/.test(err.message)) return;
5
5
  if (/Everything up-to-date/.test(err.message)) return;
@@ -7,7 +7,7 @@ exports.wtf = err => {
7
7
  };
8
8
 
9
9
  // Only throw if the error is not 0
10
- exports.stderrok = error => {
10
+ exports.stderrok = (error) => {
11
11
  // 0 or undefined should be ignored
12
12
  if (!error.code) return;
13
13
  throw error;
package/src/index.js CHANGED
@@ -15,5 +15,5 @@ module.exports = {
15
15
  pull,
16
16
  push,
17
17
  save,
18
- test
18
+ test,
19
19
  };
package/src/lint.js CHANGED
@@ -2,18 +2,20 @@ const cmd = require("atocha");
2
2
  const { read } = require("files");
3
3
  const { stderrok } = require("./helpers");
4
4
 
5
- module.exports = cli => ({
5
+ const ci = "export CI=true || set CI=true&&";
6
+
7
+ module.exports = (cli) => ({
6
8
  title: "Linting",
7
- skip: async ctx => {
9
+ skip: async (ctx) => {
8
10
  if (!ctx.pkg) return true;
9
11
  if (!ctx.pkg.scripts.lint && !ctx.pkg.scripts.linter) return true;
10
12
  },
11
- task: async ctx => {
13
+ task: async (ctx) => {
12
14
  if (ctx.pkg.scripts.lint) {
13
- return await cmd("npm run lint").catch(stderrok);
15
+ return await cmd(`${ci} npm run lint`).catch(stderrok);
14
16
  }
15
17
  if (ctx.pkg.scripts.linter) {
16
- return await cmd("npm run linter").catch(stderrok);
18
+ return await cmd(`${ci} npm run linter`).catch(stderrok);
17
19
  }
18
- }
20
+ },
19
21
  });
package/src/publish.js CHANGED
@@ -1,9 +1,9 @@
1
1
  const cmd = require("atocha");
2
2
  const { read } = require("files");
3
3
 
4
- module.exports = cli => ({
4
+ module.exports = (cli) => ({
5
5
  title: "Publish to npm",
6
- skip: async ctx => {
6
+ skip: async (ctx) => {
7
7
  if (!cli.flags.publish) return true;
8
8
  // 5.0.0
9
9
  if (!/^\d+\.\d+\.\d+$/.test(await cmd(`np --version`))) {
@@ -11,7 +11,7 @@ module.exports = cli => ({
11
11
  }
12
12
  return false;
13
13
  },
14
- task: async ctx => {
14
+ task: async (ctx) => {
15
15
  await cmd(`np ${cli.flags.publish} --yolo --no-release-draft`);
16
- }
16
+ },
17
17
  });
package/src/pull.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const cmd = require("atocha");
2
2
  const { wtf } = require("./helpers");
3
3
 
4
- module.exports = cli => ({
4
+ module.exports = (cli) => ({
5
5
  title: "Downloading latest",
6
6
  skip: async () => {
7
7
  const status = await cmd(`git status`);
@@ -10,5 +10,5 @@ module.exports = cli => ({
10
10
  const updated = /Your branch is up to date with/.test(status);
11
11
  if (updated) return true;
12
12
  },
13
- task: async () => await cmd(`git pull origin master`).catch(wtf)
13
+ task: async () => await cmd(`git pull origin master`).catch(wtf),
14
14
  });
package/src/push.js CHANGED
@@ -1,12 +1,12 @@
1
1
  const cmd = require("atocha");
2
2
  const { wtf } = require("./helpers");
3
3
 
4
- module.exports = cli => ({
4
+ module.exports = (cli) => ({
5
5
  title: "Uploading changes",
6
6
  skip: async () => {
7
7
  const status = await cmd(`git status`);
8
8
  const hasCommited = /Your branch is ahead of/.test(status);
9
9
  if (!hasCommited) return true;
10
10
  },
11
- task: async () => await cmd(`git push`).catch(wtf)
11
+ task: async () => await cmd(`git push`).catch(wtf),
12
12
  });
package/src/save.js CHANGED
@@ -5,17 +5,18 @@ const { stderrok } = require("./helpers");
5
5
  // ISO 8601 without milliseconds (which is still ISO 8601)
6
6
  const time = () => new Date().toISOString().replace(/\.[0-9]{3}/, "");
7
7
 
8
- module.exports = cli => ({
8
+ module.exports = (cli) => ({
9
9
  title: "Saving changes",
10
10
  skip: async () => {
11
11
  const status = await cmd(`git status`);
12
- const hasEdited = /Changes not staged for commit/.test(status);
13
- const hasUncommited = /Changes to be committed/.test(status);
14
- if (!hasEdited && !hasUncommited) return true;
12
+ const hasAdded = /untracked files present/i.test(status);
13
+ const hasEdited = /Changes not staged for commit/i.test(status);
14
+ const hasUncommited = /Changes to be committed/i.test(status);
15
+ if (!hasAdded && !hasEdited && !hasUncommited) return true;
15
16
  },
16
17
  task: async () => {
17
18
  const message = cli.input[0] || `Saved on ${time()}`;
18
19
  await cmd(`git add . -A`).catch(stderrok);
19
20
  return await cmd(`git commit -m "${message}"`).catch(stderrok);
20
- }
21
+ },
21
22
  });
package/src/test.js CHANGED
@@ -2,11 +2,13 @@ const cmd = require("atocha");
2
2
  const { read } = require("files");
3
3
  const { stderrok } = require("./helpers");
4
4
 
5
- module.exports = cli => ({
5
+ const ci = "export CI=true || set CI=true&&";
6
+
7
+ module.exports = (cli) => ({
6
8
  title: "Testing project",
7
- skip: async ctx => {
9
+ skip: async (ctx) => {
8
10
  if (!ctx.pkg) return true;
9
11
  if (!ctx.pkg.scripts.test) return true;
10
12
  },
11
- task: async ctx => cmd("npm run test").catch(stderrok)
13
+ task: async (ctx) => cmd(`${ci} npm run test`).catch(stderrok),
12
14
  });