61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/crossplane/cli.rb', line 61
def build(filename)
dirname = Dir.pwd unless dirname
payload = JSON.parse(File.read(filename))
builder = CrossPlane::Builder.new(
payload: payload['config'][0]['parsed']
)
if not options['force'] and not options['stdout']
existing = []
payload['config'].each do |config|
path = config['file']
p = Pathname.new(path)
path = p.absolute? ? path: File.join(dirname, path)
if File.exist?(path)
existing.push(path)
end
end
if existing.length > 0
puts(format('building %s would overwrite these files:', filename))
puts existing.join("\n")
end
end
payload['config'].each do |config|
path = config['file']
p = Pathname.new(path)
path = p.absolute? ? path: File.join(dirname, path)
parsed = config['parsed']
output = builder.build(
parsed,
indent: options['indent'] || 4, tabs: options['tabs'],
header: options['header']
)
output = output.rstrip + "\n"
puts output
end
end
|