Skip to content

Commit 0aa8daa

Browse files
authored
Prettier (#39)
* Setup an automatic formatter * better * check * Prettier * turn the CI green to have reviews * fix package-lock.json * format
1 parent 7a0288a commit 0aa8daa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+3329
-2280
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- run:
2727
name: "run checks"
2828
command: |
29-
npm ci && npm run license-check
29+
npm ci && npm run license-check && npm run prettier-check
3030
- run:
3131
name: "check vulnerabilities in transitive dependencies"
3232
command: |

.prettierignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package.json
2+
package-lock.json
3+
jsdoc.json

.prettierrc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"printWidth": 80,
3+
"singleQuote": true,
4+
"tabWidth": 2,
5+
"semi": true,
6+
"trailingComma": "all"
7+
}

package-lock.json

+21-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
{
2+
"name": "akkaserverless-javascript-sdk",
23
"devDependencies": {
3-
"license-check-and-add": "^4.0.2"
4+
"license-check-and-add": "^4.0.2",
5+
"prettier": "^2.3.1"
46
},
57
"scripts": {
68
"license-check": "license-check-and-add check -f build/license.json",
7-
"license-add": "license-check-and-add add -f build/license.json"
9+
"license-add": "license-check-and-add add -f build/license.json",
10+
"prettier-format": "prettier --config .prettierrc 'sdk/**/*.js' --write",
11+
"prettier-check": "prettier --config .prettierrc 'sdk/**/*.js' --check"
812
}
913
}

sdk/bin/compile-descriptor.js

+39-23
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,67 @@
11
#!/usr/bin/env node
22

3-
const path = require("path");
3+
const path = require('path');
44
const { execFileSync } = require('child_process');
5-
const fs = require("fs");
5+
const fs = require('fs');
66

7-
const protoc = path.join(__dirname, "..", "protoc", "bin", "protoc" + (process.platform === "win32" ? ".exe" : ""));
7+
const protoc = path.join(
8+
__dirname,
9+
'..',
10+
'protoc',
11+
'bin',
12+
'protoc' + (process.platform === 'win32' ? '.exe' : ''),
13+
);
814
const builtInPaths = [
9-
path.join(__dirname, "..", "proto"),
10-
path.join(__dirname, "..", "protoc", "include")
15+
path.join(__dirname, '..', 'proto'),
16+
path.join(__dirname, '..', 'protoc', 'include'),
1117
];
1218

1319
const userArgs = process.argv.slice(2);
1420

15-
const protocArgs = [
16-
"--include_imports"
17-
].concat(builtInPaths.map(path => "--proto_path=" + path));
21+
const protocArgs = ['--include_imports'].concat(
22+
builtInPaths.map((path) => '--proto_path=' + path),
23+
);
1824

19-
if (!userArgs.some(arg => arg.startsWith("--descriptor_set_out"))) {
20-
protocArgs.push("--descriptor_set_out=user-function.desc");
25+
if (!userArgs.some((arg) => arg.startsWith('--descriptor_set_out'))) {
26+
protocArgs.push('--descriptor_set_out=user-function.desc');
2127
}
2228

23-
if (!userArgs.includes("--include_source_info")) {
24-
protocArgs.push("--include_source_info");
29+
if (!userArgs.includes('--include_source_info')) {
30+
protocArgs.push('--include_source_info');
2531
}
2632

2733
// We need to ensure that the files passed in is on the proto path. The user may have already ensured this by passing
2834
// their own proto path, but if not, we detect that, and add the files parent directory as a proto path.
29-
const filesToCompile = userArgs.filter(arg => !arg.startsWith("-") && !arg.startsWith("@"));
35+
const filesToCompile = userArgs.filter(
36+
(arg) => !arg.startsWith('-') && !arg.startsWith('@'),
37+
);
3038
const protoPaths = userArgs
31-
.filter(arg => arg.startsWith("-I") || arg.startsWith("--proto_path="))
32-
.map(arg => {
33-
if (arg.startsWith("-I")) {
39+
.filter((arg) => arg.startsWith('-I') || arg.startsWith('--proto_path='))
40+
.map((arg) => {
41+
if (arg.startsWith('-I')) {
3442
return arg.substring(2);
3543
} else {
36-
return arg.substring("--proto_path=".length);
44+
return arg.substring('--proto_path='.length);
3745
}
3846
});
39-
const notOnProtoPath = filesToCompile.filter(file => {
47+
const notOnProtoPath = filesToCompile.filter((file) => {
4048
// We mark this file as not on the proto path if it doesn't start with any of the passed in proto paths,
4149
// and it exists.
42-
return protoPaths.findIndex(p => file.startsWith(p + path.sep)) === -1 &&
43-
fs.existsSync(file);
50+
return (
51+
protoPaths.findIndex((p) => file.startsWith(p + path.sep)) === -1 &&
52+
fs.existsSync(file)
53+
);
4454
});
45-
const additionalProtoPaths = [...new Set(notOnProtoPath.map(file => "--proto_path=" + path.dirname(file)))];
55+
const additionalProtoPaths = [
56+
...new Set(
57+
notOnProtoPath.map((file) => '--proto_path=' + path.dirname(file)),
58+
),
59+
];
4660
protocArgs.push(...additionalProtoPaths);
4761

4862
protocArgs.push(...userArgs);
4963

50-
console.log("Compiling descriptor with command: " + protoc + " " + protocArgs.join(" "));
51-
execFileSync(protoc, protocArgs);
64+
console.log(
65+
'Compiling descriptor with command: ' + protoc + ' ' + protocArgs.join(' '),
66+
);
67+
execFileSync(protoc, protocArgs);

sdk/bin/download-protoc.js

+56-43
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,99 @@
11
#!/usr/bin/env node
22

3-
const request = require("request");
4-
const unzipper = require("unzipper");
5-
const mkdirp = require("mkdirp");
6-
const path = require("path");
7-
const fs = require("fs");
8-
const rimraf = require("rimraf");
3+
const request = require('request');
4+
const unzipper = require('unzipper');
5+
const mkdirp = require('mkdirp');
6+
const path = require('path');
7+
const fs = require('fs');
8+
const rimraf = require('rimraf');
99

10-
const downloadUrlPrefix = "https://github.com/protocolbuffers/protobuf/releases/download/v";
11-
const protocVersion = "3.15.6";
10+
const downloadUrlPrefix =
11+
'https://github.com/protocolbuffers/protobuf/releases/download/v';
12+
const protocVersion = '3.15.6';
1213
function makeDownloadFile(platformArch) {
13-
return "protoc-" + protocVersion + "-" + platformArch + ".zip";
14+
return 'protoc-' + protocVersion + '-' + platformArch + '.zip';
1415
}
1516
function determineDownloadFile() {
1617
switch (process.platform) {
17-
case "linux":
18+
case 'linux':
1819
switch (process.arch) {
19-
case "arm64":
20-
return makeDownloadFile("linux-aarch_64");
21-
case "ppc64":
22-
return makeDownloadFile("linux-ppcle_64");
23-
case "x32":
24-
return makeDownloadFile("linux-x86_32");
25-
case "x64":
26-
return makeDownloadFile("linux-x86_64");
20+
case 'arm64':
21+
return makeDownloadFile('linux-aarch_64');
22+
case 'ppc64':
23+
return makeDownloadFile('linux-ppcle_64');
24+
case 'x32':
25+
return makeDownloadFile('linux-x86_32');
26+
case 'x64':
27+
return makeDownloadFile('linux-x86_64');
2728
}
2829
break;
29-
case "win32":
30+
case 'win32':
3031
switch (process.arch) {
31-
case "x32":
32-
return makeDownloadFile("win32");
33-
case "x64":
34-
return makeDownloadFile("win64");
32+
case 'x32':
33+
return makeDownloadFile('win32');
34+
case 'x64':
35+
return makeDownloadFile('win64');
3536
}
3637
break;
37-
case "darwin":
38+
case 'darwin':
3839
switch (process.arch) {
39-
case "x32":
40-
return makeDownloadFile("osx-x86_32");
41-
case "x64":
42-
return makeDownloadFile("osx-x86_64");
40+
case 'x32':
41+
return makeDownloadFile('osx-x86_32');
42+
case 'x64':
43+
return makeDownloadFile('osx-x86_64');
4344
}
4445
break;
4546
}
46-
throw new Error("There is no protoc compiler available for the current platform/arch combination: " + process.platform + "/" + process.arch)
47+
throw new Error(
48+
'There is no protoc compiler available for the current platform/arch combination: ' +
49+
process.platform +
50+
'/' +
51+
process.arch,
52+
);
4753
}
4854

49-
const protocDir = path.join(__dirname, "..", "protoc");
50-
const protocBin = path.join(protocDir, "bin", "protoc" + (process.platform === "win32" ? ".exe" : ""));
55+
const protocDir = path.join(__dirname, '..', 'protoc');
56+
const protocBin = path.join(
57+
protocDir,
58+
'bin',
59+
'protoc' + (process.platform === 'win32' ? '.exe' : ''),
60+
);
5161
const downloadFile = determineDownloadFile();
5262

5363
const protocZipFile = path.join(protocDir, downloadFile);
5464
// Check if we already have the file downloaded
5565
if (!fs.existsSync(protocZipFile)) {
56-
5766
// First, delete the directory if it exists, then recreate
5867
if (fs.existsSync(protocDir)) {
5968
rimraf.sync(protocDir);
6069
}
61-
mkdirp.sync(path.join(__dirname, "..", "protoc"));
70+
mkdirp.sync(path.join(__dirname, '..', 'protoc'));
6271

6372
// Download the file
64-
const downloadUrl = downloadUrlPrefix + protocVersion + "/" + downloadFile;
65-
console.log("Downloading protoc from " + downloadUrl);
73+
const downloadUrl = downloadUrlPrefix + protocVersion + '/' + downloadFile;
74+
console.log('Downloading protoc from ' + downloadUrl);
6675

6776
const file = fs.createWriteStream(protocZipFile);
6877
request(downloadUrl)
6978
.pipe(file)
70-
.on("finish", () => {
79+
.on('finish', () => {
7180
fs.createReadStream(protocZipFile)
7281
.pipe(unzipper.Parse())
73-
.on("entry", function(entry) {
82+
.on('entry', function (entry) {
7483
const extractPath = path.join(protocDir, entry.path);
75-
const extractDirectory = "Directory" === entry.type ? extractPath : path.dirname(extractPath);
84+
const extractDirectory =
85+
'Directory' === entry.type
86+
? extractPath
87+
: path.dirname(extractPath);
7688

77-
mkdirp(extractDirectory, function(err) {
89+
mkdirp(extractDirectory, function (err) {
7890
if (err) throw err;
79-
if ("File" === entry.type) {
80-
entry.pipe(fs.createWriteStream(extractPath))
81-
.on("finish", function() {
91+
if ('File' === entry.type) {
92+
entry
93+
.pipe(fs.createWriteStream(extractPath))
94+
.on('finish', function () {
8295
if (protocBin === extractPath) {
83-
fs.chmod(extractPath, 0o755, function(err) {
96+
fs.chmod(extractPath, 0o755, function (err) {
8497
if (err) throw err;
8598
});
8699
}

sdk/index.js

+13-11
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@
2020
* @module akkaserverless
2121
*/
2222

23-
module.exports.AkkaServerless = require("./src/akkaserverless");
24-
module.exports.EventSourcedEntity = require("./src/event-sourced-entity");
25-
module.exports.ValueEntity = require("./src/value-entity")
26-
module.exports.ReplicatedEntity = require("./src/replicated-entity").ReplicatedEntity;
27-
module.exports.ReplicatedData = require("./src/replicated-entity").ReplicatedData;
28-
module.exports.Action = require("./src/action");
29-
module.exports.Metadata = require("./src/metadata");
30-
module.exports.IntegrationTestkit = require("./src/integration-testkit");
31-
module.exports.View = require("./src/view");
32-
module.exports.replies = require("./src/reply");
33-
module.exports.settings = require("./settings");
23+
module.exports.AkkaServerless = require('./src/akkaserverless');
24+
module.exports.EventSourcedEntity = require('./src/event-sourced-entity');
25+
module.exports.ValueEntity = require('./src/value-entity');
26+
module.exports.ReplicatedEntity =
27+
require('./src/replicated-entity').ReplicatedEntity;
28+
module.exports.ReplicatedData =
29+
require('./src/replicated-entity').ReplicatedData;
30+
module.exports.Action = require('./src/action');
31+
module.exports.Metadata = require('./src/metadata');
32+
module.exports.IntegrationTestkit = require('./src/integration-testkit');
33+
module.exports.View = require('./src/view');
34+
module.exports.replies = require('./src/reply');
35+
module.exports.settings = require('./settings');

0 commit comments

Comments
 (0)