@8ms/helpers 1.2.6 → 1.2.7

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,9 @@
1
+ type CreateDirectory = {
2
+ filePath: string;
3
+ };
4
+ /**
5
+ * Create a directory recursively.
6
+ * Requires fs-extra
7
+ */
8
+ declare const createDirectory: ({ filePath }: CreateDirectory) => void;
9
+ export default createDirectory;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Create a directory recursively.
5
+ * Requires fs-extra
6
+ */
7
+ const createDirectory = ({ filePath }) => {
8
+ const fs = require('fs-extra');
9
+ const path = require('path');
10
+ const fileDir = path.parse(filePath).dir;
11
+ fs.ensureDirSync(fileDir);
12
+ };
13
+ exports.default = createDirectory;
@@ -0,0 +1 @@
1
+ declare const writeFile: () => void;
@@ -0,0 +1,2 @@
1
+ const writeFile = () => {
2
+ };
@@ -9,7 +9,10 @@ const IsTableExists_1 = __importDefault(require("./IsTableExists"));
9
9
  * Returns table instance.
10
10
  */
11
11
  const createTable = async ({ datasetId, options, tableId }) => {
12
- const tableExists = await (0, IsTableExists_1.default)({ datasetId, tableId });
12
+ const tableExists = await (0, IsTableExists_1.default)({
13
+ datasetId,
14
+ tableId
15
+ });
13
16
  if (!tableExists) {
14
17
  await global.googleBigQueryClient.dataset(datasetId)
15
18
  .createTable(tableId, options);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "1.2.6",
4
+ "version": "1.2.7",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"
@@ -0,0 +1,11 @@
1
+ type WriteUrlContents = {
2
+ filePath: string;
3
+ url: string;
4
+ };
5
+ /**
6
+ * Downloads a given URL's contents to a local file.
7
+ *
8
+ * Requires fs-extra
9
+ */
10
+ declare const saveUrlContents: ({ filePath, url }: WriteUrlContents) => Promise<unknown>;
11
+ export default saveUrlContents;
@@ -4,22 +4,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const axios_1 = __importDefault(require("axios"));
7
+ const createDirectory_1 = __importDefault(require("../file/createDirectory"));
7
8
  /**
8
9
  * Downloads a given URL's contents to a local file.
9
10
  *
10
11
  * Requires fs-extra
11
12
  */
12
- const saveUrlContents = ({ fileName, path, url }) => {
13
+ const saveUrlContents = ({ filePath, url }) => {
13
14
  const fs = require('fs-extra');
14
- let finalPath = path ? path : '/tmp';
15
- // Must begin with slash
16
- if ('/' !== finalPath[0]) {
17
- finalPath = '/' + finalPath;
18
- }
19
- // Must end without slash
20
- if ('/' === finalPath[finalPath.length - 1]) {
21
- finalPath = finalPath.substring(0, finalPath.length - 2);
22
- }
23
15
  return new Promise(async (resolve, reject) => {
24
16
  (0, axios_1.default)({
25
17
  method: "get",
@@ -27,7 +19,10 @@ const saveUrlContents = ({ fileName, path, url }) => {
27
19
  responseType: "stream"
28
20
  })
29
21
  .then(function (response) {
30
- response.data.pipe(fs.createWriteStream(`${finalPath}/${fileName}`));
22
+ (0, createDirectory_1.default)({
23
+ filePath,
24
+ });
25
+ response.data.pipe(fs.createWriteStream(filePath));
31
26
  resolve(true);
32
27
  });
33
28
  });
@@ -1,12 +0,0 @@
1
- type SaveUrlContents = {
2
- fileName: string;
3
- path?: string;
4
- url: string;
5
- };
6
- /**
7
- * Downloads a given URL's contents to a local file.
8
- *
9
- * Requires fs-extra
10
- */
11
- declare const saveUrlContents: ({ fileName, path, url }: SaveUrlContents) => Promise<unknown>;
12
- export default saveUrlContents;