-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
133 additions
and
52 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
File renamed without changes.
File renamed without changes.
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,17 @@ | ||
import { sourceList } from "./sourcelist"; | ||
|
||
interface ManifestInterface { | ||
sourceList(): string[]; | ||
} | ||
|
||
class ManifestV1 implements ManifestInterface { | ||
manifest: any; | ||
|
||
constructor(json: string) { | ||
/* noop */ | ||
} | ||
|
||
sourceList(): string[] { | ||
return sourceList(sourceList(this.manifest)); | ||
} | ||
} |
File renamed without changes.
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,64 @@ | ||
import validate from "@kintone/plugin-manifest-validator"; | ||
import _debug from "debug"; | ||
import fs from "fs"; | ||
import path from "path"; | ||
import { logger } from "../../../utils/log"; | ||
import { generateErrorMessages } from "./gen-error-msg"; | ||
|
||
const debug = _debug("validate"); | ||
|
||
export const validateManifestJson = ( | ||
manifestJson: string, | ||
pluginDir: string, | ||
) => { | ||
const manifest = JSON.parse(manifestJson); | ||
const result = validate(manifest, { | ||
maxFileSize: validateMaxFileSize(pluginDir), | ||
fileExists: validateFileExists(pluginDir), | ||
}); | ||
debug(result); | ||
|
||
if (result.warnings && result.warnings.length > 0) { | ||
result.warnings.forEach((warning) => { | ||
logger.warn(warning.message); | ||
}); | ||
} | ||
|
||
if (!result.valid) { | ||
const msgs = generateErrorMessages(result.errors ?? []); | ||
logger.error("Invalid manifest.json:"); | ||
msgs.forEach((msg) => { | ||
logger.error(`- ${msg}`); | ||
}); | ||
throw new Error("Invalid manifest.json"); | ||
} | ||
}; | ||
|
||
/** | ||
* Return validator for `maxFileSize` keyword | ||
*/ | ||
const validateMaxFileSize = (pluginDir: string) => { | ||
return (maxBytes: number, filePath: string) => { | ||
try { | ||
const stat = fs.statSync(path.join(pluginDir, filePath)); | ||
return stat.size <= maxBytes; | ||
} catch (_) { | ||
return false; | ||
} | ||
}; | ||
}; | ||
|
||
/** | ||
* | ||
* @param pluginDir | ||
*/ | ||
const validateFileExists = (pluginDir: string) => { | ||
return (filePath: string) => { | ||
try { | ||
const stat = fs.statSync(path.join(pluginDir, filePath)); | ||
return stat.isFile(); | ||
} catch (_) { | ||
return false; | ||
} | ||
}; | ||
}; |
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