File tree 8 files changed +98
-9
lines changed
8 files changed +98
-9
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,6 @@ Documentation
26
26
.. toctree ::
27
27
28
28
usage
29
-
29
+ extended_usage
30
30
31
31
.. _moban : https://github.com/chfw/moban
Original file line number Diff line number Diff line change
1
+ Custom use case: scaffolding a npm package
2
+ ================================================================================
3
+
4
+ As mentioned in previous section, **yehua ** would take a yehua.yml from command
5
+ line options. This section walk you through creating a npm package, **non-python
6
+ package **.
7
+
8
+ If you are familiar with npm, you can try and compare with yehua::
9
+
10
+ $ npm init
11
+
12
+ Evaluation
13
+ --------------------------------------------------------------------------------
14
+
15
+ Please first checkout yehua repository so that you will have the access to
16
+ example directory. Then make sure you have **yehua ** installed. Let's do these
17
+ steps to evaluate it::
18
+
19
+ $ cd /tmp
20
+ $ yehua
21
+
22
+ yehua.yml for npm package
23
+ --------------------------------------------------------------------------------
24
+
25
+ Let us go through the variant yehua file.
26
+
27
+ configuration section
28
+ ********************************************************************************
29
+
30
+
31
+
32
+ .. literalinclude :: ../../examples/npm-init/yehua.yml
33
+ :lines: 12-15
34
+
Original file line number Diff line number Diff line change 1
- How it works
1
+ Default use case: scaffolding a python package
2
2
================================================================================
3
3
4
4
**yehua ** reads a configuration file named yehua.yml which then instruct **yehua
5
5
to ask questions to collect project specific variables, and create the file
6
- structures. Its default usage is to create a blank python package but it is not
7
- limited to it. You can provide your own yehua file and do something else.
6
+ structures.
8
7
8
+ It takes a yehua file from command line option, or YEHUA_FILE in the environment
9
+ varaible. If none is found, it resorts to the default yehua.yml file included
10
+ in the package. And the default yehua.yml create a blank python package.
9
11
10
- Default behaviour
12
+
13
+ Default yehua.yml file
11
14
--------------------------------------------------------------------------------
12
15
13
- Let us go through the default yehua file. And then talk about the customization.
16
+ Let us go through the default yehua file. And then talk about the customization
17
+ in the next chapter
14
18
15
19
configuration section
16
20
********************************************************************************
Original file line number Diff line number Diff line change
1
+ console . log ( "hello world" ) ;
Original file line number Diff line number Diff line change
1
+ {
2
+ "name": "{{project_name}}",
3
+ "version": "{{version}}",
4
+ "description": "{{description}}",
5
+ "main": "{{entry_point}}",
6
+ "scripts": {
7
+ "test": "{{test_command}}",
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "{{git_repo}}"
12
+ },
13
+ "keywords": [
14
+ "{{keywords}}"
15
+ ],
16
+ "author": "{{author}}",
17
+ "license": "{{license}}"
18
+ }
Original file line number Diff line number Diff line change
1
+ introduction : |
2
+ This utility will walk you through creating a package.json file.
3
+ It only covers the most common items, and tries to guess sensible defaults.
4
+
5
+ See `npm help json` for definitive documentation on these fields
6
+ and exactly what they do.
7
+
8
+ Use `npm install <pkg> --save` afterwards to install a package and
9
+ save it as a dependency in the package.json file.
10
+
11
+ Press ^C at any time to quit.
12
+ configuration :
13
+ template_path : .
14
+ static_path : .
15
+ questions :
16
+ - project_name : " name:"
17
+ - version : " version:"
18
+ - description : " description:"
19
+ - entry_point : " entry point:"
20
+ - test_command : " test command:"
21
+ - git_repo : " git repository:"
22
+ - keywords : " keywords:"
23
+ - author : " author:"
24
+ - license : " license:"
25
+ templates :
26
+ - package.json : package.json.jj2
27
+ static :
28
+ - index.js : index.js
Original file line number Diff line number Diff line change @@ -21,8 +21,10 @@ def __init__(self, yehua_file):
21
21
self ._template_yehua_file ()
22
22
23
23
def create_all_directories (self ):
24
- temp = {self .answers ['project_name' ]: self .directives ['layout' ]}
25
- utils .make_directories (None , temp )
24
+ folder_tree = {
25
+ self .answers ['project_name' ]: self .directives .get ('layout' , None )
26
+ }
27
+ utils .make_directories (None , folder_tree )
26
28
27
29
def templating (self ):
28
30
for template in self .directives ['templates' ]:
@@ -99,7 +101,7 @@ def raise_complex_question(question):
99
101
suggested_answers = sorted (subq .keys ())
100
102
long_question = [subquestion ] + suggested_answers
101
103
choice = '(%s): ' % (
102
- ',' .join ([str (x ) for x in xrange (1 , len (long_question ))]))
104
+ ',' .join ([str (x ) for x in range (1 , len (long_question ))]))
103
105
long_question .append (choice )
104
106
a = utils .yehua_input ('\n ' .join (long_question ))
105
107
for key in suggested_answers :
Original file line number Diff line number Diff line change @@ -37,6 +37,8 @@ def make_directories(parent, node_dictionary):
37
37
else :
38
38
the_parent = key
39
39
mkdir (the_parent )
40
+ if value is None :
41
+ continue
40
42
for item in value :
41
43
if isinstance (item , dict ):
42
44
make_directories (the_parent , item )
You can’t perform that action at this time.
0 commit comments