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,GAAG,KAAH,CAAS,KAAK,MAAL,CAAY,kBAAZ,EAAT,CAAN;AACA,cAAM,GAAG,IAAH,CAAQ,eAAK,SAAL,CAAe,eAAK,IAAL,CAAU,SAAV,EAAqB,IAArB,EAA2B,UAA3B,EAAuC,QAAvC,CAAf,CAAR,EAA0E,KAAK,MAAL,CAAY,kBAAZ,EAA1E,CAAN;AACA,cAAM,GAAG,IAAH,CAAQ,eAAK,SAAL,CAAe,eAAK,IAAL,CAAU,SAAV,EAAqB,IAArB,EAA2B,UAA3B,EAAuC,QAAvC,CAAf,CAAR,EAA0E,KAAK,MAAL,CAAY,kBAAZ,EAA1E,CAAN;AACA,cAAM,KAAK,MAAL,CAAY,KAAZ,EAAN;AACD,O;;;;;;;;;;8BACS;AACR,WAAK,aAAL,CAAmB,OAAnB;AACD;;;;+CAEmB,W,EAAsC;AACxD,eAAO,IAAI,MAAJ,CAAW,WAAX,GAAwB,MAAM,iBAAO,MAAP,CAAc,WAAd,CAA9B,EAAP;AACD,O;;;;;;;;;;;;;AAGH,OAAO,OAAP,GAAiB,MAAjB","file":"index.js","sourcesContent":["/* @flow */\n\nimport Path from 'path'\nimport invariant from 'assert'\nimport { CompositeDisposable, Disposable } from 'sb-event-kit'\nimport * as FS from './fs'\nimport CLI from './cli'\nimport Config from './config'\nimport { MotionError, ERROR_CODE } from './error'\nimport { getPundleInstance } from './helpers'\n\nclass Motion {\n cli: CLI;\n config: Config;\n watching: boolean;\n projectPath: string;\n subscriptions: CompositeDisposable;\n\n constructor(projectPath: string, config: Config) {\n invariant(config instanceof Config, 'Use Motion.create instead of constructor')\n\n this.cli = new CLI(config)\n this.config = config\n this.watching = false\n this.projectPath = projectPath\n this.subscriptions = new CompositeDisposable()\n\n this.subscriptions.add(this.cli)\n this.cli.onShouldBuild(async () => {\n await this.build(false)\n })\n this.cli.onShouldDispose(() => {\n this.dispose()\n })\n }\n async exists(): Promise<boolean> {\n return await FS.exists(Path.join(this.projectPath, '.motion.json'))\n }\n async watch(terminal: boolean = false): Promise<Disposable> {\n if (!await this.exists()) {\n throw new MotionError(ERROR_CODE.NOT_MOTION_APP)\n }\n\n if (terminal) {\n this.cli.activate()\n }\n const pundle = await getPundleInstance(this.cli, terminal, this.projectPath, true, this.config.config, error => {\n this.cli.log(error)\n })\n await pundle.activate()\n const reloadHook = this.cli.onShouldReload(async () => {\n pundle.pundle.clearCache()\n await pundle.pundle.compile()\n })\n const disposable = new Disposable(() => {\n this.subscriptions.remove(disposable)\n pundle.dispose()\n reloadHook.dispose()\n })\n\n this.subscriptions.add(disposable)\n return disposable\n }\n async build(terminal: boolean = false): Promise<void> {\n if (!await this.exists()) {\n throw new MotionError(ERROR_CODE.NOT_MOTION_APP)\n }\n let error\n const compilation = await getPundleInstance(this.cli, terminal, this.projectPath, false, this.config.config, givenError => {\n error = givenError\n })\n if (error) {\n throw error\n }\n await compilation.compile()\n await FS.mkdir(Path.join(this.config.getPublicDirectory(), '_'))\n await FS.writeFile(Path.join(this.config.getPublicDirectory(), '_/bundle.js'), compilation.generate().contents)\n }\n async init(): Promise<void> {\n if (await this.exists()) {\n throw new MotionError(ERROR_CODE.ALREADY_MOTION_APP)\n }\n await FS.mkdir(this.config.getBundleDirectory())\n await FS.mkdir(this.config.getPublicDirectory())\n await FS.copy(Path.normalize(Path.join(__dirname, '..', 'template', 'bundle')), this.config.getBundleDirectory())\n await FS.copy(Path.normalize(Path.join(__dirname, '..', 'template', 'public')), this.config.getPublicDirectory())\n await this.config.write()\n }\n dispose() {\n this.subscriptions.dispose()\n }\n\n static async create(projectRoot: string): Promise<Motion> {\n return new Motion(projectRoot, await Config.create(projectRoot))\n }\n}\n\nmodule.exports = Motion\n"]}
\No newline at end of file