gqtryrun 0.0.1
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/.eslintignore +3 -0
- package/.eslintrc +178 -0
- package/.flowconfig +15 -0
- package/LICENSE +21 -0
- package/README.md +67 -0
- package/app.coffee +15 -0
- package/app.js +31 -0
- package/babel.config.js +6 -0
- package/manifest.js +1 -0
- package/nodemon.json +21 -0
- package/package.json +53 -0
- package/renovate.json +8 -0
- package/resources/prepublish.sh +19 -0
- package/resources/watch.js +207 -0
- package/test.coffee +52 -0
- package/todo.js +4 -0
package/.eslintignore
ADDED
package/.eslintrc
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
{
|
|
2
|
+
"globals": {
|
|
3
|
+
"$ReadOnlyArray": true
|
|
4
|
+
},
|
|
5
|
+
|
|
6
|
+
"parser": "babel-eslint",
|
|
7
|
+
|
|
8
|
+
"plugins": ["prettier"],
|
|
9
|
+
|
|
10
|
+
"env": {
|
|
11
|
+
"es6": true,
|
|
12
|
+
"node": true,
|
|
13
|
+
"jest": true
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
"rules": {
|
|
17
|
+
"block-scoped-var": 0,
|
|
18
|
+
"callback-return": 2,
|
|
19
|
+
"camelcase": [2, {"properties": "always"}],
|
|
20
|
+
"comma-dangle": 0,
|
|
21
|
+
"comma-spacing": 0,
|
|
22
|
+
"complexity": 0,
|
|
23
|
+
"computed-property-spacing": [2, "never"],
|
|
24
|
+
"consistent-return": 0,
|
|
25
|
+
"consistent-this": 0,
|
|
26
|
+
"default-case": 0,
|
|
27
|
+
"dot-location": [2, "property"],
|
|
28
|
+
"dot-notation": 0,
|
|
29
|
+
"eol-last": 2,
|
|
30
|
+
"eqeqeq": 2,
|
|
31
|
+
"func-names": 0,
|
|
32
|
+
"func-style": 0,
|
|
33
|
+
"generator-star-spacing": [0, {"before": true, "after": false}],
|
|
34
|
+
"guard-for-in": 2,
|
|
35
|
+
"handle-callback-err": [2, "error"],
|
|
36
|
+
"id-length": 0,
|
|
37
|
+
"id-match": [2, "^(?:_?[a-zA-Z0-9]*)|[_A-Z0-9]+$"],
|
|
38
|
+
"init-declarations": 0,
|
|
39
|
+
"key-spacing": [2, {"beforeColon": false, "afterColon": true}],
|
|
40
|
+
"keyword-spacing": 2,
|
|
41
|
+
"linebreak-style": 2,
|
|
42
|
+
"lines-around-comment": 0,
|
|
43
|
+
"max-depth": 0,
|
|
44
|
+
"max-nested-callbacks": 0,
|
|
45
|
+
"max-params": 0,
|
|
46
|
+
"max-statements": 0,
|
|
47
|
+
"new-cap": 0,
|
|
48
|
+
"new-parens": 2,
|
|
49
|
+
"newline-after-var": 0,
|
|
50
|
+
"no-alert": 2,
|
|
51
|
+
"no-array-constructor": 2,
|
|
52
|
+
"no-bitwise": 0,
|
|
53
|
+
"no-caller": 2,
|
|
54
|
+
"no-catch-shadow": 0,
|
|
55
|
+
"no-class-assign": 2,
|
|
56
|
+
"no-cond-assign": 2,
|
|
57
|
+
"no-console": 1,
|
|
58
|
+
"no-const-assign": 2,
|
|
59
|
+
"no-constant-condition": 2,
|
|
60
|
+
"no-continue": 0,
|
|
61
|
+
"no-control-regex": 0,
|
|
62
|
+
"no-debugger": 1,
|
|
63
|
+
"no-delete-var": 2,
|
|
64
|
+
"no-div-regex": 2,
|
|
65
|
+
"no-dupe-args": 2,
|
|
66
|
+
"no-dupe-keys": 2,
|
|
67
|
+
"no-duplicate-case": 2,
|
|
68
|
+
"no-else-return": 2,
|
|
69
|
+
"no-empty": 2,
|
|
70
|
+
"no-empty-character-class": 2,
|
|
71
|
+
"no-eq-null": 0,
|
|
72
|
+
"no-eval": 2,
|
|
73
|
+
"no-ex-assign": 2,
|
|
74
|
+
"no-extend-native": 2,
|
|
75
|
+
"no-extra-bind": 2,
|
|
76
|
+
"no-extra-boolean-cast": 2,
|
|
77
|
+
"no-extra-parens": 0,
|
|
78
|
+
"no-extra-semi": 2,
|
|
79
|
+
"no-fallthrough": 2,
|
|
80
|
+
"no-floating-decimal": 2,
|
|
81
|
+
"no-func-assign": 2,
|
|
82
|
+
"no-implicit-coercion": 2,
|
|
83
|
+
"no-implied-eval": 2,
|
|
84
|
+
"no-inline-comments": 0,
|
|
85
|
+
"no-inner-declarations": [2, "functions"],
|
|
86
|
+
"no-invalid-regexp": 2,
|
|
87
|
+
"no-invalid-this": 0,
|
|
88
|
+
"no-irregular-whitespace": 2,
|
|
89
|
+
"no-iterator": 2,
|
|
90
|
+
"no-label-var": 2,
|
|
91
|
+
"no-labels": 0,
|
|
92
|
+
"no-lone-blocks": 2,
|
|
93
|
+
"no-lonely-if": 2,
|
|
94
|
+
"no-loop-func": 0,
|
|
95
|
+
"no-mixed-requires": [2, true],
|
|
96
|
+
"no-mixed-spaces-and-tabs": 2,
|
|
97
|
+
"no-multi-spaces": 2,
|
|
98
|
+
"no-multi-str": 2,
|
|
99
|
+
"no-multiple-empty-lines": 0,
|
|
100
|
+
"no-native-reassign": 0,
|
|
101
|
+
"no-negated-in-lhs": 2,
|
|
102
|
+
"no-nested-ternary": 0,
|
|
103
|
+
"no-new": 2,
|
|
104
|
+
"no-new-func": 0,
|
|
105
|
+
"no-new-object": 2,
|
|
106
|
+
"no-new-require": 2,
|
|
107
|
+
"no-new-wrappers": 2,
|
|
108
|
+
"no-obj-calls": 2,
|
|
109
|
+
"no-octal": 2,
|
|
110
|
+
"no-octal-escape": 2,
|
|
111
|
+
"no-param-reassign": 2,
|
|
112
|
+
"no-path-concat": 2,
|
|
113
|
+
"no-plusplus": 0,
|
|
114
|
+
"no-process-env": 0,
|
|
115
|
+
"no-process-exit": 0,
|
|
116
|
+
"no-proto": 2,
|
|
117
|
+
"no-redeclare": 2,
|
|
118
|
+
"no-regex-spaces": 2,
|
|
119
|
+
"no-restricted-modules": 0,
|
|
120
|
+
"no-return-assign": 2,
|
|
121
|
+
"no-script-url": 2,
|
|
122
|
+
"no-self-compare": 0,
|
|
123
|
+
"no-sequences": 2,
|
|
124
|
+
"no-shadow": 2,
|
|
125
|
+
"no-shadow-restricted-names": 2,
|
|
126
|
+
"no-spaced-func": 2,
|
|
127
|
+
"no-sparse-arrays": 2,
|
|
128
|
+
"no-sync": 2,
|
|
129
|
+
"no-ternary": 0,
|
|
130
|
+
"no-this-before-super": 2,
|
|
131
|
+
"no-throw-literal": 2,
|
|
132
|
+
"no-trailing-spaces": 2,
|
|
133
|
+
"no-undef": 2,
|
|
134
|
+
"no-undef-init": 2,
|
|
135
|
+
"no-undefined": 0,
|
|
136
|
+
"no-underscore-dangle": 0,
|
|
137
|
+
"no-unexpected-multiline": 2,
|
|
138
|
+
"no-unneeded-ternary": 2,
|
|
139
|
+
"no-unreachable": 2,
|
|
140
|
+
"no-unused-expressions": 2,
|
|
141
|
+
"no-unused-vars": [2, {"vars": "all", "args": "after-used"}],
|
|
142
|
+
"no-use-before-define": 0,
|
|
143
|
+
"no-useless-call": 2,
|
|
144
|
+
"no-var": 0,
|
|
145
|
+
"no-void": 2,
|
|
146
|
+
"no-warning-comments": 0,
|
|
147
|
+
"no-with": 2,
|
|
148
|
+
"object-curly-spacing": [0, "always"],
|
|
149
|
+
"object-shorthand": [2, "always"],
|
|
150
|
+
"one-var": [2, "never"],
|
|
151
|
+
"operator-assignment": [2, "always"],
|
|
152
|
+
"prefer-const": 0,
|
|
153
|
+
"prefer-reflect": 0,
|
|
154
|
+
"prefer-spread": 0,
|
|
155
|
+
"quote-props": [2, "as-needed"],
|
|
156
|
+
"radix": 2,
|
|
157
|
+
"require-yield": 2,
|
|
158
|
+
"semi-spacing": [2, {"before": false, "after": true}],
|
|
159
|
+
"sort-vars": 0,
|
|
160
|
+
"space-before-blocks": [2, "always"],
|
|
161
|
+
"space-before-function-paren": [2, {"anonymous": "always", "named": "never"}],
|
|
162
|
+
"space-in-parens": 0,
|
|
163
|
+
"space-infix-ops": [2, {"int32Hint": false}],
|
|
164
|
+
"space-unary-ops": [2, {"words": true, "nonwords": false}],
|
|
165
|
+
"spaced-comment": [2, "always"],
|
|
166
|
+
"strict": 0,
|
|
167
|
+
"use-isnan": 2,
|
|
168
|
+
"valid-jsdoc": 0,
|
|
169
|
+
"valid-typeof": 2,
|
|
170
|
+
"vars-on-top": 0,
|
|
171
|
+
"wrap-iife": 2,
|
|
172
|
+
"wrap-regex": 0,
|
|
173
|
+
"yoda": [2, "never", {"exceptRange": true}],
|
|
174
|
+
|
|
175
|
+
"prettier/prettier": 2
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
package/.flowconfig
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) GraphQL Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# gqtryrun
|
|
2
|
+
|
|
3
|
+
```
|
|
4
|
+
__
|
|
5
|
+
____ _______/ |________ ___.__._______ __ __ ____
|
|
6
|
+
/ ___\ / ____/\ __\_ __ < | |\_ __ \ | \/ \
|
|
7
|
+
/ /_/ >< <_| | | | | | \/\___ | | | \/ | / | \
|
|
8
|
+
\___ / \__ | |__| |__| / ____| |__| |____/|___| /
|
|
9
|
+
/_____/ |__| \/ \/
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Description
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
A never-fail-mechanic for handling try catch inside callbacks and other small scope trys.
|
|
16
|
+
|
|
17
|
+
We all have done it, when callback is silent handling your error and you have no clue why it failed to do anything from the callback.
|
|
18
|
+
This small utility engulf the runtime function in a try catch and print out the error for you using console.error.
|
|
19
|
+
You will never see no error when callback failed to do anything.
|
|
20
|
+
It is also compatible with both sync and async mode in one function. Callback parameter is nullable.
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Getting Started
|
|
24
|
+
|
|
25
|
+
### Dependencies
|
|
26
|
+
|
|
27
|
+
none
|
|
28
|
+
|
|
29
|
+
### Installing
|
|
30
|
+
|
|
31
|
+
* npm install gqtryrun
|
|
32
|
+
|
|
33
|
+
### Executing program
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
tryrun=require("gqtryrun")
|
|
37
|
+
|
|
38
|
+
o={}
|
|
39
|
+
o.query=function(o,cb){
|
|
40
|
+
//your logic
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
tryrun.run(o,cb)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Help
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
see test.coffee for how to use it
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Authors
|
|
53
|
+
|
|
54
|
+
* glidev5
|
|
55
|
+
|
|
56
|
+
## Version History
|
|
57
|
+
|
|
58
|
+
* 0.1
|
|
59
|
+
* Initial Release
|
|
60
|
+
|
|
61
|
+
## License
|
|
62
|
+
|
|
63
|
+
This project is licensed under the MIT License - see the LICENSE.md file for details
|
|
64
|
+
|
|
65
|
+
## Acknowledgments
|
|
66
|
+
|
|
67
|
+
* thank you for taking sometime reading this repo :)
|
package/app.coffee
ADDED
package/app.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Generated by CoffeeScript 2.7.0
|
|
2
|
+
(function() {
|
|
3
|
+
var err, log, runFunc;
|
|
4
|
+
|
|
5
|
+
log = console.log;
|
|
6
|
+
|
|
7
|
+
err = console.error;
|
|
8
|
+
|
|
9
|
+
runFunc = function(query, data, cb) {
|
|
10
|
+
var e, e2;
|
|
11
|
+
try {
|
|
12
|
+
cb = cb || function(e, r) {
|
|
13
|
+
return null;
|
|
14
|
+
};
|
|
15
|
+
return query(data, cb);
|
|
16
|
+
} catch (error) {
|
|
17
|
+
e = error;
|
|
18
|
+
err(e);
|
|
19
|
+
try {
|
|
20
|
+
return cb(e, data);
|
|
21
|
+
} catch (error) {
|
|
22
|
+
e2 = error;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
module.exports = {
|
|
28
|
+
run: runFunc
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
}).call(this);
|
package/babel.config.js
ADDED
package/manifest.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// what is my plan for this project
|
package/nodemon.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"restartable": "rs",
|
|
3
|
+
"ignore": [
|
|
4
|
+
".git",
|
|
5
|
+
"node_modules/**/node_modules"
|
|
6
|
+
],
|
|
7
|
+
"verbose": false,
|
|
8
|
+
"watch": [
|
|
9
|
+
"test/",
|
|
10
|
+
"*.coffee",
|
|
11
|
+
"*.js",
|
|
12
|
+
"*.json"
|
|
13
|
+
],
|
|
14
|
+
"env": {
|
|
15
|
+
"NODE_ENV": "development"
|
|
16
|
+
},
|
|
17
|
+
"ext": "coffee,json",
|
|
18
|
+
"events": {
|
|
19
|
+
"restart": "echo \"App restarted due to:\n'$FILENAME'\" with title \"nodemon\""
|
|
20
|
+
}
|
|
21
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "gqtryrun",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "A never-fail-mechanic for handling try catch inside callbacks and other small scope trys",
|
|
5
|
+
"repository": "git@github.com:goldfiction/gqtryrun.git",
|
|
6
|
+
"contributors": [
|
|
7
|
+
"glidev5 <glidev5@gmail.com> (https://www.linkedin.com/in/grant-li-194a4521/)"
|
|
8
|
+
],
|
|
9
|
+
"private": false,
|
|
10
|
+
"main": "app.js",
|
|
11
|
+
"node_version": "18.20.2",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"dependencies": {},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"gqtest": ">=0.0.17",
|
|
16
|
+
"coffeescript": "2.7.0",
|
|
17
|
+
"nodemon": "3.1.10"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"start": "node --openssl-legacy-provider --require coffeescript/register app.coffee",
|
|
21
|
+
"test": "node --require coffeescript/register test.coffee",
|
|
22
|
+
"test:watch": "nodemon --delay 10 -q -x \"npm test\"",
|
|
23
|
+
"test:slow": "mocha --openssl-legacy-provider -require coffeescript/register --no-color --reporter min -t 20000 test/test.slow.coffee",
|
|
24
|
+
"install:nobin": "npm install --no-bin-links --no-optional --omit=optional --ignore-scripts",
|
|
25
|
+
"install:prod": "npm install --production",
|
|
26
|
+
"install:prod2": "npm install --omit=dev --no-bin-links",
|
|
27
|
+
"git": "git add .; git commit -m \"update\"; echo gitted...",
|
|
28
|
+
"git:push": "git push origin master & git push nodegit master & git push bitbucket master & echo pushed...",
|
|
29
|
+
"git:setup": "git config --global user.name \"username\";git config --global user.email \"username@gmail.com\";git branch --set-upstream-to=origin/master master;",
|
|
30
|
+
"test:dl": "npm run lint && npm run check && npm run testonly",
|
|
31
|
+
"test:ci": "npm run lint && npm run check && npm run testonly -- --coverage",
|
|
32
|
+
"lint": "eslint .",
|
|
33
|
+
"check": "flow check --max-warnings 0",
|
|
34
|
+
"build": "babel src --ignore src/__tests__ --out-dir dist/ ; cp src/index.js dist/index.js.flow ; cp src/index.d.ts dist/",
|
|
35
|
+
"watch": "babel resources/watch.js | node",
|
|
36
|
+
"testonly": "jest src",
|
|
37
|
+
"prerelease": ". ./resources/prepublish.sh",
|
|
38
|
+
"release": "changeset publish"
|
|
39
|
+
},
|
|
40
|
+
"prettier": {
|
|
41
|
+
"arrowParens": "avoid",
|
|
42
|
+
"singleQuote": true,
|
|
43
|
+
"trailingComma": "all",
|
|
44
|
+
"overrides": [
|
|
45
|
+
{
|
|
46
|
+
"files": "src/**/*.js",
|
|
47
|
+
"options": {
|
|
48
|
+
"parser": "babel-flow"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
}
|
package/renovate.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Remove existing build artifacts
|
|
2
|
+
rm -rf dist;
|
|
3
|
+
|
|
4
|
+
# Build before publishing
|
|
5
|
+
npm run build;
|
|
6
|
+
|
|
7
|
+
# When Travis CI publishes to NPM, the published files are available in the root
|
|
8
|
+
# directory, which produces a cleaner distribution.
|
|
9
|
+
#
|
|
10
|
+
cp dist/* .
|
|
11
|
+
|
|
12
|
+
# Ensure a vanilla package.json before deploying so other tools do not interpret
|
|
13
|
+
# The built output as requiring any further transformation.
|
|
14
|
+
node -e "var package = require('./package.json'); \
|
|
15
|
+
delete package.scripts; \
|
|
16
|
+
delete package.devDependencies; \
|
|
17
|
+
delete package.publishConfig; \
|
|
18
|
+
require('fs').writeFileSync('dist/package.json', JSON.stringify(package, null, 2));"
|
|
19
|
+
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import sane from 'sane';
|
|
3
|
+
import { resolve as resolvePath } from 'path';
|
|
4
|
+
import { spawn } from 'child_process';
|
|
5
|
+
import flowBinPath from 'flow-bin';
|
|
6
|
+
|
|
7
|
+
process.env.PATH += ':./node_modules/.bin';
|
|
8
|
+
|
|
9
|
+
var cmd = resolvePath(__dirname);
|
|
10
|
+
var srcDir = resolvePath(cmd, './src');
|
|
11
|
+
|
|
12
|
+
function exec(command, options) {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
var child = spawn(command, options, {
|
|
15
|
+
cmd,
|
|
16
|
+
env: process.env,
|
|
17
|
+
stdio: 'inherit',
|
|
18
|
+
});
|
|
19
|
+
child.on('exit', code => {
|
|
20
|
+
if (code === 0) {
|
|
21
|
+
resolve(true);
|
|
22
|
+
} else {
|
|
23
|
+
reject(new Error('Error code: ' + code));
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
var flowServer = spawn(flowBinPath, ['server'], {
|
|
30
|
+
cmd,
|
|
31
|
+
env: process.env,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
var watcher = sane(srcDir, { glob: ['**/*.js'] })
|
|
35
|
+
.on('ready', startWatch)
|
|
36
|
+
.on('add', changeFile)
|
|
37
|
+
.on('delete', deleteFile)
|
|
38
|
+
.on('change', changeFile);
|
|
39
|
+
|
|
40
|
+
process.on('SIGINT', () => {
|
|
41
|
+
watcher.close();
|
|
42
|
+
flowServer.kill();
|
|
43
|
+
console.log(CLEARLINE + yellow(invert('stopped watching')));
|
|
44
|
+
process.exit();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
var isChecking;
|
|
48
|
+
var needsCheck;
|
|
49
|
+
var toCheck = {};
|
|
50
|
+
var timeout;
|
|
51
|
+
|
|
52
|
+
function startWatch() {
|
|
53
|
+
process.stdout.write(CLEARSCREEN + green(invert('watching...')));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function changeFile(filepath, root, stat) {
|
|
57
|
+
if (!stat.isDirectory()) {
|
|
58
|
+
toCheck[filepath] = true;
|
|
59
|
+
debouncedCheck();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function deleteFile(filepath) {
|
|
64
|
+
delete toCheck[filepath];
|
|
65
|
+
debouncedCheck();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function debouncedCheck() {
|
|
69
|
+
needsCheck = true;
|
|
70
|
+
clearTimeout(timeout);
|
|
71
|
+
timeout = setTimeout(guardedCheck, 250);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function guardedCheck() {
|
|
75
|
+
if (isChecking || !needsCheck) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
isChecking = true;
|
|
79
|
+
var filepaths = Object.keys(toCheck);
|
|
80
|
+
toCheck = {};
|
|
81
|
+
needsCheck = false;
|
|
82
|
+
checkFiles(filepaths).then(() => {
|
|
83
|
+
isChecking = false;
|
|
84
|
+
process.nextTick(guardedCheck);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function checkFiles(filepaths) {
|
|
89
|
+
console.log('\u001b[2J');
|
|
90
|
+
|
|
91
|
+
return parseFiles(filepaths)
|
|
92
|
+
.then(() => runTests(filepaths))
|
|
93
|
+
.then(testSuccess =>
|
|
94
|
+
lintFiles(filepaths).then(lintSuccess =>
|
|
95
|
+
typecheckStatus().then(
|
|
96
|
+
typecheckSuccess => testSuccess && lintSuccess && typecheckSuccess,
|
|
97
|
+
),
|
|
98
|
+
),
|
|
99
|
+
)
|
|
100
|
+
.catch(() => false)
|
|
101
|
+
.then(success => {
|
|
102
|
+
process.stdout.write(
|
|
103
|
+
'\n' + (success ? '' : '\x07') + green(invert('watching...')),
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Checking steps
|
|
109
|
+
|
|
110
|
+
function parseFiles(filepaths) {
|
|
111
|
+
console.log('Checking Syntax');
|
|
112
|
+
|
|
113
|
+
return Promise.all(
|
|
114
|
+
filepaths.map(filepath => {
|
|
115
|
+
if (isJS(filepath) && !isTest(filepath)) {
|
|
116
|
+
return exec('babel', [
|
|
117
|
+
'--optional',
|
|
118
|
+
'runtime',
|
|
119
|
+
'--out-file',
|
|
120
|
+
'/dev/null',
|
|
121
|
+
srcPath(filepath),
|
|
122
|
+
]);
|
|
123
|
+
}
|
|
124
|
+
}),
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function runTests(filepaths) {
|
|
129
|
+
console.log('\nRunning Tests');
|
|
130
|
+
|
|
131
|
+
return exec(
|
|
132
|
+
'jest',
|
|
133
|
+
allTests(filepaths) ? filepaths.map(srcPath) : ['src'],
|
|
134
|
+
).catch(() => false);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function lintFiles(filepaths) {
|
|
138
|
+
console.log('Linting Code\n');
|
|
139
|
+
|
|
140
|
+
return filepaths.reduce(
|
|
141
|
+
(prev, filepath) =>
|
|
142
|
+
prev.then(prevSuccess => {
|
|
143
|
+
if (isJS(filepath)) {
|
|
144
|
+
process.stdout.write(' ' + filepath + ' ...');
|
|
145
|
+
return exec('eslint', [srcPath(filepath)])
|
|
146
|
+
.catch(() => false)
|
|
147
|
+
.then(success => {
|
|
148
|
+
console.log(
|
|
149
|
+
CLEARLINE + ' ' + (success ? CHECK : X) + ' ' + filepath,
|
|
150
|
+
);
|
|
151
|
+
return prevSuccess && success;
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
return prevSuccess;
|
|
155
|
+
}),
|
|
156
|
+
Promise.resolve(true),
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function typecheckStatus() {
|
|
161
|
+
console.log('\nType Checking\n');
|
|
162
|
+
return exec(flowBinPath, ['status']).catch(() => false);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Filepath
|
|
166
|
+
|
|
167
|
+
function srcPath(filepath) {
|
|
168
|
+
return resolvePath(srcDir, filepath);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Predicates
|
|
172
|
+
|
|
173
|
+
function isJS(filepath) {
|
|
174
|
+
return filepath.indexOf('.js') === filepath.length - 3;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function allTests(filepaths) {
|
|
178
|
+
return filepaths.length > 0 && filepaths.every(isTest);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function isTest(filepath) {
|
|
182
|
+
return isJS(filepath) && filepath.indexOf('__tests__/') !== -1;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Print helpers
|
|
186
|
+
|
|
187
|
+
var CLEARSCREEN = '\u001b[2J';
|
|
188
|
+
var CLEARLINE = '\r\x1B[K';
|
|
189
|
+
var CHECK = green('\u2713');
|
|
190
|
+
var X = red('\u2718');
|
|
191
|
+
|
|
192
|
+
function invert(str) {
|
|
193
|
+
return `\u001b[7m ${str} \u001b[27m`;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function red(str) {
|
|
197
|
+
return `\x1B[K\u001b[1m\u001b[31m${str}\u001b[39m\u001b[22m`;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function green(str) {
|
|
201
|
+
return `\x1B[K\u001b[1m\u001b[32m${str}\u001b[39m\u001b[22m`;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function yellow(str) {
|
|
205
|
+
return `\x1B[K\u001b[1m\u001b[33m${str}\u001b[39m\u001b[22m`;
|
|
206
|
+
}
|
|
207
|
+
|
package/test.coffee
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
tryrun=require './app.coffee'
|
|
2
|
+
assert=require 'assert'
|
|
3
|
+
tests=require 'gqtest'
|
|
4
|
+
|
|
5
|
+
it=tests.it
|
|
6
|
+
run=tests.doRun
|
|
7
|
+
|
|
8
|
+
# dummy test for code integrity
|
|
9
|
+
it "should be able to run",(done)->
|
|
10
|
+
done()
|
|
11
|
+
|
|
12
|
+
it "should be able to safe run async",(done)->
|
|
13
|
+
o={}
|
|
14
|
+
o.a=1
|
|
15
|
+
o.b=2
|
|
16
|
+
o.query=(o,cb)->
|
|
17
|
+
cb null,o.a+o.b
|
|
18
|
+
tryrun.run o.query,o,(e,r)->
|
|
19
|
+
assert.equal r,o.a+o.b
|
|
20
|
+
done e
|
|
21
|
+
|
|
22
|
+
it "should be able to fail run async",(done)->
|
|
23
|
+
o={}
|
|
24
|
+
o.a=1
|
|
25
|
+
o.b=2
|
|
26
|
+
o.query=(o,cb)->
|
|
27
|
+
cb null,ddd
|
|
28
|
+
tryrun.run o.query,o,(e,r)->
|
|
29
|
+
assert.equal e.message,"ddd is not defined"
|
|
30
|
+
done !e
|
|
31
|
+
|
|
32
|
+
it "should be able to safe run sync",(done)->
|
|
33
|
+
o={}
|
|
34
|
+
o.a=1
|
|
35
|
+
o.b=2
|
|
36
|
+
o.query=(o,cb)->
|
|
37
|
+
return o.a+o.b
|
|
38
|
+
ret=tryrun.run o.query,o
|
|
39
|
+
assert.equal ret,o.a+o.b
|
|
40
|
+
done null
|
|
41
|
+
|
|
42
|
+
it "should be able to fail run sync",(done)->
|
|
43
|
+
o={}
|
|
44
|
+
o.a=1
|
|
45
|
+
o.b=2
|
|
46
|
+
o.query=(o,cb)->
|
|
47
|
+
return ddd
|
|
48
|
+
ret=tryrun.run o.query,o
|
|
49
|
+
#assert.equal e.message,"ddd is not defined"
|
|
50
|
+
done null
|
|
51
|
+
|
|
52
|
+
run()
|
package/todo.js
ADDED