-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpath.js
43 lines (29 loc) · 1022 Bytes
/
path.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'use strict';
const Fs = require('fs');
const Path = require('path');
const Contents = require('./contents');
const Utils = require('../utils');
exports.create = async (path) => {
const simpleGit = Utils.simpleGit(path);
const isRepo = await simpleGit.checkIsRepo();
if (!isRepo) {
throw new Error(`${path} is not a git repository`);
}
if (!Fs.existsSync(Path.join(path, 'package.json'))) {
throw new Error(`${path} does not contain a package.json`);
}
return {
getCommit: () => {
return simpleGit.revparse(['HEAD']);
},
loadFolder: (folderPath) => {
const fullPath = Path.join(path, folderPath);
return Fs.existsSync(fullPath) ? Fs.readdirSync(fullPath) : [];
},
loadFile: (filename, options = {}) => {
const fullPath = Path.join(path, filename);
const buffer = Fs.readFileSync(fullPath);
return Contents.convert(buffer, options);
}
};
};