Skip to content

Commit

Permalink
feat: 完成 init 功能
Browse files Browse the repository at this point in the history
  • Loading branch information
hellosean1025 committed Jan 17, 2018
1 parent b46d062 commit c708b0d
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Thumbs.db
# *.tar.gz

_site
demo/
./test.js

/coverage
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Shines
新一代文档网站生成工具,基于node, React,markdown,目前还未开发完成
新一代文档网站生成工具,基于node, recet,markdown。

# Usage

```
npm install
bin/ydoc build
npm install ydoc
ydoc init
ydoc build
```
7 changes: 1 addition & 6 deletions docs/nav.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
# YDoc
![](style/images/logo.png)

<<<<<<< HEAD
* [Documents](/documents/index.html)
* [Jsxbook](/jsxbook/index.html)
* [second](/jsxbook/index.html)
=======

* [documents](/documents/index.html)
* [jsxbook](/jsxbook/index.html)
* [second](/jsxbook/index.html)
* [API](/api/index.html)
>>>>>>> 4f0e3bfdca1d08973b72213a4fbf7b9e840c1b01
4 changes: 4 additions & 0 deletions init/about/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<h1>About</h1>
<p>
...
</p>
8 changes: 8 additions & 0 deletions init/documents/env.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# env
env

## title
content

### sub-title
content
2 changes: 2 additions & 0 deletions init/documents/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# ydoc
This is home page of documents book.
5 changes: 5 additions & 0 deletions init/documents/intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Introduction
Introduction

## title
content
8 changes: 8 additions & 0 deletions init/documents/summary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Summary

* [Installation](installation.md)

### Getting Started

* [Introduction](intro.md#)
* [env](env.md)
5 changes: 5 additions & 0 deletions init/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
welcome: Welcome to use ydoc.
---

<h1>{welcome}</h1>
7 changes: 7 additions & 0 deletions init/nav.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# YDoc
![](style/images/logo.png)


* [documents](/documents/index.html)

* [about](/about/index.html)
11 changes: 7 additions & 4 deletions src/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ const loadPlugins = require('../plugin.js').loadPlugins;

const defaultBuildPath = '_site';
const projectPath = process.cwd();
const configFilepath = path.resolve(projectPath, 'ydoc.json');
const styleInPath = path.resolve(projectPath, 'theme/styles/index.scss');
const scriptInPath = path.resolve(projectPath, 'theme/scripts/');
const ydocPath = path.resolve(__dirname, '../..')
const styleInPath = path.resolve(ydocPath, 'theme/styles/index.scss');
const scriptInPath = path.resolve(ydocPath, 'theme/scripts/');
const styleOutPath = path.resolve(projectPath, defaultBuildPath + '/ydoc/styles', 'style.css');
const scriptOutPath = path.resolve(projectPath, defaultBuildPath + '/ydoc/scripts/');
const logger = require('../logger');

const config = utils.fileExist(configFilepath) ? require(configFilepath) : require(path.resolve(projectPath, 'ydoc.js'));
const configFilepath = utils.getConfigPath(projectPath);
const config = utils.fileExist(configFilepath) ? require(configFilepath) : {};
const ydoc = require('../ydoc.js');
utils.extend(ydoc.config, config);




module.exports = {
setOptions: function (yargs) {
yargs.option('verbose', {
Expand Down
17 changes: 14 additions & 3 deletions src/commands/init.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
const path = require('path');
const fs = require('fs-extra');
const projectPath = process.cwd();
const utils = require('../utils');
const initPath = path.resolve(__dirname, '../../init');
const docsPath = path.resolve(projectPath, 'docs')

module.exports = {
setOptions: function (yargs) {},
run: function (argv) {
console.log(argv)
setOptions: function () {},
run: function () {
let configFilepath = utils.getConfigPath(projectPath);
if(configFilepath){
return utils.log.error('The current directory already exists ydoc config.')
}else if(utils.dirExist(docsPath)){
return utils.log.error('The current directory already exists docs directory.');
}
fs.ensureDirSync(docsPath);
fs.copySync(initPath, docsPath)
},
desc: 'Initialize a document site'
}
25 changes: 23 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,25 @@ exports.clearArray = function clearArray(a) {
return a.splice(0, a.length);
}

exports.fileExist = (filePath) => {
function fileExist(filePath){
try {
return fs.statSync(filePath).isFile();
} catch (err) {
return false;
}
};
}
exports.fileExist = fileExist;


function dirExist(filePath){
try {
return fs.statSync(filePath).isDirectory();
} catch (err) {
return false;
}
}
exports.dirExist = dirExist;


/**
* log 输出,一共四个 api:
Expand Down Expand Up @@ -75,3 +87,12 @@ exports.handleMdUrl = (findTransactionBySrcPath) => (content, filepath) => {
})
return $.html()
}

exports.getConfigPath = function getConfigPath(dirname){
let allowFilename = ['ydoc.json', 'ydoc.js'];
for(let i =0; i< allowFilename.length; i++){
let configFilepath = path.resolve(dirname, allowFilename[i]);
if(fileExist(configFilepath)) return configFilepath;
}
return null;
}

0 comments on commit c708b0d

Please sign in to comment.