Comparing version 1.1.1 to 2.0.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createGitHubAdaptor = exports.createKoreFile = void 0; | ||
var korefile_1 = require("./korefile"); | ||
exports.createKoreFile = korefile_1.createKoreFile; | ||
Object.defineProperty(exports, "createKoreFile", { enumerable: true, get: function () { return korefile_1.createKoreFile; } }); | ||
var GitHubAdaptor_1 = require("./GitHubAdaptor"); | ||
exports.createGitHubAdaptor = GitHubAdaptor_1.createGitHubAdaptor; | ||
Object.defineProperty(exports, "createGitHubAdaptor", { enumerable: true, get: function () { return GitHubAdaptor_1.createGitHubAdaptor; } }); | ||
//# sourceMappingURL=browser.js.map |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
@@ -37,14 +57,8 @@ }); | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createFsAdaptor = void 0; | ||
var fs = __importStar(require("fs")); | ||
var path = __importStar(require("path")); | ||
var util = __importStar(require("util")); | ||
exports.createFsAdaptor = function (options) { | ||
var createFsAdaptor = function (options) { | ||
var readFile = util.promisify(fs.readFile); | ||
@@ -72,3 +86,3 @@ var writeFile = util.promisify(fs.writeFile); | ||
_a.sent(); | ||
if (Buffer.isBuffer(content) || ArrayBuffer.isView(content)) { | ||
if (Buffer.isBuffer(content)) { | ||
return [2 /*return*/, writeFile(resolvedFilePath, content)]; | ||
@@ -89,2 +103,3 @@ } | ||
}; | ||
exports.createFsAdaptor = createFsAdaptor; | ||
//# sourceMappingURL=fsAdaptor.js.map |
@@ -0,1 +1,2 @@ | ||
import { Octokit } from "@octokit/rest"; | ||
import { KoreFileAdaptor } from "./KoreFileAdaptor"; | ||
@@ -14,9 +15,3 @@ export interface GitCommitPushOptions { | ||
} | ||
export declare const getContent: (github: { | ||
[x: string]: any; | ||
} & { | ||
[x: string]: any; | ||
} & import("@octokit/core").Octokit & void & { | ||
paginate: import("@octokit/plugin-paginate-rest").PaginateInterface; | ||
} & import("@octokit/plugin-rest-endpoint-methods/dist-types/generated/method-types").RestEndpointMethods, { owner, repo, path, ref }: { | ||
export declare const getContent: (github: Octokit, { owner, repo, path, ref }: { | ||
owner: string; | ||
@@ -27,9 +22,3 @@ repo: string; | ||
}) => Promise<string>; | ||
export declare const deleteFile: (octokit: { | ||
[x: string]: any; | ||
} & { | ||
[x: string]: any; | ||
} & import("@octokit/core").Octokit & void & { | ||
paginate: import("@octokit/plugin-paginate-rest").PaginateInterface; | ||
} & import("@octokit/plugin-rest-endpoint-methods/dist-types/generated/method-types").RestEndpointMethods, { owner, repo, path, ref, commitMessage }: { | ||
export declare const deleteFile: (octokit: Octokit, { owner, repo, path, ref, commitMessage }: { | ||
owner: string; | ||
@@ -36,0 +25,0 @@ repo: string; |
@@ -14,6 +14,7 @@ "use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
@@ -49,4 +50,4 @@ }); | ||
}; | ||
var _this = this; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createGitHubAdaptor = exports.deleteFile = exports.getContent = void 0; | ||
var rest_1 = require("@octokit/rest"); | ||
@@ -116,3 +117,3 @@ var base64_arraybuffer_1 = require("base64-arraybuffer"); | ||
debug("createCommit Response: %O", res); | ||
return __assign({}, data, { newTreeSha: res.data.sha }); | ||
return __assign(__assign({}, data), { newTreeSha: res.data.sha }); | ||
}); | ||
@@ -130,3 +131,3 @@ }); | ||
debug("createTree Response: %O", res); | ||
return __assign({}, data, { newCommitSha: res.data.sha }); | ||
return __assign(__assign({}, data), { newCommitSha: res.data.sha }); | ||
}); | ||
@@ -145,3 +146,3 @@ }; | ||
}; | ||
exports.getContent = function (github, _a) { | ||
var getContent = function (github, _a) { | ||
var owner = _a.owner, repo = _a.repo, path = _a.path, ref = _a.ref; | ||
@@ -154,17 +155,22 @@ return github.repos.getContent({ | ||
}).then(function (res) { | ||
var data = res.data; | ||
if (Array.isArray(data)) { | ||
throw new Error("folder does not support"); | ||
} | ||
debug("getContent Response: %O", res); | ||
if (res.data.type !== "file") { | ||
if (data.type !== "file") { | ||
return Promise.reject(new Error("This is not file:" + path)); | ||
} | ||
if (res.data.encoding === "base64") { | ||
if (data.encoding === "base64") { | ||
// TODO: support binary | ||
return Promise.resolve(Buffer.from(res.data.content, "base64").toString()); | ||
return Promise.resolve(Buffer.from(data.content, "base64").toString()); | ||
} | ||
throw new Error("Unknown file type" + res.data.type + ":" + res.data.encoding); | ||
throw new Error("Unknown file type" + data.type + ":" + data.encoding); | ||
}); | ||
}; | ||
exports.deleteFile = function (octokit, _a) { | ||
exports.getContent = getContent; | ||
var deleteFile = function (octokit, _a) { | ||
var owner = _a.owner, repo = _a.repo, path = _a.path, ref = _a.ref, commitMessage = _a.commitMessage; | ||
return __awaiter(_this, void 0, void 0, function () { | ||
var data; | ||
return __awaiter(void 0, void 0, void 0, function () { | ||
var response, data; | ||
return __generator(this, function (_b) { | ||
@@ -179,4 +185,8 @@ switch (_b.label) { | ||
case 1: | ||
data = (_b.sent()).data; | ||
response = _b.sent(); | ||
data = response.data; | ||
debug("deleteFile:getContents Response: %O", data); | ||
if (Array.isArray(data)) { | ||
throw new Error("folder does not support"); | ||
} | ||
return [2 /*return*/, octokit.repos.deleteFile({ | ||
@@ -196,3 +206,4 @@ owner: owner, | ||
}; | ||
exports.createGitHubAdaptor = function (options) { | ||
exports.deleteFile = deleteFile; | ||
var createGitHubAdaptor = function (options) { | ||
var token = options.token || GITHUB_API_TOKEN; | ||
@@ -223,3 +234,3 @@ if (!token) { | ||
writeFile: function (filePath, content) { | ||
var withFileOption = __assign({}, filledOptions, { files: [{ | ||
var withFileOption = __assign(__assign({}, filledOptions), { files: [{ | ||
path: filePath, | ||
@@ -233,3 +244,3 @@ content: content | ||
.then(function (data) { return createTree(octKit, withFileOption, data); }) | ||
.then(function (data) { return createCommit(octKit, __assign({}, filledOptions, { commitMessage: commitMessage }), data); }) | ||
.then(function (data) { return createCommit(octKit, __assign(__assign({}, filledOptions), { commitMessage: commitMessage }), data); }) | ||
.then(function (data) { return updateReference(octKit, withFileOption, data); }); | ||
@@ -241,6 +252,7 @@ }, | ||
: "Delete " + filePath; | ||
return exports.deleteFile(octKit, __assign({}, filledOptions, { path: filePath, commitMessage: commitMessage })); | ||
return exports.deleteFile(octKit, __assign(__assign({}, filledOptions), { path: filePath, commitMessage: commitMessage })); | ||
} | ||
}; | ||
}; | ||
exports.createGitHubAdaptor = createGitHubAdaptor; | ||
//# sourceMappingURL=GitHubAdaptor.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createGitHubAdaptor = exports.createFsAdaptor = exports.createKoreFile = void 0; | ||
var korefile_1 = require("./korefile"); | ||
exports.createKoreFile = korefile_1.createKoreFile; | ||
Object.defineProperty(exports, "createKoreFile", { enumerable: true, get: function () { return korefile_1.createKoreFile; } }); | ||
var fsAdaptor_1 = require("./fsAdaptor"); | ||
exports.createFsAdaptor = fsAdaptor_1.createFsAdaptor; | ||
Object.defineProperty(exports, "createFsAdaptor", { enumerable: true, get: function () { return fsAdaptor_1.createFsAdaptor; } }); | ||
var GitHubAdaptor_1 = require("./GitHubAdaptor"); | ||
exports.createGitHubAdaptor = GitHubAdaptor_1.createGitHubAdaptor; | ||
Object.defineProperty(exports, "createGitHubAdaptor", { enumerable: true, get: function () { return GitHubAdaptor_1.createGitHubAdaptor; } }); | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createKoreFile = function (_a) { | ||
exports.createKoreFile = void 0; | ||
var createKoreFile = function (_a) { | ||
var adaptor = _a.adaptor; | ||
@@ -17,2 +18,3 @@ return { | ||
}; | ||
exports.createKoreFile = createKoreFile; | ||
//# sourceMappingURL=korefile.js.map |
{ | ||
"name": "korefile", | ||
"version": "1.1.1", | ||
"version": "2.0.0", | ||
"description": "File System API for Local/GitHub.", | ||
@@ -35,3 +35,3 @@ "keywords": [ | ||
"scripts": { | ||
"build": "cross-env NODE_ENV=production tsc -p .", | ||
"build": "tsc -p .", | ||
"clean": "rimraf lib/", | ||
@@ -60,23 +60,18 @@ "prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"", | ||
"devDependencies": { | ||
"@types/base-64": "^0.1.3", | ||
"@types/base64-js": "^1.2.5", | ||
"@types/mocha": "^5.2.7", | ||
"@types/node": "^12.0.4", | ||
"cross-env": "^5.2.0", | ||
"husky": "^2.3.0", | ||
"lint-staged": "^8.1.7", | ||
"mocha": "^6.1.4", | ||
"prettier": "^1.17.1", | ||
"rimraf": "^2.6.3", | ||
"ts-node": "^8.2.0", | ||
"ts-node-test-register": "^8.0.1", | ||
"typescript": "^3.5.1" | ||
"@types/mocha": "^8.2.0", | ||
"@types/node": "^14.14.16", | ||
"husky": "^4.3.6", | ||
"lint-staged": "^10.5.3", | ||
"mocha": "^8.2.1", | ||
"prettier": "^2.2.1", | ||
"rimraf": "^3.0.2", | ||
"ts-node": "^9.1.1", | ||
"ts-node-test-register": "^9.0.1", | ||
"typescript": "^4.1.3" | ||
}, | ||
"dependencies": { | ||
"@octokit/rest": "^18.0.3", | ||
"base-64": "^0.1.0", | ||
"@octokit/rest": "^18.0.12", | ||
"base64-arraybuffer": "^0.2.0", | ||
"base64-js": "^1.3.1", | ||
"debug": "^4.1.1" | ||
"debug": "^4.3.1" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# korefile [![Build Status](https://travis-ci.org/azu/korefile.svg?branch=master)](https://travis-ci.org/azu/korefile) | ||
# korefile [![Actions Status: test](https://github.com/azu/korefile/workflows/test/badge.svg)](https://github.com/azu/korefile/actions?query=workflow%3A"test") | ||
@@ -10,3 +10,3 @@ > korefile: コレ・ファイル | ||
- Write/Read/Delete API for Local/GitHub | ||
- Plugabble adaptor | ||
- Pluggable adaptor | ||
@@ -26,3 +26,3 @@ ## Install | ||
Read/Write/Delete for local file system. | ||
It wrap `fs` module. | ||
It wraps `fs` module. | ||
@@ -29,0 +29,0 @@ ```js |
@@ -20,3 +20,3 @@ import { KoreFileAdaptor } from "./KoreFileAdaptor"; | ||
}, | ||
async writeFile(filePath: string, content: string | ArrayBuffer | Buffer): Promise<void> { | ||
async writeFile(filePath: string, content: string | Buffer): Promise<void> { | ||
const resolvedFilePath = path.resolve(cwd, filePath); | ||
@@ -27,3 +27,3 @@ const dir = path.dirname(resolvedFilePath); | ||
}); | ||
if (Buffer.isBuffer(content) || ArrayBuffer.isView(content)) { | ||
if (Buffer.isBuffer(content)) { | ||
return writeFile(resolvedFilePath, content); | ||
@@ -30,0 +30,0 @@ } else { |
import { Octokit } from "@octokit/rest"; | ||
import { KoreFileAdaptor } from "./KoreFileAdaptor"; | ||
import { encode as arrayBufferToBase64 } from "base64-arraybuffer"; | ||
// https://github.com/octokit/rest.js/issues/1971 | ||
import type { components } from "@octokit/openapi-types"; | ||
type GetRepoContentResponseDataFile = components["schemas"]["content-file"] | ||
const debug = require("debug")("korefile"); | ||
@@ -128,11 +132,15 @@ const GITHUB_API_TOKEN = process.env.GITHUB_API_TOKEN; | ||
}).then(res => { | ||
const data = res.data as GetRepoContentResponseDataFile; | ||
if (Array.isArray(data)) { | ||
throw new Error(`folder does not support`); | ||
} | ||
debug("getContent Response: %O", res); | ||
if (res.data.type !== "file") { | ||
if (data.type !== "file") { | ||
return Promise.reject(new Error("This is not file:" + path)); | ||
} | ||
if (res.data.encoding === "base64") { | ||
if (data.encoding === "base64") { | ||
// TODO: support binary | ||
return Promise.resolve(Buffer.from(res.data.content, "base64").toString()); | ||
return Promise.resolve(Buffer.from(data.content, "base64").toString()); | ||
} | ||
throw new Error("Unknown file type" + res.data.type + ":" + res.data.encoding); | ||
throw new Error("Unknown file type" + data.type + ":" + data.encoding); | ||
}); | ||
@@ -148,3 +156,3 @@ }; | ||
}) => { | ||
const { data } = await octokit.repos.getContent({ | ||
const response = await octokit.repos.getContent({ | ||
owner, | ||
@@ -155,3 +163,7 @@ repo, | ||
}); | ||
const { data } = response; | ||
debug("deleteFile:getContents Response: %O", data); | ||
if (Array.isArray(data)) { | ||
throw new Error(`folder does not support`); | ||
} | ||
return octokit.repos.deleteFile({ | ||
@@ -158,0 +170,0 @@ owner, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44808
3
10
749
- Removedbase-64@^0.1.0
- Removedbase64-js@^1.3.1
- Removedbase-64@0.1.0(transitive)
- Removedbase64-js@1.5.1(transitive)
Updated@octokit/rest@^18.0.12
Updateddebug@^4.3.1