Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
state.result = new FileRef(fn, datatype, filename);
return true;
},
dumpInstanceOf: FileRef,
dumpPredicate: function(fref) {
return fref.fn == fn && fref.datatype == datatype;
},
dumpRepresenter: function(fref) {
return fref.filename;
}
});
};
// YAML binary type
var BINARY_TYPE =
JsYaml.DEFAULT_SAFE_SCHEMA.compiledTypeMap['tag:yaml.org,2002:binary']
// YAML schema used for YAML files containing file references.
var fileRefSchema = JsYaml.Schema.create(
[JsYaml.JSON_SCHEMA],
[BINARY_TYPE,
createFileRefType('!includeYaml', 'include', 'yaml'),
createFileRefType('!includeBinary', 'include', 'binary'),
createFileRefType('!hashYaml', 'hash', 'yaml'),
createFileRefType('!hashBinary', 'hash', 'binary')]);
// Reads YAML and handles file references.
function YamlReader() {
// Maps from data type + file name to file data.
this.dataMap = {yaml: {}, binary: {}};
// Maps from data type + file name to boolean of whether or not this file
// currently being loaded. This can detect circular dependencies.
state.result = new FileRef(fn, datatype, filename);
return true;
},
dumpInstanceOf: FileRef,
dumpPredicate: function(fref) {
return fref.fn == fn && fref.datatype == datatype;
},
dumpRepresenter: function(fref) {
return fref.filename;
}
});
};
// YAML binary type
var BINARY_TYPE =
JsYaml.DEFAULT_SAFE_SCHEMA.compiledTypeMap['tag:yaml.org,2002:binary']
// YAML schema used for YAML files containing file references.
var fileRefSchema = JsYaml.Schema.create(
[JsYaml.JSON_SCHEMA],
[BINARY_TYPE,
createFileRefType('!includeYaml', 'include', 'yaml'),
createFileRefType('!includeBinary', 'include', 'binary'),
createFileRefType('!hashYaml', 'hash', 'yaml'),
createFileRefType('!hashBinary', 'hash', 'binary')]);
// Reads YAML and handles file references.
class YamlReader {
constructor() {
// Maps from data type + file name to file data.
this.dataMap = {yaml: {}, binary: {}};
// Maps from data type + file name to boolean of whether or not this file
files.forEach((file) => {
const content = fs.readFileSync(path.join(cwd, file), 'utf-8');
try {
yaml.loadAll(content, () => {}, { schema: yaml.DEFAULT_SAFE_SCHEMA });
} catch (e) {
logger.error(`An error has occurred in: ${file}`);
logger.error(e.message);
result = false;
}
});
return result ? resolve() : reject();
const ImageType = new yaml.Type('image', {
kind: 'scalar',
instanceOf: AssetProxy,
represent(value) {
return `${ value.path }`;
},
resolve(value) {
if (value === null) return false;
if (value instanceof AssetProxy) return true;
return false;
},
});
const OutputSchema = new yaml.Schema({
include: yaml.DEFAULT_SAFE_SCHEMA.include,
implicit: [MomentType, ImageType].concat(yaml.DEFAULT_SAFE_SCHEMA.implicit),
explicit: yaml.DEFAULT_SAFE_SCHEMA.explicit,
});
export default {
fromFile(content) {
return yaml.safeLoad(content);
},
toFile(data, sortedKeys = []) {
return yaml.safeDump(data, { schema: OutputSchema, sortKeys: sortKeys(sortedKeys) });
}
}
module.exports = function(yamlTags) {
let yamlTypes = yamlTags.map(tagToType);
let schema = new yaml.Schema({
include: [yaml.DEFAULT_SAFE_SCHEMA],
explicit: yamlTypes
});
return function(file) {
let content = fs.readFileSync(file, 'utf8');
return yaml.load(content, { schema });
};
};
const ImageType = new yaml.Type('image', {
kind: 'scalar',
instanceOf: AssetProxy,
represent(value) {
return `${value.path}`;
},
resolve(value) {
if (value === null) return false;
if (value instanceof AssetProxy) return true;
return false;
},
});
const OutputSchema = new yaml.Schema({
include: yaml.DEFAULT_SAFE_SCHEMA.include,
implicit: [MomentType, ImageType].concat(yaml.DEFAULT_SAFE_SCHEMA.implicit),
explicit: yaml.DEFAULT_SAFE_SCHEMA.explicit,
});
export default {
fromFile(content) {
return yaml.safeLoad(content);
},
toFile(data, sortedKeys = []) {
return yaml.safeDump(data, { schema: OutputSchema, sortKeys: sortKeys(sortedKeys) });
},
};
instanceOf: AssetProxy,
represent(value) {
return `${ value.path }`;
},
resolve(value) {
if (value === null) return false;
if (value instanceof AssetProxy) return true;
return false;
},
});
const OutputSchema = new yaml.Schema({
include: yaml.DEFAULT_SAFE_SCHEMA.include,
implicit: [MomentType, ImageType].concat(yaml.DEFAULT_SAFE_SCHEMA.implicit),
explicit: yaml.DEFAULT_SAFE_SCHEMA.explicit,
});
export default {
fromFile(content) {
return yaml.safeLoad(content);
},
toFile(data, sortedKeys = []) {
return yaml.safeDump(data, { schema: OutputSchema, sortKeys: sortKeys(sortedKeys) });
}
}
const openpgp = require('openpgp')
const username = require('username')
const readline = require('readline')
const split = require('split')
const semver = require('semver')
/**
* Setup Custom YAML Parsing
*/
const yaml = require('js-yaml')
const PythonUnicodeType = new yaml.Type('tag:yaml.org,2002:python/unicode', {
kind: 'scalar',
construct: (data) => { return data !== null ? data : ''; }
})
const PYTHON_SCHEMA = new yaml.Schema({
include: [yaml.DEFAULT_SAFE_SCHEMA],
explicit: [PythonUnicodeType]
})
const currentUser = process.env.SUDO_USER || username.sync()
const doc = `
Usage:
sift [options] list-upgrades [--pre-release]
sift [options] install [--pre-release] [--version=] [--mode=] [--user=]
sift [options] update
sift [options] upgrade [--pre-release]
sift [options] self-upgrade [--pre-release]
sift [options] version
sift [options] debug
sift -h | --help | -v
schema() {
if (this._schema) return this._schema
let plugins = this._pluginM.list()
this._schema = new yaml.Schema({
include: [yaml.DEFAULT_SAFE_SCHEMA],
explicit: plugins
})
return this._schema
}
}