-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: plugin pack command for 2 (#916)
Release-As: 1.12.2
- Loading branch information
Showing
82 changed files
with
1,872 additions
and
1,307 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,27 @@ | ||
import type { CommandModule } from "yargs"; | ||
import type yargs from "yargs"; | ||
import { packCommand } from "./pack"; | ||
import { emitExperimentalWarning } from "../../utils/stability"; | ||
import { infoCommand } from "./info"; | ||
import { setStability } from "../stability"; | ||
|
||
const command = "plugin"; | ||
|
||
const describe = "[Experimental] Commands for kintone plugin"; | ||
const describe = "Commands for kintone plugin"; | ||
|
||
const builder = (args: yargs.Argv) => args.command(packCommand).demandCommand(); | ||
const builder = (args: yargs.Argv) => | ||
args.command(infoCommand).command(packCommand).demandCommand(); | ||
|
||
const handler = () => { | ||
emitExperimentalWarning("This feature is under early development"); | ||
/** noop **/ | ||
}; | ||
|
||
export const pluginCommand: CommandModule = { | ||
command, | ||
describe, | ||
builder, | ||
handler, | ||
}; | ||
export const pluginCommand: CommandModule = setStability( | ||
{ | ||
command, | ||
describe, | ||
builder, | ||
handler, | ||
}, | ||
"experimental", | ||
"This feature is under early development", | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import type yargs from "yargs"; | ||
import type { CommandModule } from "yargs"; | ||
import type { OutputFormat } from "../../plugin/info/"; | ||
import { run } from "../../plugin/info/"; | ||
import { logger } from "../../utils/log"; | ||
import { RunError } from "../../record/error"; | ||
import { setStability } from "../stability"; | ||
|
||
const command = "info"; | ||
|
||
const describe = "Show information from plugin file"; | ||
|
||
const outputFormats: OutputFormat[] = ["plain", "json"]; | ||
|
||
const builder = (args: yargs.Argv) => | ||
args | ||
.option("input", { | ||
describe: "The input plugin zip", | ||
type: "string", | ||
demandOption: true, | ||
requiresArg: true, | ||
}) | ||
.option("format", { | ||
describe: "Format", | ||
default: "plain" satisfies OutputFormat as OutputFormat, | ||
choices: outputFormats, | ||
requiresArg: true, | ||
}); | ||
|
||
type Args = yargs.Arguments< | ||
ReturnType<typeof builder> extends yargs.Argv<infer U> ? U : never | ||
>; | ||
|
||
const handler = async (args: Args) => { | ||
try { | ||
await run(args.input, args.format); | ||
} catch (error) { | ||
logger.error(new RunError(error)); | ||
// eslint-disable-next-line n/no-process-exit | ||
process.exit(1); | ||
} | ||
}; | ||
|
||
export const infoCommand: CommandModule<{}, Args> = setStability( | ||
{ | ||
command, | ||
describe, | ||
builder, | ||
handler, | ||
}, | ||
"experimental", | ||
"This feature is under early development", | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import type { ArgumentsCamelCase, CommandModule } from "yargs"; | ||
import { | ||
emitDeprecationWarning, | ||
emitExperimentalWarning, | ||
} from "../utils/stability"; | ||
|
||
/** | ||
* Set stability index to a command. | ||
* - Show stability on help message | ||
* - Emit warning on execution | ||
* @param cmd Command module | ||
* @param stability "experimental" or "deprecated" | ||
* @param message additional information | ||
*/ | ||
export const setStability = <T = {}, U = {}>( | ||
cmd: CommandModule<T, U>, | ||
stability: "experimental" | "deprecated", | ||
message: string, | ||
): CommandModule<T, U> => { | ||
const { describe, handler, ...restCmd } = cmd; | ||
const newDescribe = buildDescriptionWithStability( | ||
describe, | ||
message, | ||
stability, | ||
); | ||
|
||
const newHandler = async (args: ArgumentsCamelCase<U>) => { | ||
switch (stability) { | ||
case "experimental": | ||
emitExperimentalWarning(message); | ||
break; | ||
case "deprecated": | ||
emitDeprecationWarning(message); | ||
break; | ||
} | ||
await handler(args); | ||
}; | ||
|
||
return { | ||
...restCmd, | ||
describe: newDescribe, | ||
handler: newHandler, | ||
}; | ||
}; | ||
|
||
const buildDescriptionWithStability = ( | ||
description: string | false | undefined, | ||
message: string, | ||
stability: "experimental" | "deprecated", | ||
): string => { | ||
const labels = { | ||
experimental: "Experimental", | ||
deprecated: "Deprecated", | ||
}; | ||
const label = labels[stability]; | ||
const msgLines = message.split("\n"); | ||
|
||
let output = ""; | ||
if (description) { | ||
output += description + "\n\n"; | ||
} | ||
|
||
output += `[${label}: ${msgLines[0]}]`; | ||
if (msgLines.length > 1) { | ||
output += `${"\n" + msgLines.slice(1)}`; | ||
} | ||
|
||
return output; | ||
}; |
Binary file added
BIN
+20.5 KB
...gin/core/contents/__tests__/fixtures/invalid-maxFileSize/invalid-maxFileSize-contents.zip
Binary file not shown.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
Empty file.
File renamed without changes
Empty file.
Empty file.
36 changes: 36 additions & 0 deletions
36
src/plugin/core/contents/__tests__/fixtures/plugin-manifest-v2/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"$schema": "https://example.com/plugin-manifest-schema.json", | ||
"manifest_version": 2, | ||
"version": 1, | ||
"type": "APP", | ||
"name": { | ||
"en": "sample extension" | ||
}, | ||
"description": { | ||
"en": "This is sample extension." | ||
}, | ||
"icon": "image/icon.png", | ||
"components": [ | ||
{ | ||
"type": "APP_INDEX_HEADER_SPACE", | ||
"js": ["js/customize.js", "https://example.com/js/customize.js"], | ||
"css": ["https://example.com/css/customize.css", "css/customize.css"], | ||
"html": "html/customize.html" | ||
} | ||
], | ||
"config": { | ||
"html": "html/config.html", | ||
"js": ["https://example.com/js/config.js", "js/config.js"], | ||
"css": ["css/config.css", "https://example.com/css/config.css"], | ||
"required_params": ["Param1", "Param2"] | ||
}, | ||
"allowed_hosts": ["https://example.com"], | ||
"permissions": { | ||
"js_api": [ | ||
"rest_api:execute", | ||
"kintone.app.getId", | ||
"kintone.plugin.app.getConfig" | ||
], | ||
"rest_api": ["app_record:read", "/k/v1/record.json:put"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import path from "path"; | ||
import { ManifestFactory } from "../../manifest"; | ||
import { ContentsZip } from "../index"; | ||
import { LocalFSDriver } from "../../driver"; | ||
import fs from "fs"; | ||
|
||
const fixturesDir = path.join(__dirname, "fixtures"); | ||
|
||
describe("ContentsZip", () => { | ||
describe("should be able to create ContentsZip from a plugin directory", () => { | ||
it("manifest v1", async () => { | ||
const pluginDir = path.join(fixturesDir, "plugin-manifest-v1"); | ||
|
||
const manifestJSONPath = path.join(pluginDir, "manifest.json"); | ||
const manifest = await ManifestFactory.loadJsonFile(manifestJSONPath); | ||
|
||
const contentsZip = await ContentsZip.buildFromManifest( | ||
manifest, | ||
new LocalFSDriver(pluginDir), | ||
); | ||
const files = await contentsZip.fileList(); | ||
expect(files).toStrictEqual(["manifest.json", "image/icon.png"]); | ||
expect(contentsZip).toBeInstanceOf(ContentsZip); | ||
expect(contentsZip.buffer).toBeInstanceOf(Buffer); | ||
}); | ||
|
||
it("manifest v2", async () => { | ||
const pluginDir = path.join(fixturesDir, "plugin-manifest-v2"); | ||
|
||
const manifestJSONPath = path.join(pluginDir, "manifest.json"); | ||
const manifest = await ManifestFactory.loadJsonFile(manifestJSONPath); | ||
|
||
const contentsZip = await ContentsZip.buildFromManifest( | ||
manifest, | ||
new LocalFSDriver(pluginDir), | ||
); | ||
|
||
const expectedFiles = [ | ||
"manifest.json", | ||
"image/icon.png", | ||
"js/customize.js", | ||
"css/customize.css", | ||
"html/customize.html", | ||
"html/config.html", | ||
"js/config.js", | ||
"css/config.css", | ||
]; | ||
const files = await contentsZip.fileList(); | ||
expect(files).toStrictEqual(expectedFiles); | ||
expect(contentsZip).toBeInstanceOf(ContentsZip); | ||
expect(contentsZip.buffer).toBeInstanceOf(Buffer); | ||
}); | ||
}); | ||
|
||
describe("invalid contents.zip", () => { | ||
const invalidMaxFileSizeContentsZipPath = path.join( | ||
__dirname, | ||
"fixtures", | ||
"invalid-maxFileSize", | ||
"invalid-maxFileSize-contents.zip", | ||
); | ||
|
||
// TODO: This test must be in contents-zip module | ||
it("throws an error if the contents.zip is invalid", async () => { | ||
const buffer = fs.readFileSync(invalidMaxFileSizeContentsZipPath); | ||
await expect(ContentsZip.fromBuffer(buffer)).rejects.toThrow( | ||
'"/icon" file size should be <= 20MB', | ||
); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.