You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

58 rivejä
1.7 KiB

  1. from __future__ import unicode_literals, absolute_import
  2. import click
  3. import os, shutil
  4. import frappe
  5. from frappe.commands import pass_context
  6. @click.command('build-docs')
  7. @pass_context
  8. @click.argument('app')
  9. @click.option('--docs-version', default='current')
  10. @click.option('--target', default=None)
  11. @click.option('--local', default=False, is_flag=True, help='Run app locally')
  12. @click.option('--watch', default=False, is_flag=True, help='Watch for changes and rewrite')
  13. def build_docs(context, app, docs_version="current", target=None, local=False, watch=False):
  14. "Setup docs in target folder of target app"
  15. from frappe.utils import watch as start_watch
  16. from frappe.utils.setup_docs import add_breadcrumbs_tag
  17. for site in context.sites:
  18. _build_docs_once(site, app, docs_version, target, local)
  19. if watch:
  20. def trigger_make(source_path, event_type):
  21. if "/docs/user/" in source_path:
  22. # user file
  23. target_path = frappe.get_app_path(target, 'www', 'docs', 'user',
  24. os.path.relpath(source_path, start=frappe.get_app_path(app, 'docs', 'user')))
  25. shutil.copy(source_path, target_path)
  26. add_breadcrumbs_tag(target_path)
  27. if source_path.endswith('/docs/index.md'):
  28. target_path = frappe.get_app_path(target, 'www', 'docs', 'index.md')
  29. shutil.copy(source_path, target_path)
  30. apps_path = frappe.get_app_path(app)
  31. start_watch(apps_path, handler=trigger_make)
  32. def _build_docs_once(site, app, docs_version, target, local, only_content_updated=False):
  33. from frappe.utils.setup_docs import setup_docs
  34. try:
  35. frappe.init(site=site)
  36. frappe.connect()
  37. make = setup_docs(app, target)
  38. if not only_content_updated:
  39. make.build(docs_version)
  40. #make.make_docs(target, local)
  41. finally:
  42. frappe.destroy()
  43. commands = [
  44. build_docs,
  45. ]