本文整理匯總了TypeScript中@angular-devkit/core.isJsonObject函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript isJsonObject函數的具體用法?TypeScript isJsonObject怎麽用?TypeScript isJsonObject使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了isJsonObject函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: return
return (tree) => {
const angularConfigContent = tree.read('angular.json') || tree.read('.angular.json');
if (!angularConfigContent) {
return;
}
const angularJson = parseJson(angularConfigContent.toString(), JsonParseMode.Loose);
if (!isJsonObject(angularJson) || !isJsonObject(angularJson.projects)) {
// If that field isn't there, no use...
return;
}
// For all projects
for (const [name, project] of Object.entries(angularJson.projects)) {
if (!isJsonObject(project)) {
continue;
}
if (typeof project.root != 'string' || project.projectType !== 'application') {
continue;
}
if (name.endsWith('-e2e')) {
// Skip existing separate E2E projects
continue;
}
const browserslistPath = join(normalize(project.root), 'browserslist');
if (typeof project.sourceRoot === 'string') {
// Move the CLI 7 style browserlist to root if it's there.
const srcBrowsersList = join(normalize(project.sourceRoot), 'browserslist');
if (tree.exists(srcBrowsersList) && !tree.exists(browserslistPath)) {
// TODO: use rename instead.
// This is a hacky workaround. We should be able to just rename it.
// On unit tests the rename works fine but on real projects it fails with
// ERROR! browserslist does not exist..
// This seems to happen because we are both renaming and then commiting an update.
// But it's fine if we read/create/delete. There's a bug somewhere.
// tree.rename(srcBrowsersList, browserslistPath);
const content = tree.read(srcBrowsersList);
if (content) {
tree.create(browserslistPath, content);
tree.delete(srcBrowsersList);
}
}
}
const source = tree.read(browserslistPath);
if (!source) {
tree.create(browserslistPath, browserslistContent);
} else if (!source.toString().toLowerCase().includes('chrome 41')) {
const recorder = tree.beginUpdate(browserslistPath);
recorder.insertRight(source.length, '\nChrome 41 # Googlebot');
tree.commitUpdate(recorder);
}
}
return tree;
};
示例2: return
return (tree) => {
// Simple. Take the ast of polyfills (if it exists) and find the import metadata. Remove it.
const angularConfigContent = tree.read('angular.json') || tree.read('.angular.json');
const rules: Rule[] = [];
if (!angularConfigContent) {
// Is this even an angular project?
return;
}
const angularJson = parseJson(angularConfigContent.toString(), JsonParseMode.Loose);
if (!isJsonObject(angularJson) || !isJsonObject(angularJson.projects)) {
// If that field isn't there, no use...
return;
}
// For all projects
for (const projectName of Object.keys(angularJson.projects)) {
const project = angularJson.projects[projectName];
if (!isJsonObject(project)) {
continue;
}
if (project.projectType !== 'application') {
continue;
}
const architect = project.architect;
if (!isJsonObject(architect)
|| !isJsonObject(architect.build)
|| !isJsonObject(architect.build.options)
|| typeof architect.build.options.polyfills !== 'string') {
continue;
}
rules.push(dropES2015PolyfillsFromFile(architect.build.options.polyfills));
}
return chain(rules);
};
示例3: runCommand
export async function runCommand(
args: string[],
logger: logging.Logger,
workspace: CommandWorkspace,
commands?: CommandMapOptions,
): Promise<number | void> {
if (commands === undefined) {
const commandMapPath = findUp('commands.json', __dirname);
if (commandMapPath === null) {
throw new Error('Unable to find command map.');
}
const cliDir = dirname(commandMapPath);
const commandsText = readFileSync(commandMapPath).toString('utf-8');
const commandJson = json.parseJson(
commandsText,
JsonParseMode.Loose,
{ path: commandMapPath },
);
if (!isJsonObject(commandJson)) {
throw Error('Invalid command.json');
}
commands = {};
for (const commandName of Object.keys(commandJson)) {
const commandValue = commandJson[commandName];
if (typeof commandValue == 'string') {
commands[commandName] = resolve(cliDir, commandValue);
}
}
}
// This registry is exclusively used for flattening schemas, and not for validating.
const registry = new schema.CoreSchemaRegistry([]);
registry.registerUriHandler((uri: string) => {
if (uri.startsWith('ng-cli://')) {
const content = readFileSync(join(__dirname, '..', uri.substr('ng-cli://'.length)), 'utf-8');
return Promise.resolve(JSON.parse(content));
} else {
return null;
}
});
// Normalize the commandMap
const commandMap: CommandDescriptionMap = {};
for (const name of Object.keys(commands)) {
const schemaPath = commands[name];
const schemaContent = readFileSync(schemaPath, 'utf-8');
const schema = json.parseJson(schemaContent, JsonParseMode.Loose, { path: schemaPath });
if (!isJsonObject(schema)) {
throw new Error('Invalid command JSON loaded from ' + JSON.stringify(schemaPath));
}
commandMap[name] =
await parseJsonSchemaToCommandDescription(name, schemaPath, registry, schema);
}
let commandName: string | undefined = undefined;
for (let i = 0; i < args.length; i++) {
const arg = args[i];
if (arg in commandMap) {
commandName = arg;
args.splice(i, 1);
break;
} else if (!arg.startsWith('-')) {
commandName = arg;
args.splice(i, 1);
break;
}
}
// if no commands were found, use `help`.
if (commandName === undefined) {
if (args.length === 1 && args[0] === '--version') {
commandName = 'version';
} else {
commandName = 'help';
}
}
let description: CommandDescription | null = null;
if (commandName !== undefined) {
if (commandMap[commandName]) {
description = commandMap[commandName];
} else {
Object.keys(commandMap).forEach(name => {
const commandDescription = commandMap[name];
const aliases = commandDescription.aliases;
let found = false;
if (aliases) {
if (aliases.some(alias => alias === commandName)) {
found = true;
}
}
if (found) {
if (description) {
//.........這裏部分代碼省略.........