Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Dan Selman <danscode@selman.org>
- Loading branch information
Showing
189 changed files
with
4,478 additions
and
8 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const ModelManager = require('composer-common').ModelManager; | ||
const ModelFile = require('composer-common').ModelFile; | ||
const CodeGen = require('composer-common').CodeGen; | ||
const Template = require('@accordproject/cicero-core').Template; | ||
const rimraf = require('rimraf'); | ||
const path = require('path'); | ||
const nunjucks = require('nunjucks'); | ||
const AdmZip = require('adm-zip'); | ||
|
||
const plantumlEncoder = require('plantuml-encoder'); | ||
|
||
const { | ||
promisify | ||
} = require('util'); | ||
const { | ||
resolve | ||
} = require('path'); | ||
const fs = require('fs-extra') | ||
const readdir = promisify(fs.readdir); | ||
const rename = promisify(fs.rename); | ||
const stat = promisify(fs.stat); | ||
const mkdirp = require('mkdirp'); | ||
const writeFile = promisify(fs.writeFile); | ||
|
||
async function getFiles(dir) { | ||
const subdirs = await readdir(dir); | ||
const files = await Promise.all(subdirs.map(async (subdir) => { | ||
const res = resolve(dir, subdir); | ||
return (await stat(res)).isDirectory() ? getFiles(res) : res; | ||
})); | ||
return files.reduce((a, f) => a.concat(f), []); | ||
} | ||
|
||
async function generatePlantUML(buildDir, destPath, fileNameNoExt, modelFile) { | ||
// generate the PlantUML for the ModelFile | ||
try { | ||
const generatedPumlFile = `${destPath}/${fileNameNoExt}.puml`; | ||
const visitor = new CodeGen.PlantUMLVisitor(); | ||
const fileWriter = new CodeGen.FileWriter(buildDir); | ||
fileWriter.openFile(generatedPumlFile); | ||
fileWriter.writeLine(0, '@startuml'); | ||
const params = {fileWriter : fileWriter}; | ||
modelFile.accept(visitor, params); | ||
fileWriter.writeLine(0, '@enduml'); | ||
fileWriter.closeFile(); | ||
// save the UML | ||
const modelFilePlantUML = fs.readFileSync(generatedPumlFile, 'utf8'); | ||
const encoded = plantumlEncoder.encode(modelFilePlantUML) | ||
return `http://www.plantuml.com/plantuml/svg/${encoded}`; | ||
} | ||
catch(err) { | ||
console.log(err.message); | ||
} | ||
} | ||
|
||
const rootDir = resolve(__dirname, './src'); | ||
const buildDir = resolve(__dirname, './build'); | ||
let modelFileIndex = []; | ||
|
||
// console.log('build: ' + buildDir); | ||
// console.log('rootDir: ' + rootDir); | ||
|
||
(async function () { | ||
|
||
// delete build directory | ||
rimraf.sync(buildDir); | ||
|
||
nunjucks.configure('./views', { autoescape: true }); | ||
|
||
// copy the logo to build directory | ||
await fs.copy('accord_logo.png', './build/accord_logo.png'); | ||
|
||
// validate and copy all the files | ||
const files = await getFiles(rootDir); | ||
const index = []; | ||
|
||
for( const file of files ) { | ||
const fileName = path.basename(file); | ||
const filePath = path.dirname(fileName); | ||
|
||
if(fileName === 'package.json' && file.indexOf('/node_modules/') === -1) { | ||
// read the parent directory as a template | ||
const templatePath = path.dirname(file); | ||
const dest = templatePath.replace('/src/', '/build/'); | ||
|
||
try { | ||
const template = await Template.fromDirectory(templatePath); | ||
const archive = await template.toArchive(); | ||
const destPath = path.dirname(dest); | ||
await fs.ensureDir(destPath); | ||
const templateId = template.getIdentifier() + '.cta'; | ||
await writeFile( `${destPath}/templateId`, archive); | ||
console.log('Copied: ' + templateId ); | ||
index.push({id: templateId}); | ||
} | ||
catch(err) { | ||
console.log(`Failed processing ${file} with ${err}`); | ||
} | ||
} | ||
|
||
// generate the index html page | ||
const serverRoot = process.env.SERVER_ROOT; | ||
const templateResult = nunjucks.render('index.njk', { serverRoot: serverRoot, templateIndex: index }); | ||
await writeFile( './build/index.html', templateResult); | ||
|
||
// const modelText = fs.readFileSync(file, 'utf8'); | ||
// const modelManager = new ModelManager(); | ||
// const modelFile = new ModelFile(modelManager, modelText, file); | ||
// let modelFilePlantUML = ''; | ||
// // passed validation, so copy to build dir | ||
// const dest = file.replace('/src/', '/build/'); | ||
// const destPath = path.dirname(dest); | ||
// const relative = destPath.slice(buildDir.length); | ||
// // console.log('dest: ' + dest); | ||
// // console.log('destPath: ' + destPath); | ||
// // console.log('relative: ' + relative); | ||
|
||
// const fileName = path.basename(file); | ||
// const fileNameNoExt = path.parse(fileName).name; | ||
|
||
// await fs.ensureDir(destPath); | ||
// let umlURL = ''; | ||
// try { | ||
// modelManager.addModelFile(modelFile, modelFile.getName(), true); | ||
|
||
// // use the FORCE_PUBLISH flag to disable download of | ||
// // external models and model validation | ||
// if(!process.env.FORCE_PUBLISH) { | ||
// modelManager.updateExternalModels(); | ||
// } | ||
|
||
// umlURL = await generatePlantUML(buildDir, destPath, fileNameNoExt, modelFile); | ||
// await generateTypescript(buildDir, destPath, fileNameNoExt, modelFile); | ||
// await generateJsonSchema(buildDir, destPath, fileNameNoExt, modelFile); | ||
// await generateJava(buildDir, destPath, fileNameNoExt, modelFile); | ||
// await generateGo(buildDir, destPath, fileNameNoExt, modelFile); | ||
|
||
// // copy the CTO file to the build dir | ||
// await fs.copy(file, dest); | ||
// console.log('Copied ' + file); | ||
|
||
// // generate the html page for the model | ||
// const generatedHtmlFile = `${relative}/${fileNameNoExt}.html`; | ||
// const serverRoot = process.env.SERVER_ROOT; | ||
// const templateResult = nunjucks.render('model.njk', { serverRoot: serverRoot, modelFile: modelFile, filePath: `${relative}/${fileNameNoExt}`, umlURL: umlURL }); | ||
// fs.writeFile( `./build/${generatedHtmlFile}`, templateResult, function (err) { | ||
// if (err) { | ||
// return console.log(err); | ||
// } | ||
// modelFileIndex.push( {htmlFile: generatedHtmlFile, modelFile: modelFile}); | ||
} | ||
|
||
// }); | ||
})(); |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<!-- Global site tag (gtag.js) - Google Analytics --> | ||
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-120382669-1"></script> | ||
<script> | ||
window.dataLayer = window.dataLayer || []; | ||
function gtag(){dataLayer.push(arguments);} | ||
gtag('js', new Date()); | ||
gtag('config', 'UA-120382669-1'); | ||
</script> | ||
|
||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
|
||
<!-— generic unfurl tags --> | ||
<meta property="og:type" content="website" /> | ||
<meta name="twitter:card" content="summary_large_image"> | ||
<meta name="twitter:domain" value="models.accordproject.org" /> | ||
<meta name="twitter:label1" value="Apache 2.0 Licensed" /> | ||
<meta name="twitter:data1" value="on GitHub.com" /> | ||
<meta name="twitter:label2" value="Contribute" /> | ||
<meta name="twitter:data2" value="at AccordProject.org" /> | ||
|
||
|
||
<!-— facebook open graph tags --> | ||
<meta property="og:url" content="https://models.accordproject.org" /> | ||
<meta property="og:title" content="Accord Project Model Repository" /> | ||
<meta property="og:description" content="Repository hosting all Accord Project models." /> | ||
<meta property="og:image" content="https://models.accordproject.org/accord_logo.png" /> | ||
|
||
<!-— twitter card tags additive with the og: tags --> | ||
<meta name="twitter:title" value="Accord Project Model Repository" /> | ||
<meta name="twitter:description" value="Repository hosting all Accord Project models." /> | ||
<meta name="twitter:image" content="https://models.accordproject.org/accord_logo.png" /> | ||
<meta name="twitter:url" value="https://models.accordproject.org" /> | ||
|
||
|
||
<title>Accord Project Model Repository</title> | ||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.min.css"> | ||
<script defer src="https://use.fontawesome.com/releases/v5.0.7/js/all.js"></script> | ||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css"> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||
<script>hljs.initHighlightingOnLoad();</script> | ||
</head> | ||
|
||
<body> | ||
<a href="https://github.com/accordproject/models"> | ||
<img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png" | ||
alt="Fork me on GitHub"> | ||
</a> | ||
<section class="section"> | ||
<div class="container"> | ||
<a href="/"> | ||
<img src="/accord_logo.png" /> | ||
</a> | ||
</div> | ||
</section> | ||
|
||
|
||
<section class="section"> | ||
<div class="container"> | ||
<h1 class="title"> | ||
Accord Project Template Repository | ||
</h1> | ||
<p class="subtitle"> | ||
Open Source Smart Legal Templates | ||
</p> | ||
</div> | ||
</section> | ||
|
||
<section class="section"> | ||
<div class="container"> | ||
<h2 class="title is-2">Welcome!</h2> | ||
This repository host all Accord Project contract and clause templates. Templates are captured using the | ||
<a href="https://github.com/accordproject/cicero">Accord Project Cicero format</a> | ||
</div> | ||
</section> | ||
|
||
<section class="section"> | ||
<div class="container"> | ||
<h2 class="title is-2">Contributing</h2> | ||
To contribute new templates (or fix existing templates), you can fork this GitHub repository and submit | ||
pull requests to the maintainers. Please join the | ||
<a href="http://accordproject.org">Accord Project</a> Technology Working Group Slack channel. | ||
</div> | ||
</section> | ||
|
||
<section class="section"> | ||
<div class="container"> | ||
<h2 class="title is-2">Templates</h2> | ||
<div class="content"> | ||
<ul> | ||
|
||
<li> | ||
<a href="acceptance-of-delivery@0.0.3.cta">acceptance-of-delivery@0.0.3.cta</a> | ||
</li> | ||
|
||
<li> | ||
<a href="demandforecast@0.0.6.cta">demandforecast@0.0.6.cta</a> | ||
</li> | ||
|
||
<li> | ||
<a href="fragile-goods@0.0.4.cta">fragile-goods@0.0.4.cta</a> | ||
</li> | ||
|
||
<li> | ||
<a href="helloworld@0.0.5.cta">helloworld@0.0.5.cta</a> | ||
</li> | ||
|
||
<li> | ||
<a href="helloworldstate@0.0.5.cta">helloworldstate@0.0.5.cta</a> | ||
</li> | ||
|
||
<li> | ||
<a href="installment-sale@0.0.3.cta">installment-sale@0.0.3.cta</a> | ||
</li> | ||
|
||
<li> | ||
<a href="ip-payment@0.0.3.cta">ip-payment@0.0.3.cta</a> | ||
</li> | ||
|
||
<li> | ||
<a href="latedeliveryandpenalty@0.0.4.cta">latedeliveryandpenalty@0.0.4.cta</a> | ||
</li> | ||
|
||
<li> | ||
<a href="perishable-goods@0.1.0.cta">perishable-goods@0.1.0.cta</a> | ||
</li> | ||
|
||
<li> | ||
<a href="promissory-note@0.0.4.cta">promissory-note@0.0.4.cta</a> | ||
</li> | ||
|
||
<li> | ||
<a href="saft@0.1.1.cta">saft@0.1.1.cta</a> | ||
</li> | ||
|
||
<li> | ||
<a href="safte@0.1.1.cta">safte@0.1.1.cta</a> | ||
</li> | ||
|
||
<li> | ||
<a href="servicelevelagreement@0.0.1.cta">servicelevelagreement@0.0.1.cta</a> | ||
</li> | ||
|
||
<li> | ||
<a href="supplyagreement@0.0.6.cta">supplyagreement@0.0.6.cta</a> | ||
</li> | ||
|
||
<li> | ||
<a href="volumediscount@0.0.6.cta">volumediscount@0.0.6.cta</a> | ||
</li> | ||
|
||
</ul> | ||
</div> | ||
</div> | ||
</section> | ||
|
||
|
||
<footer class="footer"> | ||
<div class="container"> | ||
<div class="content has-text-centered"> | ||
<p> | ||
Copyright 2018 <a href="https://accordproject.org">Accord Project</a>. Licensed under the | ||
<a href="https://www.apache.org/licenses/LICENSE-2.0.html">Apache-2.0</a> Open Source software license. | ||
</p> | ||
</div> | ||
</div> | ||
</footer> | ||
</body> | ||
|
||
</html> |
Binary file not shown.
Oops, something went wrong.