UNPKG

1.27 kBJavaScriptView Raw
1/*
2 * _generator.js
3 *
4 * browserify entry point to load generator into client
5 * served at /pub/_generator.js by serve-scripts.js
6 * depends on jquery
7 *
8 * copyright 2015, Jurgen Leschner - github.com/jldec - MIT license
9*/
10
11var debug = require('debug')('pub:generator');
12var initOpts = require('./init-opts');
13
14$.ajaxSetup( { cache: true } );
15
16// init client-side opts
17initOpts(function(err, opts) {
18
19 // start client-side pub-generator
20 var generator = window.generator = require('pub-generator')(opts);
21 opts.log.logger.noErrors = true;
22
23 // get browserified generator plugins - avoid caching across directories
24 $.getScript(pubRef.relPath + '/pub/_generator-plugins.js?_=' + encodeURIComponent(opts.basedir))
25 .fail(function(jqXHR) {
26 opts.log(new Error(jqXHR.responseText));
27 })
28 .done(function(script) {
29 debug('plugins loaded');
30
31 // load sources
32 generator.load(function(err) {
33 if (err) return opts.log(err);
34 debug('generator loaded');
35
36 // hook custom timers
37 generator.emit('init-timers', false);
38
39 // slightly ugly way to notify client (editor) that generator is ready
40 if (window.onGeneratorLoaded) {
41 window.onGeneratorLoaded(generator);
42 debug('ui loaded');
43 }
44 });
45 });
46});