Skip to content

Commit c3cb3b0

Browse files
Extract data from accord projects
1 parent 541748e commit c3cb3b0

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

Diff for: src/services/ContractMetadata.coffee

+18
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,24 @@ class ContractMetadata
5151
cto_paths: ctoPathsResult
5252
return result
5353

54+
# @todo Deduplicate method singleDirectory and iterateFoldersInDirectory
55+
singleDirectory: (directory) =>
56+
dir = [directory]
57+
result = []
58+
dir.map (d) ->
59+
c = []
60+
files = find.fileSync d
61+
files.map (f) ->
62+
if f.toLowerCase().endsWith('.cto')
63+
c.push f
64+
65+
#console.log f
66+
result.push
67+
project_path: d
68+
cto_paths: c
69+
70+
return result
71+
5472
# Finds all cto models
5573
# @todo Make more async
5674
iterateFoldersInDirectory: (directory) =>

Diff for: src/services/SetupClient.coffee

+14-5
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,15 @@ class SetupClient
3838
console.log 'to directory ' + directoryToCreate
3939
@deploy guid, directoryToCreate
4040

41+
program.usage('export <dir> <to json file>').command('export <dir> <to json file>').action (directory, jsonFile, cmd) =>
42+
console.log 'extract single directory to json file'
43+
json = await @extract directory, jsonFile, false
44+
@createFile jsonFile, JSON.stringify(json)
45+
4146
# Extract JSON from Cicero projects
42-
program.usage('extract <dir> <to json file>').command('extract <dir> <to json file>').action (directory, jsonFile, cmd) =>
43-
console.log 'extract directory to json file'
44-
json = await @extract directory, jsonFile
47+
program.usage('exportmulti <dir> <to json file>').command('exportmulti <dir> <to json file>').action (directory, jsonFile, cmd) =>
48+
console.log 'extract multiple directory to json file'
49+
json = await @extract directory, jsonFile, true
4550
@createFile jsonFile, JSON.stringify(json)
4651

4752
# Subscribe to server to await work events
@@ -56,9 +61,13 @@ class SetupClient
5661
contractJson = await @fetchContractJsonFromServer guid
5762
await @createProject directoryToCreate, contractJson
5863

59-
extract: (directory, jsonFile) =>
64+
extract: (directory, jsonFile, isMulti) =>
6065
meta = new ContractMetadata()
61-
i = await meta.iterateFoldersInDirectory directory
66+
if isMulti
67+
i = await meta.iterateFoldersInDirectory directory
68+
else
69+
i = await meta.singleDirectory directory
70+
6271
c = await meta.directoriesToJson i
6372
m = await meta.metaDataOfDirectoriesJson c
6473
m

Diff for: test_extract.bat

-1
This file was deleted.

Diff for: test_extract_multi.bat

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
call run exportmulti "C:\home\projects\accord\cicero-template-library\src" output.json

Diff for: test_extract_single.bat

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
call run export "C:\home\projects\accord\cicero-template-library\src\one-time-payment-tr" output.json

0 commit comments

Comments
 (0)