因此,如果我setTimeout
在 final 上设置 a console.log
,它会很好地记录下来,但我想我的新问题是,即使有then
陈述,为什么在一切都解决之后它不会触发?
我有一个奇怪的错误,我无法弄清楚为什么它没有打印我期望的整个结构。我没有收到任何错误,我确实尝试输入了一些console.log
,但似乎只是让anyOf
属性记录下来。它总是显示为空。
我的主要问题是hold
没有正确记录。它显示anyOf
为空。
const $ = require('cheerio');
const Axios = require('axios').default;
let name = 'sqs';
let basePath = '/AWS_SQS.html'
let hold = {
'$schema': 'http://json-schema.org/draft-07/schema#',
'$id': `cf${name}`,
'description': `CF ${name}`,
'properties': {
'Type': {
'type': 'string',
'enum': [],
},
},
'anyOf': [] // this keeps coming up empty
};
let typeProperties = (t, p) => {
return {
'if': { 'properties': { 'Type': { 'const': t } } },
'then': {
'properties': {
'Properties': {
'type': 'object',
'properties': p,
},
},
},
}
}
const makeRequest = (bpath) => {
let url = 'https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/' + bpath
return Axios.get(url)
.then((res) => {
return res.data;
})
.catch(console.log);
};
let getData = makeRequest(basePath).then((data) => {
let match = $('.listitem>p>a', data);
match.map((i, e) => {
let t = $(e);
hold.properties.Type.enum.push(t.text());
makeRequest(t.attr('href')).then((newdata) => {
let holdProperties = {}
let pType = $($('.variablelist', newdata)[0])
$('.term>.code', pType).map((i, elem) => {
let propertyName = $(elem).text()
holdProperties[propertyName] = {}
})
hold.anyOf.push(typeProperties(t.text(), holdProperties))
}).catch(console.log)
});
}).catch(console.log)
getData.then(() => {
// Why doesnt this log fully once everything is resolved? If i put a setTimeout here, it will work fine
console.log(JSON.stringify(hold));
}).catch(console.log)
收到一只叮咚
相关分类