|
1 | 1 | import type { Sandbox, Module, Directory } from 'common/types'; |
2 | | - |
3 | | -/* eslint-disable */ |
4 | | -// import favicon from '!base64-loader!./files/favicon.ico'; // $FlowIssue |
5 | | -// import gitignore from '!raw-loader!./files/.gitignore'; // $FlowIssue |
6 | | -// import manifest from '!raw-loader!./files/manifest.json'; // $FlowIssue |
7 | | -// import serviceWorker from '!raw-loader!./files/createServiceWorker'; // $FlowIssue |
8 | | -// import README from './files/README.md'; // $FlowIssue |
9 | | -/* eslint-enable */ |
10 | | - |
| 2 | +import files from 'buffer-loader!./files.zip'; // eslint-disable-line import/no-webpack-loader-syntax |
11 | 3 | import { |
12 | 4 | getResourceTag, |
13 | 5 | getIndexHtmlBody, |
@@ -56,61 +48,51 @@ const getHTML = (modules, resources) => |
56 | 48 | </html> |
57 | 49 | `; |
58 | 50 |
|
59 | | -const files = {}; |
60 | | -function importAll(r) { |
61 | | - r.keys().forEach(key => { |
62 | | - files[key] = r(key); |
63 | | - }); |
64 | | -} |
65 | | - |
66 | 51 | export default function createZip( |
67 | 52 | zip, |
68 | 53 | sandbox: Sandbox, |
69 | 54 | modules: Array<Module>, |
70 | 55 | directories: Array<Directory> |
71 | 56 | ) { |
72 | | - importAll(require.context('./files', true, /.*/)); |
73 | | - |
74 | | - const src = zip.folder('src'); |
75 | | - src.file('createServiceWorker.js', files['./createServiceWorker.js']); |
76 | | - modules |
77 | | - .filter(x => x.directoryShortid == null) |
78 | | - .filter(x => x.title !== 'index.html') // This will be included in the body |
79 | | - .forEach(x => src.file(x.title, x.code)); |
| 57 | + return zip.loadAsync(files).then(srcFolder => { |
| 58 | + const src = srcFolder.folder('src'); |
80 | 59 |
|
81 | | - directories |
82 | | - .filter(x => x.directoryShortid == null) |
83 | | - .forEach(x => createDirectoryWithFiles(modules, directories, x, src)); |
| 60 | + modules |
| 61 | + .filter(x => x.directoryShortid == null) |
| 62 | + .filter(x => x.title !== 'index.html') // This will be included in the body |
| 63 | + .forEach(x => src.file(x.title, x.code)); |
84 | 64 |
|
85 | | - const publicFolder = zip.folder('public'); |
| 65 | + directories |
| 66 | + .filter(x => x.directoryShortid == null) |
| 67 | + .forEach(x => createDirectoryWithFiles(modules, directories, x, src)); |
86 | 68 |
|
87 | | - publicFolder.file('favicon.ico', files['./favicon.ico'], { |
88 | | - base64: true, |
89 | | - }); |
| 69 | + const publicFolder = zip.folder('public'); |
90 | 70 |
|
91 | | - publicFolder.file('index.html', getHTML(modules, sandbox.externalResources)); |
92 | | - publicFolder.file('manifest.json', files['./manifest.json']); |
| 71 | + publicFolder.file( |
| 72 | + 'index.html', |
| 73 | + getHTML(modules, sandbox.externalResources) |
| 74 | + ); |
93 | 75 |
|
94 | | - if ( |
95 | | - !modules.find(x => x.directoryShortid == null && x.title === 'README.md') |
96 | | - ) { |
97 | | - zip.file('README.md', files['./README.md']); |
98 | | - } |
99 | | - zip.file( |
100 | | - 'package.json', |
101 | | - createPackageJSON( |
102 | | - sandbox, |
103 | | - {}, |
104 | | - { |
105 | | - 'react-scripts': '1.0.0', |
106 | | - }, |
107 | | - { |
108 | | - start: 'react-scripts start', |
109 | | - build: 'react-scripts build', |
110 | | - test: 'react-scripts test --env=jsdom', |
111 | | - eject: 'react-scripts eject', |
112 | | - } |
113 | | - ) |
114 | | - ); |
115 | | - zip.file('.gitignore', files['./gitignore']); |
| 76 | + if ( |
| 77 | + !modules.find(x => x.directoryShortid == null && x.title === 'README.md') |
| 78 | + ) { |
| 79 | + zip.file('README.md', files['./README.md']); |
| 80 | + } |
| 81 | + zip.file( |
| 82 | + 'package.json', |
| 83 | + createPackageJSON( |
| 84 | + sandbox, |
| 85 | + {}, |
| 86 | + { |
| 87 | + 'react-scripts': '1.0.0', |
| 88 | + }, |
| 89 | + { |
| 90 | + start: 'react-scripts start', |
| 91 | + build: 'react-scripts build', |
| 92 | + test: 'react-scripts test --env=jsdom', |
| 93 | + eject: 'react-scripts eject', |
| 94 | + } |
| 95 | + ) |
| 96 | + ); |
| 97 | + }); |
116 | 98 | } |
0 commit comments