92 lines
2.6 KiB
JavaScript
92 lines
2.6 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const fs_1 = require("fs");
|
|
const paths_1 = require("./paths");
|
|
function default_1(name) {
|
|
var meta = {
|
|
name: name,
|
|
namespace: 'zomo.dev',
|
|
match: '',
|
|
excludematch: '',
|
|
version: '0.0.0',
|
|
description: '',
|
|
icon: '',
|
|
require: '',
|
|
resource: '',
|
|
runat: '',
|
|
noframes: false,
|
|
grant: '',
|
|
injectinto: '',
|
|
downloadURL: (0, paths_1.FileUrl)(name),
|
|
supportURL: paths_1.SupportUrl,
|
|
homepageURL: paths_1.BaseUrl,
|
|
unwrap: false,
|
|
};
|
|
let metaPath = (0, paths_1.ScriptPath)(name).meta;
|
|
if ((0, fs_1.existsSync)(metaPath) && (0, fs_1.lstatSync)(metaPath).isFile()) {
|
|
try {
|
|
let args = JSON.parse((0, fs_1.readFileSync)(metaPath).toString());
|
|
let key;
|
|
for (key in meta) {
|
|
let val = args[key];
|
|
//cases where the value is empty
|
|
if (val === undefined)
|
|
continue;
|
|
if (val === false)
|
|
continue;
|
|
if (val === '')
|
|
continue;
|
|
meta[key] = val;
|
|
}
|
|
}
|
|
catch (e) {
|
|
console.log(e);
|
|
}
|
|
}
|
|
else {
|
|
console.log(`${metaPath} not found, using default metadata`);
|
|
}
|
|
const keyConversion = {
|
|
injectinto: 'inject-into',
|
|
excludematch: 'exclude-match',
|
|
};
|
|
return [
|
|
meta,
|
|
`// ==UserScript==
|
|
${Object.keys(meta)
|
|
.filter(key => {
|
|
let val = meta[key];
|
|
if (val === undefined)
|
|
return false;
|
|
if (val === false)
|
|
return false;
|
|
if (val === '')
|
|
return false;
|
|
return true;
|
|
})
|
|
.map(key => {
|
|
let val = meta[key];
|
|
let key_str = key in keyConversion
|
|
? keyConversion[key]
|
|
: key;
|
|
key_str = key_str.padEnd(12, ' ');
|
|
if (typeof val === 'boolean') {
|
|
if (val)
|
|
return `// @${key_str}`;
|
|
}
|
|
else if (typeof val === 'string') {
|
|
return `// @${key_str} ${val}`;
|
|
}
|
|
else if (Array.isArray(val)) {
|
|
return val.map(v => `// @${key_str} ${v}`).join('\n');
|
|
}
|
|
return '';
|
|
})
|
|
.filter(l => l.length)
|
|
.join('\n')}
|
|
// ==/UserScript==
|
|
`,
|
|
];
|
|
}
|
|
exports.default = default_1;
|
|
//# sourceMappingURL=readmeta.js.map
|