Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fe2c084

Browse files
committed
update readme builder
1 parent e42de6a commit fe2c084

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

lib/build/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function parseAndBuild(dir, lines) {
1111
title: '',
1212
description: '',
1313
},
14-
pages: []
14+
pages: [],
1515
};
1616
var index = {
1717
page: -1,
@@ -34,7 +34,7 @@ function build(dir, filePath, output) {
3434
if (validate.result(result)) {
3535
fs_1.writeFileSync(output, result, 'utf8');
3636
}
37-
if (!readme_1.createReadme()) {
37+
if (!readme_1.createReadme(dir)) {
3838
return false;
3939
}
4040
return true;

lib/build/readme.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22
var fs_1 = require('fs');
33
var node_file_exists_1 = require('node-file-exists');
44
var chalk_1 = require('chalk');
5-
function createReadme() {
6-
if (!node_file_exists_1.default('./coderoad.json')) {
5+
var path_1 = require('path');
6+
function createReadme(dir) {
7+
if (!node_file_exists_1.default(path_1.join(dir, 'coderoad.json'))) {
78
console.log(chalk_1.red('No coderoad.json file found'));
89
return false;
910
}
10-
if (!node_file_exists_1.default('./package.json')) {
11+
if (!node_file_exists_1.default(path_1.join(dir, 'package.json'))) {
1112
console.log(chalk_1.red('No package.json file found'));
1213
return false;
1314
}
14-
var data = JSON.parse(fs_1.readFileSync('coderoad.json', 'utf8'));
15-
var packageJson = JSON.parse(fs_1.readFileSync('package.json', 'utf8'));
15+
var data = JSON.parse(fs_1.readFileSync(path_1.join(dir, 'coderoad.json'), 'utf8'));
16+
var packageJson = JSON.parse(fs_1.readFileSync(path_1.join(dir, 'package.json'), 'utf8'));
1617
var content = generateReadme(data, packageJson);
17-
fs_1.writeFileSync('README.md', content, 'utf8');
18+
fs_1.writeFileSync(path_1.join(dir, 'README.md'), content, 'utf8');
1819
return true;
1920
}
2021
exports.createReadme = createReadme;

src/build/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function parseAndBuild(dir: string, lines: string[]): CR.Output {
1212
title: '',
1313
description: '',
1414
},
15-
pages: []
15+
pages: [],
1616
};
1717
const index: CR.Index = {
1818
page: -1,
@@ -44,7 +44,7 @@ export default function build(dir: string, filePath: string, output = './coderoa
4444
}
4545

4646
// check error creating readme
47-
if (!createReadme()) { return false; }
47+
if (!createReadme(dir)) { return false; }
4848

4949
return true;
5050
}

src/build/readme.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
import {readFileSync, writeFileSync} from 'fs';
22
import fileExists from 'node-file-exists';
33
import {red} from 'chalk';
4+
import {join} from 'path';
45

5-
export function createReadme(): boolean {
6+
export function createReadme(dir): boolean {
67
// if (!fileExists('./README.md')) {
78
// }
8-
if (!fileExists('./coderoad.json')) {
9+
if (!fileExists(join(dir, 'coderoad.json'))) {
910
console.log(red('No coderoad.json file found'));
1011
return false;
1112
}
12-
if (!fileExists('./package.json')) {
13+
if (!fileExists(join(dir, 'package.json'))) {
1314
console.log(red('No package.json file found'));
1415
return false;
1516
}
16-
let data: CR.Output = JSON.parse(readFileSync('coderoad.json', 'utf8'));
17-
let packageJson: PackageJson = JSON.parse(readFileSync('package.json', 'utf8'));
17+
let data: CR.Output = JSON.parse(readFileSync(join(dir, 'coderoad.json'), 'utf8'));
18+
let packageJson: PackageJson = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8'));
1819
let content: string = generateReadme(data, packageJson);
19-
writeFileSync('README.md', content, 'utf8');
20+
writeFileSync(join(dir, 'README.md'), content, 'utf8');
2021
return true;
2122
}
2223

0 commit comments

Comments
 (0)