-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathindex.js
86 lines (77 loc) · 2.37 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* jshint node: true */
'use strict'
const path = require('path')
const mergeTrees = require('broccoli-merge-trees')
const Funnel = require('broccoli-funnel')
const neededJsFiles = ['pdf.js', 'pdf.worker.js']
const UnwatchedDir = require('broccoli-source').UnwatchedDir
const stew = require('broccoli-stew')
module.exports = {
name: 'ember-pdf-js',
included (app, parentAddon) {
this._super.included(...arguments)
while (app.app) {
app = app.app
}
// let target = parentAddon || app
// target.import(`${target.bowerDirectory}/pdfjs-dist/build/pdf.js`)
// target.import(`${target.bowerDirectory}/pdfjs-dist/build/pdf.worker.js`)
// target.import(`${target.bowerDirectory}/pdfjs-dist/web/pdf_viewer.js`)
// target.import(`${target.bowerDirectory}/pdfjs-dist/web/pdf_viewer.css`)
const rs = require.resolve('pdfjs-dist')
console.log(rs)
let pdfjsPath = path.dirname(path.dirname(rs))
console.log(pdfjsPath)
this.pdfjsNode = new UnwatchedDir(pdfjsPath)
app.import('vendor/pdfjs-dist/build/pdf.js');
app.import('vendor/pdfjs-dist/build/pdf.worker.js');
app.import('vendor/pdfjs-dist/web/pdf_viewer.js');
app.import('vendor/pdfjs-dist/web/pdf_viewer.css');
},
treeForPublic (tree) {
// let workerPath = path.join(this.project.root, 'bower_components', 'pdfjs-dist', 'build')
// let pdfJsImages = path.join(this.project.root, 'bower_components', 'pdfjs-dist', 'web', 'images')
let pdfJsImagesTree = new Funnel(this.pdfjsNode, {
srcDir: 'web/images',
destDir: '/assets/images'
})
let pdfJsFilesTree = new Funnel(this.pdfjsNode, {
srcDir: 'build',
include: neededJsFiles,
destDir: '/'
})
if (tree) {
return mergeTrees([
tree,
pdfJsFilesTree,
pdfJsImagesTree
])
} else {
return mergeTrees([
pdfJsFilesTree,
pdfJsImagesTree
])
}
},
treeForVendor (vendorTree) {
let trees = []
if (vendorTree) {
trees.push(vendorTree)
}
trees.push(
Funnel(this.pdfjsNode, {
srcDir: 'build',
include: ['pdf.js', 'pdf.worker.js'],
destDir: 'pdfjs-dist/build',
})
)
trees.push(
Funnel(this.pdfjsNode, {
srcDir: 'web',
include: ['pdf_viewer.js', 'pdf_viewer.css'],
destDir: 'pdfjs-dist/web',
})
)
return mergeTrees(trees)
}
}