@polylith/builder 0.0.39 → 0.0.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/App.js CHANGED
@@ -14,6 +14,7 @@ import mainHTML from './plugin-main-html.js';
14
14
  import features from './plugin-features.js';
15
15
  import resources from "./plugin-copy-resources.js";
16
16
  import jsconfig from "./plugin-jsconfig.js";
17
+ import loadConfigs from "./plugin-config.js";
17
18
 
18
19
  import {forceToPosix, fileExists} from './utils.js'
19
20
  import ConfigFeature from './ConfigFeature.js';
@@ -49,7 +50,7 @@ export default class App {
49
50
  this.loadables = [];
50
51
  this.features = [];
51
52
  this.featureIndexes = [];
52
- this.configs = {};
53
+ this.configs = [];
53
54
  this.manualChunkType = 'function';
54
55
  this.manualChunks = [];
55
56
  this.files = new Files(this.sourcePath, this.destPath);
@@ -57,8 +58,7 @@ export default class App {
57
58
  this.cssFiles = [];
58
59
  this.liveReload = true;
59
60
  this.templateVariables = {};
60
- this.ns = name.toUpperCase();
61
- this.ns = this.ns.replace(/[- ]*?/g, '_');
61
+ this.ns = name.replace(/[- ]+/g, '_').toUpperCase();
62
62
  this.codeVariables = {};
63
63
  }
64
64
 
@@ -100,13 +100,13 @@ export default class App {
100
100
  if (names.length === 0) return '';
101
101
 
102
102
  var members = names.map(function(name) {
103
- return ` ${name}: ${JSON.stringify(this.codeVariables[name])},`
103
+ return ` ${name}: ${JSON.stringify(this.codeVariables[name])},`
104
104
  }, this);
105
105
 
106
106
  var codeBlock =
107
- ` ${this.ns} = {
107
+ ` window.${this.ns} = {
108
108
  ${members.join('\n')}
109
- }
109
+ }
110
110
  `;
111
111
  return codeBlock;
112
112
  }
@@ -162,8 +162,13 @@ ${members.join('\n')}
162
162
  this.templateVariables[name] = value;
163
163
  }
164
164
 
165
- addConfig(config, root) {
166
- this.configs[root] = config;
165
+ /**
166
+ * Call this to add a configuration object to the application
167
+ * @param {Object} config a configuration object that will be added to the
168
+ * configuration store. Use get from @polylith/config to access
169
+ */
170
+ addConfig(config) {
171
+ this.configs.push(config);
167
172
  }
168
173
 
169
174
  /**
@@ -184,7 +189,7 @@ ${members.join('\n')}
184
189
  var files = new Files(this.sourcePath, this.destPath)
185
190
 
186
191
  // Find all the files frem the added css speces
187
- specs.forEach(function(spec) {
192
+ this.cssSpecs.forEach(function(spec) {
188
193
  files.addResourceSpec('', spec);
189
194
  }, this)
190
195
 
@@ -196,7 +201,7 @@ ${members.join('\n')}
196
201
  }, this);
197
202
 
198
203
  // now add them to be copied
199
- this.addResources('', specs);
204
+ this.addResources('', this.cssSpecs);
200
205
  }
201
206
 
202
207
  /**
@@ -477,7 +482,7 @@ ${members.join('\n')}
477
482
  var input = [this.fullIndexPath];
478
483
 
479
484
  // using a for loop because we are making an async call
480
- for (let loadable of loadables) {
485
+ for (let loadable of this.loadables) {
481
486
  // find all the css files for the loadables
482
487
  await this.findLoadableCss(loadable);
483
488
  input.push(loadable.index);
@@ -499,6 +504,7 @@ ${members.join('\n')}
499
504
  presets: ['@babel/preset-react'],
500
505
  babelHelpers: 'bundled',
501
506
  }),
507
+ loadConfigs(this.configs),
502
508
  loader(this.loadables),
503
509
  features(this.featureIndexes),
504
510
  jsconfig(this.root),
package/index.js CHANGED
@@ -2,7 +2,7 @@ import App from './App.js'
2
2
  import Feature from './Feature.js';
3
3
  import ConfigApp from './ConfigApp.js';
4
4
  import ConfigFeature from './ConfigFeature.js';
5
- import utils from './utils.js';
5
+ import * as utils from './utils.js';
6
6
 
7
7
  var utilsExport = {
8
8
  forceToPosix: utils.forceToPosix,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polylith/builder",
3
- "version": "0.0.39",
3
+ "version": "0.0.41",
4
4
  "description": "The polylith builder",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -0,0 +1,40 @@
1
+ function makeSource(configs) {
2
+
3
+ var configBody = ''
4
+
5
+ configs.forEach(function(config) {
6
+ configBody +=
7
+ `config.add(
8
+ ${JSON.stringify(config, null, ' ')})
9
+
10
+ `
11
+ })
12
+
13
+ var source =
14
+ `import config from '@polylith/config-store';
15
+ export default config;
16
+
17
+ ${configBody}
18
+ `
19
+ return source;
20
+ }
21
+
22
+ export default function loadConfigs(configs) {
23
+ return {
24
+ name: 'config',
25
+
26
+ resolveId (source, _, third) {
27
+ if (source === '@polylith/config') {
28
+ return source;
29
+ }
30
+ return null;
31
+ },
32
+
33
+ async load (id) {
34
+ if (id === '@polylith/config') {
35
+ return makeSource(configs);
36
+ }
37
+ return null;
38
+ }
39
+ };
40
+ }
@@ -18,7 +18,7 @@ export default function(name, files) {
18
18
  },
19
19
 
20
20
  watchChange(file, event) {
21
- files.copyOneFile(file);
21
+ files.copyOneFile(file, true);
22
22
  },
23
23
 
24
24
  async generateBundle(outputOptions, bundleInfo) {
package/utils.js CHANGED
@@ -19,7 +19,7 @@ export function forceToPosix(src) {
19
19
  }
20
20
 
21
21
  export function fileToPath(filename) {
22
- filename = fixPath(filename);
22
+ filename = forceToPosix(filename);
23
23
  return path.dirname(filename);
24
24
  }
25
25