Created
July 13, 2010 02:22
-
-
Save julsdelatierra/473366 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def makepackage(env_root, args): | |
pack_path=os.path.abspath(os.path.dirname('__file__')) | |
from templates import DEFAULT_README_DOC, MAIN_JS, MAIN_JS_DOC, MODULE_JS, PACKAGE_TEMPLATE, REQUIRES_MAIN_JS | |
if len(args)%2 == 0: | |
try: | |
requires = '' | |
for d in ['','lib','data','tests','docs']: | |
os.mkdir(os.path.join(pack_path,args[1],d)) | |
file = open(os.path.join(pack_path,args[1],'README.md'),'w') | |
file.write(DEFAULT_README_DOC % {'packName':args[1]}) | |
file.close() | |
file = open(os.path.join(pack_path,args[1],'package.json'),'w') | |
file.write(PACKAGE_TEMPLATE % {'packName':args[1]}) | |
file.close() | |
file = open(os.path.join(pack_path,args[1],'tests','test-main.js'),'w') | |
file.write('const m = require("main");') | |
file.close() | |
file = open(os.path.join(pack_path,args[1],'docs','main.md'),'w') | |
file.write(MAIN_JS_DOC) | |
file.close() | |
if len(args) == 4: | |
for module in args[3].split(','): | |
isModule = False | |
modules = os.listdir(os.path.join(env_root,'packages','jetpack-core','lib')) | |
for lib in modules: | |
if lib.split('.')[0] == module: | |
requires += REQUIRES_MAIN_JS % {'module':module} | |
isModule = True | |
if not isModule: | |
print >> sys.stderr,'%s is not a module acknowledge' % module | |
answer = raw_input('Would you like to create '+module+'.js? (y/n): ') | |
while answer.lower() not in ['y','n']: | |
answer = raw_input('Would you like to create '+module+'.js? (y/n): ') | |
if answer == 'y': | |
file = open(os.path.join(pack_path,args[1],'lib',module+'.js'),'w') | |
file.write(MODULE_JS % {'module':module}) | |
file.close() | |
requires += REQUIRES_MAIN_JS % {'module':module} | |
else: | |
print >> sys.stdout, 'please run cfx docs' | |
file = open(os.path.join(pack_path,args[1],'lib','main.js'),'w') | |
file.write(requires+MAIN_JS) | |
file.close() | |
except: | |
print >> sys.stderr, 'The project already exist.' | |
else: | |
if len(args) > 4: print >> sys.stderr, 'Too many arguments.' | |
if len(args) == 3: print >> sys.stderr, 'type the list of modules to implement.' | |
if len(args) < 2: print >> sys.stderr, 'Please give me a name for package.' |
Right now i've done the auto include of requires for the addon template that i said and i've wrote the validation of modules.
New Structure in the code and new functions to generate a better template and give the option to create custom libs not defined in the jetpack-core and make the read of modules from the jetpack-core folder instead of the array before defined.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A new functionality to Jetpack SDK. This create a basic structure for a new addon, i'm thinking in add so much functions to get something like this:
$ cfx mkpkg newAddon with widget
$ cfx mkpkg newAddon with context-menu
$ cfx mkpkg newAddon with widget