【发布时间】:2020-12-07 06:45:51
【问题描述】:
我编写了一个 Ruby 脚本,它将一个包含国家/地区键和信息列表的大型 YAML 文件(称为 travel.yaml)拆分为每个国家/地区的单独文件。
data = YAML.load(File.read('./src/constants/travel.yaml'))
data.fetch('countries').each do |key, value|
File.open("./src/constants/countries/#{key}.yaml", 'w') { |file| file.write({ key => value }.to_yaml) }
end
使每个文件看起来像这样:
---
BA:
sources:
domestic:
- Wearing masks and social distancing (a minimum of 2 metres) are [mandatory in
all public places](https://www.oecd.org/south-east-europe/COVID-19-Crisis-in-Bosnia-and-Herzegovina.pdf).
inbound:
- The BiH Council of Ministers has announced that it will allow entry to the citizens
of Croatia, Serbia, and Montenegro as of June 1, 2020. There is [still a ban
to entry for non-resident foreign nationals.](https://ba.usembassy.gov/covid-19-information/)
visa_quarantine:
- Both the Republika Srpska and the Federation have [abolished self-isolation
measures for people entering BiH.](https://ba.usembassy.gov/covid-19-information/).
travel:
domestic: partial
inbound: partial
inbound_allowed:
- HR
- RS
- ME
在拆分travel.yaml之前,是这样消费的:
import TravelDefaults from '@/constants/travel.yaml';
export const Travel = TravelDefaults;
const { countries, checked_on } = Travel;
我现在想一次加载所有单独的 YAML 文件并使用它们(无需单独导入每个文件)。
我该怎么做?这必须在 VUE 和 Typescript 中完成。
【问题讨论】:
-
你可以将它们合并成一个大的 YAML 文件(称为
travel.yaml)
标签: javascript typescript vue.js yaml