Skip to content

Commit 93c9540

Browse files
committed
Add domains.js as an explicit domain artifact.
1 parent d15d41e commit 93c9540

File tree

9 files changed

+131
-33
lines changed

9 files changed

+131
-33
lines changed

.core/babel.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ ReactiumBabel.ModuleAliases = ReactiumBabel.Utils.registryFactory(
6161
ReactiumBabel.Utils.Registry.MODES.CLEAN,
6262
);
6363
ReactiumBabel.ModuleAliases.register('externals', {
64-
path: './.tmp/externals-manifest',
64+
path: './src/externals-manifest',
6565
});
6666
ReactiumBabel.ModuleAliases.register('manifest', {
6767
path: './src/manifest',

.core/gulp.config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@ const defaultConfig = {
9999
includes: ['./node_modules'],
100100
appdir: path.resolve(__dirname, 'src/app'),
101101
rootdir: path.resolve(__dirname),
102+
domainManifest: path.normalize(`${rootPath}/src/domains.js`),
102103
manifest: path.normalize(`${rootPath}/src/manifest.js`),
103104
externalsManifest: path.normalize(
104-
`${rootPath}/.tmp/externals-manifest.js`,
105+
`${rootPath}/src/externals-manifest.js`,
105106
),
106107
reactiumModules: path.normalize(`${rootPath}/reactium_modules`),
107108
},

.core/gulp.tasks.js

+25-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const sourcemaps = require('gulp-sourcemaps');
1818
const rename = require('gulp-rename');
1919
const chalk = require('chalk');
2020
const reactiumConfig = require('./reactium-config');
21-
const regenManifest = require('./manifest/manifest-tools');
21+
const { regenManifest } = require('./manifest/manifest-tools');
2222
const umdWebpackGenerator = require('./umd.webpack.config');
2323
const rootPath = path.resolve(__dirname, '..');
2424
const { fork, spawn, execSync } = require('child_process');
@@ -217,6 +217,7 @@ const reactium = (gulp, config, webpackConfig) => {
217217
crossEnvPackage.bin['cross-env'],
218218
);
219219

220+
await gulp.task('domainsManifest')(() => Promise.resolve());
220221
await gulp.task('mainManifest')(() => Promise.resolve());
221222

222223
command('node', [crossEnvBin, 'NODE_ENV=development', 'gulp'], done);
@@ -308,7 +309,7 @@ const reactium = (gulp, config, webpackConfig) => {
308309

309310
const manifest = gulp.series(
310311
gulp.parallel(
311-
task('mainManifest'),
312+
gulp.series(task('domainsManifest'), task('mainManifest')),
312313
task('externalsManifest'),
313314
task('umdManifest'),
314315
),
@@ -318,6 +319,21 @@ const reactium = (gulp, config, webpackConfig) => {
318319

319320
const sw = gulp.series(task('umd'), task('serviceWorker'));
320321

322+
const domainsManifest = done => {
323+
// Generate domains.js file
324+
regenManifest({
325+
manifestFilePath: config.src.domainManifest,
326+
manifestConfig: reactiumConfig.manifest.domains,
327+
manifestTemplateFilePath: path.resolve(
328+
__dirname,
329+
'manifest/templates/domains.hbs',
330+
),
331+
manifestProcessor: require('./manifest/processors/domains'),
332+
});
333+
334+
done();
335+
};
336+
321337
const mainManifest = done => {
322338
// Generate manifest.js file
323339
regenManifest({
@@ -810,7 +826,13 @@ $assets: map.set($assets, "{{key}}", "{{{dataURL}}}");
810826

811827
const watchFork = done => {
812828
const watchers = {};
829+
813830
// Watch for file changes
831+
watchers['manifest'] = gulp.watch(
832+
config.watch.js,
833+
gulp.parallel(task('manifest')),
834+
);
835+
814836
watchers['styles:colors'] = gulp.watch(
815837
config.watch.colors,
816838
gulp.task('styles:colors'),
@@ -829,10 +851,6 @@ $assets: map.set($assets, "{{key}}", "{{{dataURL}}}");
829851
);
830852
gulpwatch(config.watch.markup, watcher);
831853
gulpwatch(config.watch.assets, watcher);
832-
const scriptWatcher = gulp.watch(
833-
config.watch.js,
834-
gulp.parallel(task('manifest')),
835-
);
836854

837855
watchLogger(watchers);
838856
done();
@@ -866,6 +884,7 @@ $assets: map.set($assets, "{{key}}", "{{{dataURL}}}");
866884
default: defaultTask,
867885
json,
868886
manifest,
887+
domainsManifest,
869888
mainManifest,
870889
externalsManifest,
871890
umd,

.core/manifest/manifest-tools.js

+27-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ const fs = require('fs-extra');
44
const _ = require('underscore');
55
const op = require('object-path');
66
const prettier = require('prettier');
7-
const moment = require('moment');
87
const chalk = require('chalk');
98
const diff = require('fast-diff');
109
const hb = require('handlebars');
10+
const rootPath = path.resolve(__dirname, '../..');
1111

12+
// flatten a tree of files from directory-tree module
1213
const flattenRegistry = (registry = { children: [] }, manifest = []) => {
1314
op.get(registry, 'children', []).forEach(item => {
1415
const type = op.get(item, 'type');
@@ -29,8 +30,13 @@ const flattenRegistry = (registry = { children: [] }, manifest = []) => {
2930
return manifest;
3031
};
3132

32-
const sources = (sourcePath, searchParams) =>
33-
flattenRegistry(tree(sourcePath, searchParams));
33+
/**
34+
* For a given sourcepath relative to the project directory, returns a flat list of matching files.
35+
*/
36+
const sources = (sourcePath, searchParams) => {
37+
const t = tree(sourcePath, searchParams);
38+
return flattenRegistry(t);
39+
};
3440

3541
const isRegExp = regEx =>
3642
typeof regEx === 'object' && regEx.constructor == RegExp;
@@ -168,7 +174,7 @@ const find = (searches = [], sourceMappings = [], searchParams = {}) => {
168174
return mappings;
169175
};
170176

171-
module.exports = function({
177+
const regenManifest = function({
172178
manifestFilePath,
173179
manifestConfig,
174180
manifestTemplateFilePath,
@@ -220,3 +226,20 @@ module.exports = function({
220226
fs.writeFileSync(manifestFilePath, fileContents);
221227
}
222228
};
229+
230+
const domainRegExp = new RegExp('/([A-Za-z_0-9-]+?)[\\/][A-Za-z_0-9-]+$');
231+
const fileToDomain = file => {
232+
let [, domain] = file.match(domainRegExp) || [];
233+
const relativeOriginalPath = path.resolve(rootPath, file);
234+
235+
return domain;
236+
};
237+
238+
module.exports = {
239+
regenManifest,
240+
flattenRegistry,
241+
sources,
242+
isRegExp,
243+
find,
244+
fileToDomain,
245+
};

.core/manifest/processors/domains.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const path = require('path');
2+
const op = require('object-path');
3+
const { fileToDomain } = require('../manifest-tools');
4+
const rootPath = path.resolve(__dirname, '../../..');
5+
6+
module.exports = data => {
7+
const domains = {};
8+
const relative = {};
9+
10+
for (const [file, original] of Object.entries(
11+
op.get(data, 'manifest.allDomains.originals'),
12+
)) {
13+
const relativeOriginalPath = path.resolve(rootPath, original);
14+
15+
const domainObj = require(relativeOriginalPath);
16+
const impliedDomain = fileToDomain(file);
17+
const domain = op.get(domainObj, 'name', impliedDomain);
18+
19+
op.set(domains, [domain], domainObj);
20+
op.set(domains, [domain, 'name'], domain);
21+
op.set(domains, [domain, 'implied'], impliedDomain);
22+
op.set(domains, [domain, 'original'], original);
23+
op.set(relative, [path.dirname(original)], domain);
24+
}
25+
26+
return JSON.stringify({ domains, relative });
27+
};

.core/manifest/processors/manifest.js

+13-20
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,20 @@ const path = require('path');
44
const rootPath = path.resolve(__dirname, '../../..');
55
const chalk = require('chalk');
66
module.exports = data => {
7+
const explicitDomains = require(path.resolve(rootPath, 'src/domains.js'));
8+
79
const types = Object.entries(data.manifest).map(([name, typeDomains]) => {
8-
const domainRegExp = new RegExp('/([A-Za-z_0-9-]+?)/[A-Za-z_0-9-]+$');
10+
const { fileToDomain } = require('../manifest-tools');
911
const { imports, type } = typeDomains;
1012

11-
const fileToDomain = file => {
12-
let [, domain] = file.match(domainRegExp) || [];
13-
try {
14-
const relativeOriginalPath = path.resolve(
15-
rootPath,
16-
typeDomains.originals[file],
17-
);
18-
const potentialDomainFile = path.normalize(
19-
path.dirname(relativeOriginalPath) + '/domain.js',
20-
);
21-
if (fs.existsSync(potentialDomainFile)) {
22-
const { name } = require(potentialDomainFile);
23-
if (name) domain = name;
24-
}
25-
} catch (error) {
26-
// intentionally blank
27-
}
13+
const mapDomain = file => {
14+
let domain = fileToDomain(file);
15+
const relative = domain;
16+
domain = op.get(
17+
explicitDomains,
18+
['relative', path.dirname(typeDomains.originals[file])],
19+
domain,
20+
);
2821

2922
if (!domain)
3023
console.log(
@@ -36,9 +29,9 @@ module.exports = data => {
3629
const domains = [];
3730
imports
3831
.map(file => file.replace(/\\/g, '/'))
39-
.filter(fileToDomain)
32+
.filter(mapDomain)
4033
.forEach(file => {
41-
const domain = fileToDomain(file);
34+
const domain = mapDomain(file);
4235
let existing;
4336
if (
4437
(existing = domains.find(({ domain: d }) => d === domain))

.core/manifest/templates/domains.hbs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* Generated by Reactium
3+
* DO NOT directly edit this file !!!!!!
4+
*/
5+
6+
module.exports = {{{this}}};

.core/reactium-config.js

+28-1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,33 @@ const defaultManifestConfig = {
157157
exclude: [/\.ds_store/i, /\.core/i, /\.cli\//i, /src\/assets/],
158158
},
159159
},
160+
domains: {
161+
patterns: [
162+
{
163+
name: 'allDomains',
164+
type: 'domain',
165+
pattern: /domain.js$/,
166+
},
167+
],
168+
sourceMappings: [
169+
{
170+
from: 'src/app/',
171+
to: '../src/app/',
172+
},
173+
{
174+
from: '.core/',
175+
to: '../.core/',
176+
},
177+
{
178+
from: 'reactium_modules/',
179+
to: '../reactium_modules/',
180+
},
181+
{
182+
node_modules: true,
183+
ignore: /^((?!reactium-plugin).)*$/,
184+
},
185+
],
186+
},
160187
};
161188

162189
const overrides = config => {
@@ -179,7 +206,7 @@ const manifestConfig = overrides(defaultManifestConfig);
179206
*/
180207
module.exports = {
181208
version,
182-
semver: '^3.0.0',
209+
semver: '^5.0.0',
183210
build: gulpConfig,
184211
update: {
185212
package: {

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ Thumbs.db
8282
.cli-cache
8383

8484
# Manifest
85+
src/domains.js
8586
src/manifest.js
87+
src/externals-manifest.js
8688
src/app/server/webpack-manifest.json
8789

8890
# Translation .mo

0 commit comments

Comments
 (0)