polylith 0.1.75 → 0.1.76

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/bin/apps.js CHANGED
@@ -25,17 +25,15 @@ function findDefaultApp(config) {
25
25
  *
26
26
  * @param {String} name the app name specified from the command line
27
27
  * @param {Object} config the current polylith configuration object
28
- * @param {Object} options the options from the command line
29
28
  *
30
29
  * @returns {Array} the list of object specs to act on
31
30
  */
32
- export function getAppSpecs(name, config, options) {
31
+ export function getAppSpecs(name, config) {
33
32
  var specs = [];
34
33
  var foundSpec;
35
- var apps = [];
36
34
  var defaultApp = findDefaultApp(config);
37
35
 
38
- if (options.all) {
36
+ if (config.all) {
39
37
  specs = config.apps;
40
38
  } else if (!name) {
41
39
  if (!defaultApp) {
@@ -76,26 +74,26 @@ async function readJson(filename) {
76
74
  /**
77
75
  * Call this method to get the App object from the given app spec.
78
76
  *
79
- * @param {Object} spec the application spec from the poilylith configuration
77
+ * @param {Object} spec the application spec from the polylith configuration
80
78
  * object
81
- * @param {Object} options the command line options
79
+ * @param {Object} config the polylith configuration object
82
80
  *
83
81
  * @returns {App|Boolean} the application object, false if there ws an error
84
82
  */
85
- async function getApp(spec, options) {
86
- var buildPath = path.join(workingDir(), options.builds);
83
+ async function getApp(spec, config) {
84
+ var buildPath = path.join(workingDir(), config.builds);
87
85
  var filename = path.join(buildPath, spec.filename);
88
86
  var app;
89
87
 
90
88
  if (!spec.code) {
91
89
  var config = await(readJson(filename));
92
90
  if (!config) return false;
93
- app = new ConfigApp(config, workingDir());
91
+ app = new ConfigApp(spec, config, workingDir());
94
92
  } else {
95
93
  try {
96
94
  var res = await import(filename);
97
95
  if (!res.default) throw new Error('no default in application module')
98
- app = res.default;
96
+ app = new res.default(config);
99
97
  if (!app.build && app.watch) throw new Error('application file is not an application module');
100
98
  } catch(e) {
101
99
  console.warn(`error loading app ${spec.name}`);
@@ -106,13 +104,13 @@ async function getApp(spec, options) {
106
104
  return app;
107
105
  }
108
106
 
109
- async function walkApps(name, config, options, cb) {
110
- var specs = getAppSpecs(name, config, options);
107
+ async function walkApps(name, config, cb) {
108
+ var specs = getAppSpecs(name, config);
111
109
  var apps = [];
112
110
 
113
111
  // using for loop because we are making async calls
114
112
  for (let spec of specs) {
115
- let app = await getApp(spec, options);
113
+ let app = await getApp(spec, config);
116
114
  if (!app) continue;
117
115
 
118
116
  if (!cb || await cb(app)) apps.push(app)
@@ -125,14 +123,13 @@ async function walkApps(name, config, options, cb) {
125
123
  * Call this method to build all the applications specified on the command line
126
124
  *
127
125
  * @param {String} name the name of the application from the command line
128
- * @param {Object} config the polylith config object
129
- * @param {Object} options the options from the command line
126
+ * @param {Object} config the polylith config
130
127
  * @param {Boolean} watch true if building for watch mode
131
128
  *
132
129
  * @returns {Promise.<Array.<App>>} the list of built apps
133
130
  */
134
- export async function build(name, config, options, watch) {
135
- var apps = await walkApps(name, config, options, async function(app) {
131
+ export async function build(name, config, watch) {
132
+ var apps = await walkApps(name, config, async function(app) {
136
133
  app.setLiveReload(watch);
137
134
  return await app.build();
138
135
  })
@@ -140,46 +137,45 @@ export async function build(name, config, options, watch) {
140
137
  return apps;
141
138
  }
142
139
 
143
- async function server(options) {
144
- var server = new PolylithServer(options, options.dest);
145
- await server.create(options.apps);
146
- server.start(options.port || '8081');
140
+ async function server(config) {
141
+ var server = new PolylithServer(config, config.dest);
142
+ await server.create(config.apps);
143
+ server.start(config.port || '8081');
147
144
  }
148
145
 
149
- export async function watch(name, config, options) {
150
- var apps = await build(name, config, options, true);
146
+ export async function watch(name, config) {
147
+ var apps = await build(name, config, true);
151
148
 
152
149
  for (let app of apps) {
153
150
  await app.watch();
154
151
  }
155
152
 
156
- if (options.serve)
157
- await server({...options, apps: apps});
153
+ if (config.serve)
154
+ await server({...config, apps: apps});
158
155
  }
159
156
 
160
- export async function run(name, config, options) {
161
- var apps = await build(name, config, options, false);
157
+ export async function run(name, config) {
158
+ var apps = await build(name, config, false);
162
159
 
163
- await server({...options, apps: apps});
160
+ await server({...config, apps: apps});
164
161
  }
165
162
 
166
- export async function serve(name, config, options) {
167
- var apps = await walkApps(name, config, options);
163
+ export async function serve(name, config) {
164
+ var apps = await walkApps(name, config);
168
165
 
169
- await server({...options, apps: apps});
166
+ await server({...config, apps: apps});
170
167
  }
171
168
 
172
- export async function test(name, config, options) {
173
- var apps = await walkApps(name, config, options, async function(app) {
169
+ export async function test(name, config) {
170
+ var apps = await walkApps(name, config, async function(app) {
174
171
  return await app.test();
175
172
  })
176
173
 
177
- if (options.watch) {
174
+ if (config.watch) {
178
175
  for (let app of apps) {
179
176
  app.watch();
180
177
  }
181
178
  }
182
179
 
183
180
  return apps;
184
-
185
181
  }
package/bin/polylith.js CHANGED
@@ -27,6 +27,8 @@ var clOptions = {
27
27
  serve: true,
28
28
  }
29
29
 
30
+ var polylithConfig = {};
31
+
30
32
  var thisDir = path.dirname(forceToPosix(import.meta.url));
31
33
 
32
34
  /**
@@ -70,7 +72,7 @@ function checkBoolean(val) {
70
72
  function getOption(name, short) {
71
73
  if (argv[name] !== undefined) return checkBoolean(argv[name]);
72
74
  if (argv[short] != undefined) return checkBoolean(argv[short]);
73
- return clOptions[name];
75
+ return polylithConfig[name];
74
76
  }
75
77
 
76
78
  /**
@@ -160,21 +162,21 @@ async function writeConfig(config) {
160
162
  async function getOptions() {
161
163
  var config = await readConfig();
162
164
 
163
- clOptions = {...clOptions, ...config};
165
+ polylithConfig = {...clOptions, ...config};
164
166
 
165
- clOptions.multiple = getOption('multiple', 'm');
166
- clOptions.dest = getOption('dest', 'd');
167
- clOptions.src = getOption('src', 's')
168
- clOptions.builds = getOption('builds', 'b')
169
- clOptions.all = getOption('all', 'a')
170
- clOptions.code = getOption('code', 'c')
171
- clOptions.index = getOption('index', 'i')
172
- clOptions.react = getOption('react', 'r')
173
- clOptions.watch = getOption('watch', 'w')
174
- clOptions.serve = getOption('serve', 'v')
167
+ polylithConfig.multiple = getOption('multiple', 'm');
168
+ polylithConfig.dest = getOption('dest', 'd');
169
+ polylithConfig.src = getOption('src', 's')
170
+ polylithConfig.builds = getOption('builds', 'b')
171
+ polylithConfig.all = getOption('all', 'a')
172
+ polylithConfig.code = getOption('code', 'c')
173
+ polylithConfig.index = getOption('index', 'i')
174
+ polylithConfig.react = getOption('react', 'r')
175
+ polylithConfig.watch = getOption('watch', 'w')
176
+ polylithConfig.serve = getOption('serve', 'v')
175
177
 
176
178
  // force multiple if we already have more than one app;
177
- if (config.apps && config.apps.length > 1) clOptions.multiple = true;
179
+ if (config.apps && config.apps.length > 1) polylithConfig.multiple = true;
178
180
  }
179
181
 
180
182
  /**
@@ -292,7 +294,7 @@ function getNames(params) {
292
294
  var app = '';
293
295
  var name = '';
294
296
 
295
- if (clOptions.multiple && !clOptions.all) {
297
+ if (polylithConfig.multiple && !polylithConfig.all) {
296
298
  app = params[1];
297
299
  name = params[2];
298
300
  } else {
@@ -320,11 +322,11 @@ function getNames(params) {
320
322
  names.name = name;
321
323
  }
322
324
 
323
- names.dest = clOptions.dest;
324
- names.builds = clOptions.builds;
325
- names.src = clOptions.src;
326
- names.react = clOptions.react;
327
- names.path = clOptions.multiple ? '/' + app : '';
325
+ names.dest = polylithConfig.dest;
326
+ names.builds = polylithConfig.builds;
327
+ names.src = polylithConfig.src;
328
+ names.react = polylithConfig.react;
329
+ names.path = polylithConfig.multiple ? '/' + app : '';
328
330
 
329
331
  return names;
330
332
  }
@@ -344,8 +346,8 @@ async function runInstall() {
344
346
  * @returns {Boolean} true if the number of parameters is correct
345
347
  */
346
348
  function verifyParams() {
347
- var multiple = clOptions.multiple;
348
- var all = clOptions.all;
349
+ var multiple = polylithConfig.multiple;
350
+ var all = polylithConfig.all;
349
351
  var command = params[0];
350
352
 
351
353
  if (!command) return false;
@@ -384,7 +386,7 @@ async function addAppJson(names, options) {
384
386
  }
385
387
 
386
388
  /**
387
- * Call this method to test that the instance of polylith being run is local to
389
+ * Call this method to test that the instance of polylith being run is local to
388
390
  * the current project
389
391
  *
390
392
  * @returns {Boolean} true if the instance is local
@@ -394,11 +396,10 @@ function checkLocalPolylith() {
394
396
  }
395
397
 
396
398
  /**
397
- * Call this function to execure the command from the command line
399
+ * Call this function to execute the command from the command line
398
400
  */
399
401
  async function execute() {
400
402
  await getOptions();
401
- var config = await readConfig();
402
403
 
403
404
  if (!verifyParams() || argv.help || argv.h) {
404
405
  await outputInstructions();
@@ -409,45 +410,45 @@ async function execute() {
409
410
  {
410
411
  case 'init': {
411
412
  let names = getNames(params);
412
- await processManifest('install', names, clOptions);
413
+ await processManifest('install', names, polylithConfig);
413
414
  await runInstall();
414
415
  break;
415
416
  }
416
417
 
417
418
  case 'app': {
418
419
  let names = getNames(params);
419
- await processManifest('app', names, clOptions);
420
- await addAppJson(names, clOptions);
420
+ await processManifest('app', names, polylithConfig);
421
+ await addAppJson(names, polylithConfig);
421
422
  break;
422
423
  }
423
424
 
424
425
  case 'feature': {
425
426
  let names = getNames(params);
426
- processManifest('feature', names, clOptions);
427
+ processManifest('feature', names, polylithConfig);
427
428
  break;
428
429
  }
429
430
 
430
431
  case 'build': {
431
- await build(params[1], config, clOptions, false);
432
+ await build(params[1], polylithConfig, false);
432
433
  break;
433
434
  }
434
435
 
435
436
  case 'watch': {
436
- await watch(params[1], config, clOptions)
437
+ await watch(params[1], polylithConfig)
437
438
  break;
438
439
  }
439
440
 
440
441
  case 'test': {
441
- await test(params[1], config, clOptions)
442
+ await test(params[1], polylithConfig)
442
443
  break;
443
444
  }
444
445
 
445
446
  case 'run': {
446
- await run(params[1], config, clOptions)
447
+ await run(params[1], polylithConfig)
447
448
  }
448
449
 
449
450
  case 'serve' : {
450
- await serve(params[1], config, clOptions)
451
+ await serve(params[1], polylithConfig)
451
452
  }
452
453
  }
453
454
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polylith",
3
- "version": "0.1.75",
3
+ "version": "0.1.76",
4
4
  "description": "cli for the polylith environment",
5
5
  "bin": {
6
6
  "polylith": "bin/polylith.js"
@@ -17,7 +17,7 @@
17
17
  "author": "Glenn Anderson",
18
18
  "license": "MIT",
19
19
  "dependencies": {
20
- "@polylith/builder": "0.2.21",
20
+ "@polylith/builder": "0.2.22",
21
21
  "@polylith/server": "0.1.25",
22
22
  "fs-extra": "^10.1.0",
23
23
  "minimist": "^1.2.7"