本文整理汇总了TypeScript中cjson.load函数的典型用法代码示例。如果您正苦于以下问题:TypeScript load函数的具体用法?TypeScript load怎么用?TypeScript load使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了load函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: parse
public static parse(configPath:string) : Config {
var config:Config;
if (configPath.match(/\.json$/)) {
config = cjson.load(configPath);
} else if (configPath.match(/\.js$/)) {
config = require(configPath);
} else {
// fallback to json parsing
config = cjson.load(configPath);
}
config = this.preprocess(config);
this.validate(config);
return config;
}
示例2: packageJsonIsValid
export function packageJsonIsValid(
sourceDirName: string,
sourceDir: string,
projectDir: string
): void {
const packageJsonFile = path.join(sourceDir, "package.json");
if (!fsutils.fileExistsSync(packageJsonFile)) {
const msg = `No npm package found in functions source directory. Please run 'npm init' inside ${sourceDirName}`;
throw new FirebaseError(msg);
}
try {
const data = cjson.load(packageJsonFile);
logger.debug("> [functions] package.json contents:", JSON.stringify(data, null, 2));
const indexJsFile = path.join(sourceDir, data.main || "index.js");
if (!fsutils.fileExistsSync(indexJsFile)) {
const msg = `${path.relative(
projectDir,
indexJsFile
)} does not exist, can't deploy Cloud Functions`;
throw new FirebaseError(msg);
}
} catch (e) {
const msg = `There was an error reading ${sourceDirName}${path.sep}package.json:\n\n ${
e.message
}`;
throw new FirebaseError(msg);
}
}
示例3: getRuntimeChoice
export function getRuntimeChoice(sourceDir: string): any {
const packageJsonPath = path.join(sourceDir, "package.json");
const loaded = cjson.load(packageJsonPath);
const engines = loaded.engines;
if (!engines || !engines.node) {
return null;
// TODO(b/129422952): Change to throw error instead of returning null
// when engines field in package.json becomes required:
// throw new FirebaseError(ENGINES_FIELD_REQUIRED_MSG, { exit: 1 });
}
const runtime = ENGINE_RUNTIMES[engines.node];
if (!runtime) {
throw new FirebaseError(UNSUPPORTED_NODE_VERSION_MSG, { exit: 1 });
}
if (runtime === "nodejs6") {
utils.logWarning(DEPRECATION_WARNING_MSG);
} else {
// for any other runtime (8 or 10)
if (functionsSDKTooOld(loaded)) {
utils.logWarning(FUNCTIONS_SDK_VERSION_TOO_OLD_WARNING);
}
}
return runtime;
}
示例4: loadSymbols
function loadSymbols ( secpath: string ): Symbol[]
{
try {
var obj = cjson.load( secpath );
var res = tv4.validateResult(obj, schema);
} catch(ex) {
throw new Error( secpath + ': ' + ex.message );
}
if (!res.valid)
throw new Error( secpath + ': ' + res.error.message || "Invalid security file" );
return obj;
}
示例5: getSwNavigationUrlChecker
export function getSwNavigationUrlChecker() {
const config = loadJson(`${AIO_DIR}/ngsw-config.json`);
const navigationUrlSpecs = processNavigationUrls('', config.navigationUrls);
const includePatterns = navigationUrlSpecs
.filter(spec => spec.positive)
.map(spec => new RegExp(spec.regex));
const excludePatterns = navigationUrlSpecs
.filter(spec => !spec.positive)
.map(spec => new RegExp(spec.regex));
return (url: string) =>
includePatterns.some(regex => regex.test(url))
&& !excludePatterns.some(regex => regex.test(url));
}
示例6: loadSWRoutes
export function loadSWRoutes() {
const pathToSWManifest = path.resolve(__dirname, '../../ngsw-manifest.json');
const contents = cjson.load(pathToSWManifest);
const routes = contents.routing.routes;
return Object.keys(routes).map(route => {
const routeConfig = routes[route];
switch (routeConfig.match) {
case 'exact':
return (url) => url === route;
case 'prefix':
return (url) => url.startsWith(route);
case 'regex':
const regex = new RegExp(route);
return (url) => regex.test(url);
default:
throw new Error(`unknown route config: ${route} - ${routeConfig.match}`);
}
});
}
示例7: loadRedirects
export function loadRedirects(): FirebaseRedirectConfig[] {
const pathToFirebaseJSON = path.resolve(__dirname, '../../firebase.json');
const contents = cjson.load(pathToFirebaseJSON);
return contents.hosting.redirects;
}
示例8: loadRedirects
export function loadRedirects(): FirebaseRedirectConfig[] {
const pathToFirebaseJSON = `${AIO_DIR}/firebase.json`;
const contents = loadJson(pathToFirebaseJSON);
return contents.hosting.redirects;
}