webext-schema
Advanced tools
Comparing version 0.6.11 to 0.7.0
@@ -22,3 +22,3 @@ /** | ||
this._channel = | ||
isString(ch) && /(?:beta|central|release)/.test(ch) && ch || "beta"; | ||
isString(ch) && /(?:beta|central|mail|release)/.test(ch) && ch || "beta"; | ||
} | ||
@@ -32,3 +32,3 @@ | ||
set channel(ch) { | ||
if (isString(ch) && /(?:beta|central|release)/.test(ch)) { | ||
if (isString(ch) && /(?:beta|central|mail|release)/.test(ch)) { | ||
this._channel = ch; | ||
@@ -43,4 +43,6 @@ } | ||
_parseSchemaContent() { | ||
const fileName = | ||
this._channel === "mail" && "mailext.json" || "webext.json"; | ||
const file = path.resolve( | ||
path.join(__dirname, "../", "schemas", this._channel, "all.json") | ||
path.join(__dirname, "../", "schemas", this._channel, fileName) | ||
); | ||
@@ -47,0 +49,0 @@ const content = fs.readFileSync(file, { |
@@ -48,2 +48,5 @@ /** | ||
break; | ||
case "mail": | ||
dir = "comm-central/"; | ||
break; | ||
case "release": | ||
@@ -59,2 +62,23 @@ dir = "releases/mozilla-release/"; | ||
/** | ||
* get schema data | ||
* @param {string} file - file name | ||
* @param {string} baseUrl - base URL | ||
* @returns {Object} - schema data | ||
*/ | ||
const getSchemaData = async (file, baseUrl) => { | ||
if (!isString(file)) { | ||
throw new TypeError(`Expected String but got ${getType(file)}.`); | ||
} | ||
if (!isString(baseUrl)) { | ||
throw new TypeError(`Expected String but got ${getType(baseUrl)}.`); | ||
} | ||
const {href} = new URL(file, baseUrl); | ||
const text = await fetchText(href); | ||
const schema = JSON5.parse(text); | ||
return { | ||
file, schema, | ||
}; | ||
}; | ||
/** | ||
* get schema file list from jar manifest | ||
@@ -70,3 +94,3 @@ * @param {string} baseUrl - base URL | ||
const text = await fetchText(href); | ||
const reg = /content\/(?:browser|extensions)\/schemas\/([\da-zA-Z_]+\.json)/; | ||
const reg = /content\/(?:browser|extensions|messenger)\/schemas\/([\da-zA-Z_]+\.json)/; | ||
const items = text.split("\n"); | ||
@@ -85,28 +109,44 @@ const arr = []; | ||
/** | ||
* get schema data | ||
* @param {string} file - file name | ||
* get all schema data | ||
* @param {string} baseUrl - base URL | ||
* @returns {Object} - schema data | ||
* @returns {Array} - schemas data in array | ||
*/ | ||
const getSchemaData = async (file, baseUrl) => { | ||
if (!isString(file)) { | ||
throw new TypeError(`Expected String but got ${getType(file)}.`); | ||
const getAllSchemaData = async baseUrl => { | ||
if (!isString(baseUrl)) { | ||
throw new TypeError(`Expected String but got ${getType(baseUrl)}.`); | ||
} | ||
const items = await getFileList(baseUrl); | ||
const func = []; | ||
for (const item of items) { | ||
func.push(getSchemaData(item, baseUrl)); | ||
} | ||
return Promise.all(func); | ||
}; | ||
/** | ||
* get listed schema data | ||
* @param {string} baseUrl - base URL | ||
* @param {Array} arr - array of schema file names | ||
* @returns {Array} - schema data in array | ||
*/ | ||
const getListedSchemaData = async (baseUrl, arr) => { | ||
if (!isString(baseUrl)) { | ||
throw new TypeError(`Expected String but got ${getType(baseUrl)}.`); | ||
} | ||
const {href} = new URL(file, baseUrl); | ||
const text = await fetchText(href); | ||
const schema = JSON5.parse(text); | ||
return { | ||
file, schema, | ||
}; | ||
if (!Array.isArray(arr)) { | ||
throw new TypeError(`Expected Array but got ${getType(arr)}.`); | ||
} | ||
const func = []; | ||
for (const item of arr) { | ||
func.push(getSchemaData(item, baseUrl)); | ||
} | ||
return Promise.all(func); | ||
}; | ||
/** | ||
* get all schema data | ||
* get MailExtensions schema data | ||
* @param {string} baseUrl - base URL | ||
* @returns {Array} - schemas data in array | ||
* @returns {Promise.<Array>} - results of each handler | ||
*/ | ||
const getAllSchemaData = async baseUrl => { | ||
const getMailExtSchemaData = async baseUrl => { | ||
if (!isString(baseUrl)) { | ||
@@ -116,5 +156,12 @@ throw new TypeError(`Expected String but got ${getType(baseUrl)}.`); | ||
const items = await getFileList(baseUrl); | ||
const schemaUrl = `${baseUrl}schemas/`; | ||
const excludeFile = [ | ||
"commands.json", | ||
"pkcs11.json", | ||
]; | ||
const func = []; | ||
for (const item of items) { | ||
func.push(getSchemaData(item, baseUrl)); | ||
if (!excludeFile.includes(item)) { | ||
func.push(getSchemaData(item, schemaUrl)); | ||
} | ||
} | ||
@@ -131,7 +178,28 @@ return Promise.all(func); | ||
const channelUrl = getChannelUrl(channel); | ||
const arr = await Promise.all([ | ||
getAllSchemaData(`${channelUrl}browser/components/extensions/schemas/`), | ||
getAllSchemaData(`${channelUrl}toolkit/components/extensions/schemas/`), | ||
]); | ||
const schema = {}; | ||
let arr; | ||
if (channel === "mail") { | ||
const browserItems = [ | ||
"commands.json", | ||
"pkcs11.json", | ||
]; | ||
const toolkitItems = [ | ||
"content_scripts.json", "experiments.json", "extension.json", "i18n.json", | ||
"management.json", "permissions.json", "runtime.json", "theme.json", | ||
]; | ||
const browserBaseUrl = | ||
`${getChannelUrl("central")}browser/components/extensions/schemas/`; | ||
const toolkitBaseUrl = | ||
`${getChannelUrl("central")}toolkit/components/extensions/schemas/`; | ||
arr = await Promise.all([ | ||
getListedSchemaData(browserBaseUrl, browserItems), | ||
getListedSchemaData(toolkitBaseUrl, toolkitItems), | ||
getMailExtSchemaData(`${channelUrl}mail/components/extensions/`), | ||
]); | ||
} else { | ||
arr = await Promise.all([ | ||
getAllSchemaData(`${channelUrl}browser/components/extensions/schemas/`), | ||
getAllSchemaData(`${channelUrl}toolkit/components/extensions/schemas/`), | ||
]); | ||
} | ||
for (const items of arr) { | ||
@@ -158,4 +226,5 @@ for (const item of items) { | ||
const content = `${JSON.stringify(schema, null, INDENT)}\n`; | ||
const fileName = channel === "mail" && "mailext" || "webext"; | ||
const filePath = | ||
path.resolve(path.join(DIR_CWD, "schemas", channel, "all.json")); | ||
path.resolve(path.join(DIR_CWD, "schemas", channel, `${fileName}.json`)); | ||
const file = await createFile(filePath, content, { | ||
@@ -185,2 +254,3 @@ encoding: CHAR, flag: "w", mode: PERM_FILE, | ||
saveSchemaFile("release", info), | ||
saveSchemaFile("mail", info), | ||
); | ||
@@ -197,2 +267,4 @@ } | ||
getFileList, | ||
getListedSchemaData, | ||
getMailExtSchemaData, | ||
getSchemaData, | ||
@@ -199,0 +271,0 @@ saveSchemaFile, |
@@ -20,2 +20,3 @@ { | ||
"update:central": "node index update -c central -i", | ||
"update:mail": "node index update -c mail -i", | ||
"update:release": "node index update -c release -i" | ||
@@ -38,3 +39,3 @@ }, | ||
}, | ||
"version": "0.6.11" | ||
"version": "0.7.0" | ||
} |
@@ -26,7 +26,5 @@ [![Build Status](https://travis-ci.org/asamuzaK/webext-schema.svg?branch=master)](https://travis-ci.org/asamuzaK/webext-schema) | ||
Schemas for "release", "beta", "central" are available. | ||
Release channel defaults to "beta". | ||
Channel defaults to "beta". | ||
"central", "beta", "release" for WebExtensions, and "mail" for MailExtensions are available. | ||
If you want to specify a particular channel, pass one of the three channels as an argument when creating the instance. | ||
``` | ||
@@ -36,3 +34,3 @@ const schema = new Schema("central"); | ||
Or you can set it afterwards. | ||
Also, you can set it afterwards. | ||
@@ -39,0 +37,0 @@ ``` |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
2293847
13
64685
97
2