Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial commit for node.js version #34

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,15 @@ Si vous cherchez un moyen d'utiliser ces contrats avec vos clients (travail à l

**Pour générer un contrat**, vous devez d'abord:

* installer les dépendances ruby/bundler: `bundle`
* définir vos informations personnelles dans `config.json` (`config.sample.json` est dispo en exemple).

une fois ceci fait, vous pouvez générer les contrats en faisant `rake`
Puis 2 possibilités:
* Vous utilisez ruby (non compactible windows à cause d'une des librairies): installer les dépendances ruby/bundler: `bundle`, puis générer les contrats en faisant `rake`
* Vous utilisez node.js: installer les dépendances node: `npm i`, puis générer les contrats en faisant `npm run build`

**Notes sur la version node.js**
Si vous voulez modifier la 'css' des contrat générés en pdf, vous pouvez via le fichier md-style.css. Et pour tester/ajuster le rendu vous devez passer par le fichier html intermédiaire, que vous trouverez dans le dossier contracts en lancant `npm run debug`;
Et si vous voulez modifier d'autres options comme les marges, le header ou le footer, modifiez la config utilisée par la librairie [mdpdf](https://github.com/BlueHatbRit/mdpdf) dans `generateContracts.js`.

## License

Expand Down
44 changes: 44 additions & 0 deletions generateContracts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const handlebars = require('handlebars')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
'require' is not defined.
Missing semicolon.

const mdpdf = require('mdpdf');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
'require' is not defined.

const path = require('path');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
'require' is not defined.

const fs = require('fs');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
'require' is not defined.

const config = require('./config.json');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
'require' is not defined.

const args = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).

debug: process.argv.includes('--debug')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'process' is not defined.

};

function generatePdf (fileNameWithoutExt) {
const fileNameCompiled = fileNameWithoutExt + '__COMPILED.md';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).

const fileCompiledPath = path.join(__dirname, `src/${fileNameCompiled}.md`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'__dirname' is not defined.
'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
'template literal syntax' is only available in ES6 (use 'esversion: 6').

const content = fs.readFileSync(path.join(__dirname, `src/${fileNameWithoutExt}.md`), 'utf8');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'__dirname' is not defined.
'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
'template literal syntax' is only available in ES6 (use 'esversion: 6').
Line is too long.

const template = handlebars.compile(content);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).

const result = template(config);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).


fs.writeFileSync(fileCompiledPath, result);
return mdpdf.convert({
source: fileCompiledPath,
destination: path.join(__dirname, `/contracts/${fileNameWithoutExt}.pdf`),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'__dirname' is not defined.
'template literal syntax' is only available in ES6 (use 'esversion: 6').

debug: args.debug && path.join(__dirname, `/contracts/${fileNameWithoutExt}.html`),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'__dirname' is not defined.
'template literal syntax' is only available in ES6 (use 'esversion: 6').
Line is too long.

styles: path.join(__dirname, 'md-style.css'),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'__dirname' is not defined.

pdf: {
format: 'A4',
header: {
height: '0mm'
},
footer: {
height: '0mm'
},
border: {
top: '20mm',
left: '20mm',
bottom: '20mm',
right: '20mm'
}
}
})
.then(() => fs.unlinkSync(fileCompiledPath));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6').

}

generatePdf('cgv')
.then(() => generatePdf('cp'))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6').

.then(() => generatePdf('cga'));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6').

Loading