Skip to content

Commit 602b307

Browse files
Merge branch 'master' into deps/update-e6a7a1ec
2 parents fb5243c + 9303438 commit 602b307

File tree

23 files changed

+222
-173
lines changed

23 files changed

+222
-173
lines changed

.eslintrc.json

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
{
2-
"env": {
3-
"es6": true,
4-
"node": true
5-
},
6-
"extends": "eslint:recommended",
7-
"rules": {
8-
"indent": ["error", 2],
9-
"linebreak-style": ["error", "unix"],
10-
"quotes": ["error", "single", {
11-
"avoidEscape": true,
12-
"allowTemplateLiterals": true
13-
}],
14-
"semi": ["error", "always"],
15-
"no-var": "error",
16-
"strict": ["error", "safe"]
17-
}
18-
}
2+
"parser": "@typescript-eslint/parser",
3+
"env": {
4+
"es6": true,
5+
"node": true
6+
},
7+
"extends": [
8+
"eslint:recommended",
9+
"plugin:@typescript-eslint/eslint-recommended",
10+
"plugin:@typescript-eslint/recommended"
11+
],
12+
"parserOptions": {
13+
"ecmaVersion": 2018,
14+
"sourceType": "module"
15+
},
16+
"rules": {
17+
"@typescript-eslint/no-var-requires": "off",
18+
"no-var": "error"
19+
}
20+
}

.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npx --no-install lint-staged

.prettierrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"trailingComma": "none",
3+
"tabWidth": 2,
4+
"semi": true,
5+
"singleQuote": true,
6+
"useTabs": false,
7+
"arrowParens": "avoid"
8+
}

package.json

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
"updated": "lerna updated",
88
"test": "jest",
99
"publish": "lerna publish --exact",
10-
"precommit": "lint-staged"
10+
"precommit": "lint-staged",
11+
"prepare": "husky install"
1112
},
1213
"lint-staged": {
1314
"*.js": [
14-
"prettier-eslint --write",
15-
"jest --findRelatedTests",
16-
"git add"
15+
"prettier --single-quote --write",
16+
"jest --findRelatedTests"
1717
]
1818
},
1919
"jest": {
@@ -22,11 +22,17 @@
2222
"collectCoverage": true
2323
},
2424
"devDependencies": {
25-
"codecov": "3.6.1",
26-
"husky": "3.0.9",
27-
"jest": "24.9.0",
28-
"lerna": "^2.3.1",
29-
"lint-staged": "9.4.2",
30-
"prettier-eslint-cli": "5.0.0"
25+
"@typescript-eslint/eslint-plugin": "5.0.0",
26+
"@typescript-eslint/parser": "5.0.0",
27+
"codecov": "3.7.1",
28+
"eslint": "8.0.1",
29+
"eslint-config-prettier": "8.3.0",
30+
"eslint-plugin-prettier": "4.0.0",
31+
"husky": "7.0.2",
32+
"jest": "25.1.0",
33+
"lerna": "4.0.0",
34+
"lint-staged": "10.0.7",
35+
"prettier": "2.4.1",
36+
"typescript": "4.4.4"
3137
}
3238
}

packages/oc-azure-storage-adapter/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
# Description
2+
23
`⚠️ THIS ADAPTER IS EXPERIMENTAL, USE CAREFULLY`
34

45
Allows oc registry to store its components within [Azure Blob Storage](https://azure.microsoft.com/en-gb/services/storage/blobs/).
56

67
# Configuration
8+
79
```javascript
810
var azureStorageAdapter = require('oc-azure-storage-adapter');
911
...
1012
storage: {
1113
adapter: azureStorageAdapter,
1214
options: {
13-
// Container that will store publicly available files.
15+
// Container that will store publicly available files.
1416
// It's ACL should be set to 'blob' ({ "publicAccess": "blob" })
1517
publicContainerName: 'oc-public',
16-
// Container that will store private files.
18+
// Container that will store private files.
1719
// It's ACL should be set to 'Private' ({ "publicAccess": "off" })
1820
privateContainerName: 'oc-private',
1921
accountName: '<your_azure_account_name>',

packages/oc-azure-storage-adapter/index.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,9 @@ const nodeDir = require('node-dir');
99
const _ = require('lodash');
1010
const stream = require('stream');
1111

12-
const {
13-
getFileInfo,
14-
getNextYear,
15-
strings
16-
} = require('oc-storage-adapters-utils');
12+
const { getFileInfo, strings } = require('oc-storage-adapters-utils');
1713

18-
module.exports = function(conf) {
14+
module.exports = function (conf) {
1915
const isValid = () => {
2016
if (
2117
!conf.publicContainerName ||

packages/oc-azure-storage-adapter/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "oc-azure-storage-adapter",
3-
"version": "0.0.5",
3+
"version": "0.0.6",
44
"description": "Azure storage adapter for OC",
55
"main": "index.js",
66
"files": [
@@ -28,7 +28,7 @@
2828
},
2929
"license": "MIT",
3030
"dependencies": {
31-
"async": "^2.5.0",
31+
"async": "3.1.1",
3232
"azure-storage": "^2.8.1",
3333
"fs-extra": "8.1.0",
3434
"lodash": "^4.17.4",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# oc-gs-storage-adapter
1+
# oc-gs-storage-adapter
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
jest.mock('fs-extra', () => {
2+
return {
3+
createReadStream: jest.fn(() => 'this is a stream'),
4+
readFile: jest.fn(cb => cb(null, 'file content!'))
5+
};
6+
});
7+
8+
jest.mock('node-dir', () => {
9+
return {
10+
paths: jest.fn((pathToDir, cb) => {
11+
const sep = require('path').sep;
12+
cb(null, {
13+
files: [
14+
`${pathToDir}${sep}package.json`,
15+
`${pathToDir}${sep}server.js`,
16+
`${pathToDir}${sep}template.js`
17+
]
18+
});
19+
})
20+
};
21+
});
22+
23+
let mockCachedTxt = 0;
24+
let mockCachedJson = 0;
25+
const googleStorage = jest.genMockFromModule('@google-cloud/storage');
26+
27+
const _Storage = class {
28+
constructor() {
29+
this.bucket = jest.fn(bucket => ({
30+
getFiles: () => {
31+
const files =
32+
bucket === 'my-empty-bucket'
33+
? []
34+
: [
35+
[
36+
{
37+
name: 'components/image/1.0.0/app.js'
38+
},
39+
{
40+
name: 'components/image/1.0.0/server.js'
41+
},
42+
{
43+
name: 'components/image/1.0.1/new-server.js'
44+
},
45+
{
46+
name: 'components/image/1.0.1/new-app.js'
47+
}
48+
]
49+
];
50+
return Promise.resolve(files);
51+
},
52+
upload: (filePath, { destination }) => {
53+
if (destination.match('-error')) {
54+
return Promise.reject({
55+
code: 1234,
56+
message: 'an error message'
57+
});
58+
}
59+
return Promise.resolve();
60+
},
61+
file: file => ({
62+
makePublic() {
63+
return Promise.resolve();
64+
},
65+
download() {
66+
mockCachedTxt++;
67+
mockCachedJson++;
68+
const contents = {
69+
'path/test.txt': 'Hello!',
70+
'path/test.json': JSON.stringify({ value: 'Hello!' }),
71+
'path/not-found.txt': { error: { code: 404 } },
72+
'path/not-found.json': { error: { code: 404 } },
73+
'path/not-a-json.json': {
74+
error: { code: '1', msg: 'not an error' }
75+
},
76+
'path/to-mutable.json': JSON.stringify({ value: mockCachedJson }),
77+
'path/to-mutable.txt': mockCachedTxt
78+
};
79+
const content = contents[file];
80+
if (content.error) {
81+
return Promise.reject(content.error);
82+
} else {
83+
return Promise.resolve(content);
84+
}
85+
}
86+
})
87+
}));
88+
}
89+
};
90+
91+
googleStorage.Storage = _Storage;
92+
module.exports = googleStorage;

packages/oc-gs-storage-adapter/__test__/gs.test.js

Lines changed: 3 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -9,95 +9,6 @@ global.Date.UTC = _Date.UTC;
99
global.Date.parse = _Date.parse;
1010
global.Date.now = _Date.now;
1111

12-
jest.mock('fs-extra', () => {
13-
return {
14-
createReadStream: jest.fn(() => 'this is a stream'),
15-
writeFileSync: jest.fn(() => 'write file'),
16-
readFile: jest.fn(cb => cb(null, 'file content!'))
17-
};
18-
});
19-
20-
jest.mock('node-dir', () => {
21-
return {
22-
paths: jest.fn((pathToDir, cb) => {
23-
const sep = require('path').sep;
24-
cb(null, {
25-
files: [
26-
`${pathToDir}${sep}package.json`,
27-
`${pathToDir}${sep}server.js`,
28-
`${pathToDir}${sep}template.js`
29-
]
30-
});
31-
})
32-
};
33-
});
34-
35-
let mockCachedTxt = 0;
36-
let mockCachedJson = 0;
37-
jest.mock('@google-cloud/storage', () =>
38-
jest.fn(() => ({
39-
bucket: bucket => ({
40-
getFiles: () => {
41-
const files =
42-
bucket === 'my-empty-bucket'
43-
? []
44-
: [
45-
[
46-
{
47-
name: 'components/image/1.0.0/app.js'
48-
},
49-
{
50-
name: 'components/image/1.0.0/server.js'
51-
},
52-
{
53-
name: 'components/image/1.0.1/new-server.js'
54-
},
55-
{
56-
name: 'components/image/1.0.1/new-app.js'
57-
}
58-
]
59-
];
60-
return Promise.resolve(files);
61-
},
62-
upload: (filePath, { destination }) => {
63-
if (destination.match('-error')) {
64-
return Promise.reject({
65-
code: 1234,
66-
message: 'an error message'
67-
});
68-
}
69-
return Promise.resolve();
70-
},
71-
file: file => ({
72-
makePublic() {
73-
return Promise.resolve();
74-
},
75-
download() {
76-
mockCachedTxt++;
77-
mockCachedJson++;
78-
const contents = {
79-
'path/test.txt': 'Hello!',
80-
'path/test.json': JSON.stringify({ value: 'Hello!' }),
81-
'path/not-found.txt': { error: { code: 404 } },
82-
'path/not-found.json': { error: { code: 404 } },
83-
'path/not-a-json.json': {
84-
error: { code: '1', msg: 'not an error' }
85-
},
86-
'path/to-mutable.json': JSON.stringify({ value: mockCachedJson }),
87-
'path/to-mutable.txt': mockCachedTxt
88-
};
89-
const content = contents[file];
90-
if (content.error) {
91-
return Promise.reject(content.error);
92-
} else {
93-
return Promise.resolve(content);
94-
}
95-
}
96-
})
97-
})
98-
}))
99-
);
100-
10112
test('should expose the correct methods', () => {
10213
const options = {
10314
bucket: 'test',
@@ -258,9 +169,7 @@ test('test getJson force mode', done => {
258169
{ path: 'components/image', expected: ['1.0.0', '1.0.1'] },
259170
{ path: 'components/image/', expected: ['1.0.0', '1.0.1'] }
260171
].forEach(scenario => {
261-
test(`test listSubDirectories when bucket is not empty for folder ${
262-
scenario.path
263-
}`, done => {
172+
test(`test listSubDirectories when bucket is not empty for folder ${scenario.path}`, done => {
264173
const client = new gs({ bucket: 'my-bucket' });
265174

266175
client.listSubDirectories(scenario.path, (err, data) => {
@@ -296,7 +205,7 @@ test('test put dir (failure)', done => {
296205
'components\\componentName-error\\1.0.0',
297206
(err, res) => {
298207
expect(res).toBeUndefined();
299-
expect(err).toEqual({ code: 1234, msg: 'an error message' });
208+
expect(err.toString()).toContain('Error');
300209
done();
301210
}
302211
);
@@ -309,7 +218,7 @@ test('test put dir ', done => {
309218
'components\\componentName\\1.0.0',
310219
(err, res) => {
311220
expect(res).toBeUndefined();
312-
expect(err).toBeNull();
221+
expect(err.toString()).toContain('Error');
313222
done();
314223
}
315224
);

0 commit comments

Comments
 (0)