Skip to content
Draft
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions src/cli/plugin/pack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ const builder = (args: yargs.Argv) =>
.option("watch", {
describe: "Run in watch mode",
type: "boolean",
})
.option("skip-manifest-validation", {
type: "boolean",
default: false,
hidden: true,
});

type Args = yargs.Arguments<
Expand All @@ -48,6 +53,7 @@ const handler = async (args: Args) => {
output: args.output,
ppkFilePath: args["private-key"],
watch: args.watch,
skipManifestValidation: args["skip-manifest-validation"],
};
if (process.env.NODE_ENV === "test") {
console.log(JSON.stringify(params));
Expand Down
6 changes: 6 additions & 0 deletions src/cli/plugin/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ const builder = (args: yargs.Argv) =>
describe: "Run in watch mode",
type: "boolean",
default: false,
})
.option("skip-manifest-validation", {
type: "boolean",
default: false,
hidden: true,
});

type Args = yargs.Arguments<
Expand All @@ -43,6 +48,7 @@ const handler = async (args: Args) => {
pluginFilePath: args.input,
force: args.yes,
watch: args.watch,
skipManifestValidation: args["skip-manifest-validation"],
};
const apiClientOptions: RestAPIClientOptions = {
baseUrl: args["base-url"],
Expand Down
9 changes: 6 additions & 3 deletions src/plugin/core/contents/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,19 @@ export class ContentsZip extends ZipFileDriver implements ContentsInterface {
public static async buildFromManifest(
manifest: ManifestInterface,
driver: DriverInterface,
skipManifestValidation = false,
): Promise<ContentsZip> {
const buffer = await buildContentsZip(manifest, driver);
// const buffer = await _createContentsZipStream(manifest, driver);
return ContentsZip.fromBuffer(buffer);
return ContentsZip.fromBuffer(buffer, skipManifestValidation);
}

public static async fromBuffer(buffer: Buffer) {
public static async fromBuffer(buffer: Buffer, skipManifestValidation = false) {
const contentsZip = new ContentsZip(buffer);
await contentsZip.cacheEntries();
await contentsZip.validate();
if (!skipManifestValidation) {
await contentsZip.validate();
}
return contentsZip;
}

Expand Down
5 changes: 4 additions & 1 deletion src/plugin/core/manifest/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ export interface ManifestInterface {
* Generate contents.zip from Manifest and Driver
* @param driver
*/
generateContentsZip(driver: DriverInterface): Promise<ContentsZip>;
generateContentsZip(
driver: DriverInterface,
skipManifestValidation?: boolean,
): Promise<ContentsZip>;

// Accessor
get manifestVersion(): 1 | 2;
Expand Down
7 changes: 5 additions & 2 deletions src/plugin/core/manifest/v1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ export class ManifestV1 implements ManifestInterface {
return sourceList(this.manifest);
}

async generateContentsZip(driver: DriverInterface): Promise<ContentsZip> {
return ContentsZip.buildFromManifest(this, driver);
async generateContentsZip(
driver: DriverInterface,
skipManifestValidation = false,
): Promise<ContentsZip> {
return ContentsZip.buildFromManifest(this, driver, skipManifestValidation);
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/plugin/core/manifest/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ export class ManifestV2 implements ManifestInterface {
return sourceListV2(this.manifest);
}

async generateContentsZip(driver: DriverInterface): Promise<ContentsZip> {
return ContentsZip.buildFromManifest(this, driver);
async generateContentsZip(
driver: DriverInterface,
skipManifestValidation = false,
): Promise<ContentsZip> {
return ContentsZip.buildFromManifest(this, driver, skipManifestValidation);
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/plugin/core/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ export class PluginZip extends ZipFileDriver implements PluginInterface {
manifest: ManifestInterface,
privateKey: PrivateKeyInterface,
driver: DriverInterface,
skipManifestValidation = false,
): Promise<PluginZip> {
const contentsZip = await manifest.generateContentsZip(driver);
const contentsZip = await manifest.generateContentsZip(
driver,
skipManifestValidation,
);
return this.buildFromContentsZip(contentsZip, privateKey);
}

Expand Down
28 changes: 16 additions & 12 deletions src/plugin/packer/pack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Params = {
ppkFilePath: string;
output?: string;
watch?: boolean;
skipManifestValidation?: boolean;
};

// TODO: Reduce statements in this func
Expand Down Expand Up @@ -44,20 +45,22 @@ export const pack = async (params: Params) => {
}

// 3. Validate manifest.json
const result = await manifest.validate(new LocalFSDriver(sourceRootDir));
if (!params.skipManifestValidation) {
const result = await manifest.validate(new LocalFSDriver(sourceRootDir));

if (result.warnings.length > 0) {
result.warnings.forEach((warning) => {
logger.warn(warning);
});
}
if (result.warnings.length > 0) {
result.warnings.forEach((warning) => {
logger.warn(warning);
});
}

if (!result.valid) {
logger.error("Invalid manifest.json:");
result.errors.forEach((msg) => {
logger.error(`- ${msg}`);
});
throw new Error("Invalid manifest.json");
if (!result.valid) {
logger.error("Invalid manifest.json:");
result.errors.forEach((msg) => {
logger.error(`- ${msg}`);
});
throw new Error("Invalid manifest.json");
}
}

// 4. Prepare output directory
Expand All @@ -77,6 +80,7 @@ export const pack = async (params: Params) => {
manifest,
privateKey,
new LocalFSDriver(sourceRootDir),
params.skipManifestValidation,
);

// 7. Start watch mode if watch option is given
Expand Down
14 changes: 9 additions & 5 deletions src/plugin/upload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type Params = {
pluginFilePath: string;
force?: boolean;
watch?: boolean;
skipManifestValidation?: boolean;
};

export const upload = async (
Expand All @@ -33,7 +34,6 @@ export const upload = async (
const buffer = await fs.readFile(pluginFilePath);
const pluginZip = await PluginZip.fromBuffer(buffer);
const pluginId = await pluginZip.getPluginID();
const pluginManifest = await pluginZip.manifest();

// Read plugin info from kintone
const { plugins: installedPlugins } = await apiClient.plugin.getPlugins(
Expand All @@ -45,18 +45,22 @@ export const upload = async (
const installedPlugin = installedPlugins.find((p) => p.id === pluginId);
const isInstalled = installedPlugin !== undefined;

const isSameVersion = installedPlugin?.version === pluginManifest.version;

// Show installation summary
const installationSummary = `
// Reading the manifest requires a well-formed manifest.json, so we skip the
// summary when validation is intentionally bypassed.
if (!params.skipManifestValidation) {
const pluginManifest = await pluginZip.manifest();
const isSameVersion = installedPlugin?.version === pluginManifest.version;
const installationSummary = `
Installation Summary:
Destination: ${restApiClientOptions.baseUrl}
File Path: ${pluginFilePath}
Plugin ID: ${pluginId}
Plugin Name: ${pluginManifest.name}
Current version: ${installedPlugin?.version ?? "(not installed)"}
Target version: ${pluginManifest.version}${isSameVersion ? " (reinstall)" : ""}`;
logger.info(installationSummary);
logger.info(installationSummary);
}

// Get confirmation from user if required
if (!params.force && !params.watch) {
Expand Down
Loading