-
Notifications
You must be signed in to change notification settings - Fork 0
/
packerConfig.js
218 lines (215 loc) · 11.1 KB
/
packerConfig.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
const path = require('path');
const {packer} = require('lerna-packer');
const {copyRootPackageJson} = require('lerna-packer/packer/modulePackages');
const fs = require('fs');
packer(
{
packages: {
orbApp: {
name: '@orbstation/app',
root: path.resolve(__dirname, 'packages', 'orb-app'),
entry: path.resolve(__dirname, 'packages', 'orb-app/src/'),
esmOnly: true,
doServeWatch: true,
babelTargets: [
{distSuffix: '', args: ['--no-comments', '--extensions', '.ts', '--extensions', '.js', '--ignore', '**/*.d.ts']},
],
},
orbAppModelCouchDb: {
name: '@orbstation/app-model-couchdb',
root: path.resolve(__dirname, 'packages', 'orb-app-model-couchdb'),
entry: path.resolve(__dirname, 'packages', 'orb-app-model-couchdb/src/'),
esmOnly: true,
doServeWatch: true,
babelTargets: [
{distSuffix: '', args: ['--no-comments', '--extensions', '.ts', '--extensions', '.js', '--ignore', '**/*.d.ts']},
],
},
orbAppModelLowDb: {
name: '@orbstation/app-model-lowdb',
root: path.resolve(__dirname, 'packages', 'orb-app-model-lowdb'),
entry: path.resolve(__dirname, 'packages', 'orb-app-model-lowdb/src/'),
esmOnly: true,
doServeWatch: true,
babelTargets: [
{distSuffix: '', args: ['--no-comments', '--extensions', '.ts', '--extensions', '.js', '--ignore', '**/*.d.ts']},
],
},
orbRoute: {
name: '@orbstation/route',
root: path.resolve(__dirname, 'packages', 'orb-route'),
entry: path.resolve(__dirname, 'packages', 'orb-route/src/'),
esmOnly: true,
doServeWatch: true,
babelTargets: [
{distSuffix: '', args: ['--no-comments', '--extensions', '.ts', '--extensions', '.js', '--ignore', '**/*.d.ts']},
],
},
orbOas: {
name: '@orbstation/oas',
root: path.resolve(__dirname, 'packages', 'orb-oas'),
entry: path.resolve(__dirname, 'packages', 'orb-oas/src/'),
esmOnly: true,
doServeWatch: true,
babelTargets: [
{distSuffix: '', args: ['--no-comments', '--extensions', '.ts', '--extensions', '.js', '--ignore', '**/*.d.ts']},
],
},
orbCommand: {
name: '@orbstation/command',
root: path.resolve(__dirname, 'packages', 'orb-command'),
entry: path.resolve(__dirname, 'packages', 'orb-command/src/'),
esmOnly: true,
doServeWatch: true,
babelTargets: [
{distSuffix: '', args: ['--no-comments', '--extensions', '.ts', '--extensions', '.js', '--ignore', '**/*.d.ts']},
],
},
orbService: {
name: '@orbstation/service',
root: path.resolve(__dirname, 'packages', 'orb-service'),
entry: path.resolve(__dirname, 'packages', 'orb-service/src/'),
esmOnly: true,
doServeWatch: true,
babelTargets: [
{distSuffix: '', args: ['--no-comments', '--extensions', '.ts', '--extensions', '.js', '--ignore', '**/*.d.ts']},
],
},
orbCling: {
name: '@orbstation/cling',
root: path.resolve(__dirname, 'packages', 'orb-cling'),
entry: path.resolve(__dirname, 'packages', 'orb-cling/src/'),
esmOnly: true,
doServeWatch: true,
babelTargets: [
{distSuffix: '', args: ['--no-comments', '--extensions', '.ts', '--extensions', '.js', '--ignore', '**/*.d.ts']},
],
},
schemaLib: {
name: '@bemit/schema',
root: path.resolve(__dirname, 'packages', 'schema-lib'),
entry: path.resolve(__dirname, 'packages', 'schema-lib/src/'),
esmOnly: true,
doServeWatch: true,
babelTargets: [
{distSuffix: '', args: ['--no-comments', '--extensions', '.ts', '--extensions', '.js', '--ignore', '**/*.d.ts']},
],
},
},
backends: {
demoApp: {
root: path.resolve(__dirname, 'packages', 'demo-app'),
src: 'src',
entry: 'server.js',
// process.env.PORT= 4265
//nodemonArgs: ['-w', path.resolve(__dirname, 'packages', 'bemit-lib', 'build') + '/**/*'],
babelArgs: [
'--env-name', 'node', '--extensions', '.ts', '--extensions', '.js', '--ignore', '**/*.d.ts',
'--copy-files',
],
nodemonArgs: [
'-e', 'js,json,twig,scss',
'-w', path.resolve(__dirname, 'packages', 'demo-app', 'locales') + '/**/*',
'-w', path.resolve(__dirname, 'packages', 'demo-app', 'templates') + '/**/*.twig',
'-w', path.resolve(__dirname, 'packages', 'demo-app', 'templates') + '/**/*.scss',
'-w', path.resolve(__dirname, 'packages', 'schema-lib', 'build') + '/**/*.js',
'-w', path.resolve(__dirname, 'packages', 'orb-app', 'build') + '/**/*.js',
'-w', path.resolve(__dirname, 'packages', 'orb-app-model-couchdb', 'build') + '/**/*.js',
'-w', path.resolve(__dirname, 'packages', 'orb-app-model-lowdb', 'build') + '/**/*.js',
'-w', path.resolve(__dirname, 'packages', 'orb-route', 'build') + '/**/*.js',
'-w', path.resolve(__dirname, 'packages', 'orb-oas', 'build') + '/**/*.js',
'-w', path.resolve(__dirname, 'packages', 'orb-cling', 'build') + '/**/*.js',
'-w', path.resolve(__dirname, 'packages', 'orb-service', 'build') + '/**/*.js',
'-w', path.resolve(__dirname, 'packages', 'orb-command', 'build') + '/**/*.js',
],
nodeExperimental: {
jsonModules: true,
},
},
},
},
__dirname, {
afterEsModules: (packages, pathBuild, isServing) => {
return Promise.all([
...(isServing ? [] : [copyRootPackageJson()(packages, pathBuild)]),
]).then(() => undefined).catch((e) => {
console.error('ERROR after-es-mod', e)
return Promise.reject(e)
})
},
},
)
.then(([execs, elapsed]) => {
if(execs.indexOf('doServe') !== -1) {
console.log('[packer] is now serving (after ' + elapsed + 'ms)')
} else {
if(execs.indexOf('doBuild') !== -1 && execs.indexOf('doBuildBackend') !== -1) {
const nodePackages = [
path.resolve(__dirname, 'packages', 'orb-app'),
path.resolve(__dirname, 'packages', 'orb-app-model-couchdb'),
path.resolve(__dirname, 'packages', 'orb-app-model-lowdb'),
path.resolve(__dirname, 'packages', 'orb-cling'),
path.resolve(__dirname, 'packages', 'orb-command'),
path.resolve(__dirname, 'packages', 'orb-oas'),
path.resolve(__dirname, 'packages', 'orb-route'),
path.resolve(__dirname, 'packages', 'orb-service'),
path.resolve(__dirname, 'packages', 'schema-lib'),
// path.resolve(__dirname, 'packages', 'render-style'),
]
const saver = nodePackages.map((pkg) => {
return new Promise(((resolve) => {
const packageFile = JSON.parse(fs.readFileSync(path.join(pkg, 'package.json')).toString())
// todo: for backends: here check all `devPackages` etc. an replace local-packages with `file:` references,
// then copy the `build` of that package to e.g. `_modules` in the backend `build`
if(packageFile.exports) {
packageFile.exports = Object.keys(packageFile.exports).reduce((exp, pkgName) => ({
...exp,
[pkgName]:
packageFile.exports[pkgName].startsWith('./build/') ?
'.' + packageFile.exports[pkgName].slice('./build'.length) :
packageFile.exports[pkgName].startsWith('./src/') ?
'.' + packageFile.exports[pkgName].slice('./src'.length) :
packageFile.exports[pkgName],
}), packageFile.exports)
}
if(packageFile.main && packageFile.main.startsWith('build/')) {
packageFile.main = packageFile.main.slice('build/'.length)
}
if(packageFile.main && packageFile.main.startsWith('src/')) {
packageFile.main = packageFile.main.slice('src/'.length)
}
if(packageFile.typings && packageFile.typings.startsWith('build/')) {
packageFile.typings = packageFile.typings.slice('build/'.length)
}
if(packageFile.typings && packageFile.typings.startsWith('src/')) {
packageFile.typings = packageFile.typings.slice('src/'.length)
}
if(packageFile.types && packageFile.types.startsWith('build/')) {
packageFile.types = packageFile.types.slice('build/'.length)
}
if(packageFile.types && packageFile.types.startsWith('src/')) {
packageFile.types = packageFile.types.slice('src/'.length)
}
fs.writeFile(path.join(pkg, 'build', 'package.json'), JSON.stringify(packageFile, null, 4), () => {
resolve()
})
}))
})
Promise.all(saver)
.then(() => {
console.log('[packer] finished successfully (after ' + elapsed + 'ms)', execs)
process.exit(0)
})
.catch((e) => {
console.error('packerConfig', e)
})
} else {
console.log('[packer] finished successfully (after ' + elapsed + 'ms)', execs)
process.exit(0)
}
}
})
.catch((e) => {
console.error('[packer] finished with error(s)', e)
process.exit(1)
})