Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove putdir method #331

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions packages/oc-azure-storage-adapter/__mocks__/@azure/storage-blob.js
Original file line number Diff line number Diff line change
@@ -8,25 +8,6 @@ jest.mock('fs-extra', () => {
};
});

jest.mock('node-dir', () => {
return {
paths: jest.fn((pathToDir, cb) => {
cb(null, {
files: [
`${pathToDir}\\package.json`,
`${pathToDir}\\server.js`,
`${pathToDir}\\.env`,
`${pathToDir}\\template.js`,
`${pathToDir}/package.json`,
`${pathToDir}/server.js`,
`${pathToDir}/.env`,
`${pathToDir}/template.js`
]
});
})
};
});

let cachedTxt = 0;
let cachedJson = 0;

39 changes: 2 additions & 37 deletions packages/oc-azure-storage-adapter/__test__/azure.test.ts
Original file line number Diff line number Diff line change
@@ -15,7 +15,8 @@ const validOptions = {
privateContainerName: 'privcon',
accountName: 'name',
accountKey: 'key',
path: '/'
path: '/',
componentsDir: 'components'
};

test('should expose the correct methods', () => {
@@ -29,7 +30,6 @@ test('should expose the correct methods', () => {
{ method: 'isValid', type: Function },
{ method: 'listSubDirectories', type: Function },
{ method: 'maxConcurrentRequests', value: 20 },
{ method: 'putDir', type: Function },
{ method: 'putFileContent', type: Function }
].forEach(api => {
if (api.type === Function) {
@@ -201,41 +201,6 @@ test('test getUrl ', () => {
expect(client.getUrl('test', '1.0.0', 'test.js')).toBe('/test/1.0.0/test.js');
});

test('test put dir (failure)', () => {
const client = azure(validOptions);

return expect(
client.putDir(
'/absolute-path-to-dir',
'components\\componentName-error\\1.0.0'
)
).rejects.toEqual({ msg: 'sorry' });
});

test('test put dir (stream failure throwing)', () => {
const client = azure(validOptions);

return expect(
client.putDir(
'/absolute-path-to-dir',
'components\\componentName-error-throw\\1.0.0'
)
).rejects.toEqual({ msg: 'sorry' });
});

test('Put dir uploads the package.json the last file to use it as a verifier', async () => {
const client = azure(validOptions);

const results = (await client.putDir(
'/absolute-path-to-dir',
'components\\componentName\\1.0.0'
)) as any[];

expect(results.pop().fileName).toBe(
'components/componentName/1.0.0/package.json'
);
});

test('test private putFileContent', async () => {
const client = azure(validOptions);

This file was deleted.

6 changes: 2 additions & 4 deletions packages/oc-azure-storage-adapter/package.json
Original file line number Diff line number Diff line change
@@ -36,12 +36,10 @@
"fs-extra": "8.1.0",
"lodash": "^4.17.4",
"nice-cache": "^0.0.5",
"node-dir": "^0.1.17",
"oc-storage-adapters-utils": "2.0.2"
},
"devDependencies": {
"@types/fs-extra": "9.0.13",
"@types/lodash": "4.14.186",
"@types/node-dir": "0.0.34"
"@types/lodash": "4.14.186"
}
}
}
39 changes: 0 additions & 39 deletions packages/oc-azure-storage-adapter/src/index.ts
Original file line number Diff line number Diff line change
@@ -5,19 +5,12 @@ import {
} from '@azure/storage-blob';
import Cache from 'nice-cache';
import fs from 'fs-extra';
import nodeDir, { PathsResult } from 'node-dir';
import { promisify } from 'util';
import {
getFileInfo,
strings,
StorageAdapter,
StorageAdapterBaseConfig
} from 'oc-storage-adapters-utils';
import path from 'path';

const getPaths: (path: string) => Promise<PathsResult> = promisify(
nodeDir.paths
);

// [Node.js only] A helper method used to read a Node.js readable stream into a Buffer
async function streamToBuffer(readableStream: NodeJS.ReadableStream) {
@@ -154,37 +147,6 @@ export default function azureAdapter(conf: AzureConfig): StorageAdapter {
return subDirectories;
};

const putDir = async (dirInput: string, dirOutput: string) => {
const paths = await getPaths(dirInput);
const packageJsonFile = path.join(dirInput, 'package.json');
const files = paths.files.filter(file => file !== packageJsonFile);

const filesResults = await Promise.all(
files.map((file: string) => {
const relativeFile = file.slice(dirInput.length);
const url = (dirOutput + relativeFile).replace(/\\/g, '/');

const serverPattern = /(\\|\/)server\.js/;
const dotFilePattern = /(\\|\/)\..+/;
const privateFilePatterns = [serverPattern, dotFilePattern];
return putFile(
file,
url,
privateFilePatterns.some(r => r.test(relativeFile))
);
})
);
// Ensuring package.json is uploaded last so we can verify that a component
// was properly uploaded by checking if package.json exists
const packageJsonFileResult = await putFile(
packageJsonFile,
`${dirOutput}/package.json`.replace(/\\/g, '/'),
false
);

return [...filesResults, packageJsonFileResult];
};

const putFileContent = async (
fileContent: string | fs.ReadStream,
fileName: string,
@@ -235,7 +197,6 @@ export default function azureAdapter(conf: AzureConfig): StorageAdapter {
getUrl,
listSubDirectories,
maxConcurrentRequests: 20,
putDir,
putFile,
putFileContent,
adapterType: 'azure-blob-storage',
42 changes: 2 additions & 40 deletions packages/oc-gs-storage-adapter/__test__/gs.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import gs from '../src';

jest.mock('node-dir', () => {
return {
paths: jest.fn((pathToDir, cb) => {
const sep = require('path').sep;
cb(null, {
files: [
`${pathToDir}${sep}package.json`,
`${pathToDir}${sep}server.js`,
`${pathToDir}${sep}.env`,
`${pathToDir}${sep}template.js`
]
});
})
};
});

//Mock Date functions
const DATE_TO_USE = new Date('2017');
const _Date = Date;
@@ -28,7 +12,8 @@ global.Date.now = _Date.now;
const validOptions = {
bucket: 'test',
projectId: '12345',
path: '/'
path: '/',
componentsDir: 'components'
};

test('should expose the correct methods', () => {
@@ -41,7 +26,6 @@ test('should expose the correct methods', () => {
{ method: 'isValid', type: Function },
{ method: 'listSubDirectories', type: Function },
{ method: 'maxConcurrentRequests', value: 20 },
{ method: 'putDir', type: Function },
{ method: 'putFileContent', type: Function }
].forEach(api => {
if (api.type === Function) {
@@ -189,28 +173,6 @@ test('test getUrl ', () => {
expect(client.getUrl('test', '1.0.0', 'test.js')).toBe('/test/1.0.0/test.js');
});

test('test put dir (failure)', () => {
const client = gs(validOptions);

return expect(
client.putDir(
'/absolute-path-to-dir',
'components\\componentName-error\\1.0.0'
)
).rejects.toEqual({ code: 1234, msg: 'an error message' });
});

test('Put dir uploads the package.json the last file to use it as a verifier', async () => {
const client = gs(validOptions);

const results = (await client.putDir(
'/absolute-path-to-dir',
'components\\componentName\\1.0.0'
)) as any[];

expect(results.pop().Key).toBe('components/componentName/1.0.0/package.json');
});

test('test private putFileContent ', async () => {
const client = gs(validOptions);

This file was deleted.

4 changes: 1 addition & 3 deletions packages/oc-gs-storage-adapter/package.json
Original file line number Diff line number Diff line change
@@ -35,14 +35,12 @@
"fs-extra": "8.1.0",
"lodash": "^4.17.4",
"nice-cache": "^0.0.5",
"node-dir": "^0.1.17",
"oc-storage-adapters-utils": "2.0.2",
"tmp": "0.1.0"
},
"devDependencies": {
"@types/fs-extra": "9.0.13",
"@types/lodash": "4.14.186",
"@types/node-dir": "0.0.34",
"@types/tmp": "0.2.3"
}
}
}
39 changes: 0 additions & 39 deletions packages/oc-gs-storage-adapter/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Cache from 'nice-cache';
import fs from 'fs-extra';
import nodeDir, { PathsResult } from 'node-dir';
import { Storage, UploadOptions } from '@google-cloud/storage';
import tmp from 'tmp';
import {
@@ -9,12 +8,6 @@ import {
StorageAdapter,
StorageAdapterBaseConfig
} from 'oc-storage-adapters-utils';
import { promisify } from 'util';
import path from 'path';

const getPaths: (path: string) => Promise<PathsResult> = promisify(
nodeDir.paths
);

export interface GsConfig extends StorageAdapterBaseConfig {
bucket: string;
@@ -139,37 +132,6 @@ export default function gsAdapter(conf: GsConfig): StorageAdapter {
}
};

const putDir = async (dirInput: string, dirOutput: string) => {
const paths = await getPaths(dirInput);
const packageJsonFile = path.join(dirInput, 'package.json');
const files = paths.files.filter(file => file !== packageJsonFile);

const filesResults = await Promise.all(
files.map((file: string) => {
const relativeFile = file.slice(dirInput.length);
const url = (dirOutput + relativeFile).replace(/\\/g, '/');

const serverPattern = /(\\|\/)server\.js/;
const dotFilePattern = /(\\|\/)\..+/;
const privateFilePatterns = [serverPattern, dotFilePattern];
return putFile(
file,
url,
privateFilePatterns.some(r => r.test(relativeFile))
);
})
);
// Ensuring package.json is uploaded last so we can verify that a component
// was properly uploaded by checking if package.json exists
const packageJsonFileResult = await putFile(
packageJsonFile,
`${dirOutput}/package.json`.replace(/\\/g, '/'),
false
);

return [...filesResults, packageJsonFileResult];
};

const putFileContent = async (
fileContent: string,
fileName: string,
@@ -241,7 +203,6 @@ export default function gsAdapter(conf: GsConfig): StorageAdapter {
getUrl,
listSubDirectories,
maxConcurrentRequests: 20,
putDir,
putFile,
putFileContent,
adapterType: 'gs',
Loading