UNPKG

1.48 kBJavaScriptView Raw
1const utils = require('./utils.js');
2const path = require('path');
3
4const projectPath = utils.projectPath;
5const assets = {
6 js: [],
7 css: []
8};
9
10const ydoc = {
11 version: require('../package.json').version,
12 log: utils.log,
13 config: {
14 root: utils.defaultDocsPath,
15 dist: utils.defaultBuildPath,
16 title: "ydoc",
17 description: "website description",
18 author: "ymfe",
19 theme: 'default'
20 },
21 hook: function(name) {
22 const {emitTplHook} = require('./plugin.js')
23 let args = Array.prototype.slice.call(arguments, 1);
24 args.unshift(utils.defaultTplHookPrefix + name)
25 let tpls = emitTplHook.apply(this, args)
26 return tpls.join("\n")
27 },
28 relePath: function(srcFilepath, importFilepath) {
29 if (utils.isUrl(importFilepath)) {
30 return importFilepath;
31 }
32 importFilepath = path.isAbsolute(importFilepath)? importFilepath : path.resolve(ydoc.config.dist, importFilepath);
33 srcFilepath = path.isAbsolute(srcFilepath) ? srcFilepath : path.resolve(ydoc.config.dist, srcFilepath);
34 let rele = path.relative(srcFilepath, importFilepath);
35 return rele.substr(3);
36 },
37 addAsset: function(filepath, type) {
38 if (type === 'js') {
39 assets.js.push(filepath);
40 }else if (type === 'css') {
41 assets.css.push(filepath);
42 }
43 },
44 getAssets: function(type) {
45 return type ? [].concat(assets[type]) : {
46 js: [].concat(assets.js),
47 css: [].concat(assets.css)
48 };
49 }
50}
51
52
53
54module.exports = ydoc;
55
56