polylith 0.1.24 → 0.1.25

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.
@@ -4,7 +4,11 @@ import path from "path/posix";
4
4
  var projectRoot = path.join(utils.fileToPath(import.meta.url), '../');
5
5
  class {App}App extends App {
6
6
  constructor() {
7
- super('{app}', projectRoot, '{path}{src}/index.js', '{dest}');
7
+ super('{app}', {
8
+ root: projectRoot,
9
+ index: '{path}{src}/index.js',
10
+ dest: '{dest}'
11
+ });
8
12
  this.setHtmlTemplate('{path}/{src}/index.html', '{dest}{path}/index.html');
9
13
  this.addResources('', [
10
14
  {
package/bin/apps.js CHANGED
@@ -106,6 +106,25 @@ async function getApp(spec, options) {
106
106
  return app;
107
107
  }
108
108
 
109
+
110
+ async function walkApps(name, config, options, cb) {
111
+ var specs = getAppSpecs(name, config, options);
112
+ var apps = [];
113
+
114
+ // using for loop because we are making async calls
115
+ for (let spec of specs) {
116
+ let app = await getApp(spec, options);
117
+ if (!app) continue;
118
+
119
+ if (await cb(app)) apps.push(app)
120
+ }
121
+
122
+ return apps;
123
+
124
+ }
125
+
126
+
127
+
109
128
  /**
110
129
  * Call this method to build all the applications specified on the command line
111
130
  *
@@ -117,18 +136,10 @@ async function getApp(spec, options) {
117
136
  * @returns {Promise.<Array.<App>>} the list of built apps
118
137
  */
119
138
  export async function build(name, config, options, watch) {
120
- var specs = getAppSpecs(name, config, options);
121
- var apps = [];
122
-
123
- // using for loop because we are making async calls
124
- for (let spec of specs) {
125
- let app = await getApp(spec, options);
126
- if (!app) continue;
127
-
128
- apps.push(app);
139
+ var apps = await walkApps(name, config, options, async function(app) {
129
140
  app.setLiveReload(watch);
130
- await app.build();
131
- }
141
+ return await app.build();
142
+ })
132
143
 
133
144
  return apps;
134
145
  }
@@ -136,7 +147,7 @@ export async function build(name, config, options, watch) {
136
147
 
137
148
  async function server(apps, options) {
138
149
  var server = new PolylithServer({apps: apps}, options.dest);
139
- await server.create(apps);
150
+ server.create(apps);
140
151
  server.start(options.port || '8081');
141
152
  }
142
153
 
@@ -149,3 +160,18 @@ export async function watch(name, config, options) {
149
160
 
150
161
  server(apps, options);
151
162
  }
163
+
164
+ export async function test(name, config, options) {
165
+ var apps = await walkApps(name, config, options, async function(app) {
166
+ return await app.test();
167
+ })
168
+
169
+ if (options.watch) {
170
+ for (let app of apps) {
171
+ app.watch();
172
+ }
173
+ }
174
+
175
+ return apps;
176
+
177
+ }
package/bin/polylith.js CHANGED
@@ -7,12 +7,14 @@ import { promisify } from 'node:util';
7
7
  import child_process from 'node:child_process';
8
8
  import { readFile, writeFile } from 'node:fs/promises';
9
9
  import { processManifest } from './templates.js';
10
- import { watch, build } from './apps.js';
10
+ import { watch, build, test } from './apps.js';
11
11
 
12
12
  var exec = promisify(child_process.exec);
13
13
  var argv = minimist(process.argv.slice(2))
14
14
  var params = argv._;
15
- var OPTIONS = {
15
+
16
+ // these are the default options
17
+ var clOptions = {
16
18
  multiple: false,
17
19
  dest: 'dist',
18
20
  src: 'src',
@@ -21,6 +23,7 @@ var OPTIONS = {
21
23
  code: false,
22
24
  index: true,
23
25
  react: true,
26
+ watch: false,
24
27
  }
25
28
 
26
29
  var thisDir = path.dirname(forceToPosix(import.meta.url));
@@ -66,7 +69,7 @@ function checkBoolean(val) {
66
69
  function getOption(name, short) {
67
70
  if (argv[name] !== undefined) return checkBoolean(argv[name]);
68
71
  if (argv[short] != undefined) return checkBoolean(argv[short]);
69
- return OPTIONS[name];
72
+ return clOptions[name];
70
73
  }
71
74
 
72
75
  /**
@@ -74,12 +77,12 @@ function getOption(name, short) {
74
77
  * be in the working directory.
75
78
  *
76
79
  * @returns {Object} the json parsed object from the config file, or the default
77
- * oprions if the file does not exist
80
+ * options if the file does not exist
78
81
  */
79
82
  async function readConfig() {
80
83
  var filename = path.join(workingDir(), 'polylith.json');
81
84
  var exists = await fileExists(filename);
82
- var config = OPTIONS;
85
+ var config = {};
83
86
 
84
87
  if (exists) {
85
88
  try {
@@ -94,7 +97,7 @@ async function readConfig() {
94
97
  }
95
98
 
96
99
  /**
97
- * Call this metho to sorts the top level keys of the given object.
100
+ * Call this method to sort the top level keys of the given object.
98
101
  *
99
102
  * @param {Object} config the object to sort
100
103
  *
@@ -136,19 +139,20 @@ async function writeConfig(config) {
136
139
  async function setOptions() {
137
140
  var config = await readConfig();
138
141
 
139
- Object.assign(OPTIONS, config);
142
+ clOptions = {...clOptions, ...config};
140
143
 
141
- OPTIONS.multiple = getOption('multiple', 'm');
142
- OPTIONS.dest = getOption('dest', 'd');
143
- OPTIONS.src = getOption('src', 's')
144
- OPTIONS.builds = getOption('builds', 'b')
145
- OPTIONS.all = getOption('all', 'a')
146
- OPTIONS.code = getOption('code', 'c')
147
- OPTIONS.index = getOption('index', 'i')
148
- OPTIONS.react = getOption('react', 'r')
144
+ clOptions.multiple = getOption('multiple', 'm');
145
+ clOptions.dest = getOption('dest', 'd');
146
+ clOptions.src = getOption('src', 's')
147
+ clOptions.builds = getOption('builds', 'b')
148
+ clOptions.all = getOption('all', 'a')
149
+ clOptions.code = getOption('code', 'c')
150
+ clOptions.index = getOption('index', 'i')
151
+ clOptions.react = getOption('react', 'r')
152
+ clOptions.watch = getOption('watch', 'w')
149
153
 
150
154
  // force multiple if we already have more than one app;
151
- if (config.apps && config.apps.length > 1) OPTIONS.multiple = true;
155
+ if (config.apps && config.apps.length > 1) clOptions.multiple = true;
152
156
  }
153
157
 
154
158
  /**
@@ -202,7 +206,7 @@ function pascalCase(name) {
202
206
  * each part of the name with an uppercase letter except the first which has the
203
207
  * first letter lowercase. It assumes the part separator is either '-' or '_'
204
208
  *
205
- * @param {String} name th ename to convert
209
+ * @param {String} name the name to convert
206
210
  * @returns {String} the camel case name
207
211
  */
208
212
  function camelCase(name) {
@@ -215,10 +219,9 @@ function camelCase(name) {
215
219
  }
216
220
 
217
221
  /**
218
- * Call this method to normalize the name so that each individual part
219
- * is lower case and separated by '_'. It makes no assumptions about how the
220
- * name was formed other than it uses some standard to separate individual
221
- * parts.
222
+ * Call this method to normalize the name so that each individual part is lower
223
+ * case and separated by '_'. The name is assumed to be either separated with
224
+ * spaces, -, or _; or is in camel case or pascal case.
222
225
  *
223
226
  * @param {String} name the name to normalize
224
227
  *
@@ -235,9 +238,8 @@ function normalizeCase(name) {
235
238
  // separate the string by assuming each part starts with an uppercase letter
236
239
  var parts = [...name.matchAll(/([A-Z][a-z]*)/g)];
237
240
 
238
-
239
- var parts = parts.map(function (part) {
240
- return nameCase(part[1]);
241
+ parts = parts.map(function (part) {
242
+ return part[1].toLowerCase();
241
243
  })
242
244
 
243
245
  return parts.join('_');
@@ -255,7 +257,7 @@ function normalizeCase(name) {
255
257
  * - APP_ = Upper snake case
256
258
  * - app_ = snake case;
257
259
  * - ['App Title'] = title case
258
- * - app the given cae from the command line
260
+ * - app = the name as given from the command line
259
261
  *
260
262
  *
261
263
  * @param {Object} params the parameters from the command line
@@ -268,7 +270,7 @@ function getNames(params) {
268
270
  var app = '';
269
271
  var name = '';
270
272
 
271
- if (OPTIONS.multiple && !OPTIONS.all) {
273
+ if (clOptions.multiple && !clOptions.all) {
272
274
  app = params[1];
273
275
  name = params[2];
274
276
  } else {
@@ -296,11 +298,11 @@ function getNames(params) {
296
298
  names.name = name;
297
299
  }
298
300
 
299
- names.dest = OPTIONS.dest;
300
- names.builds = OPTIONS.builds;
301
- names.src = OPTIONS.src;
302
- names.react = OPTIONS.react;
303
- names.path = OPTIONS.multiple ? '/' + app : '';
301
+ names.dest = clOptions.dest;
302
+ names.builds = clOptions.builds;
303
+ names.src = clOptions.src;
304
+ names.react = clOptions.react;
305
+ names.path = clOptions.multiple ? '/' + app : '';
304
306
 
305
307
  return names;
306
308
  }
@@ -319,8 +321,8 @@ async function runInstall() {
319
321
  * @returns {Boolean} true if the number of parameters is correct
320
322
  */
321
323
  function verifyParams() {
322
- var multiple = OPTIONS.multiple;
323
- var all = OPTIONS.all;
324
+ var multiple = clOptions.multiple;
325
+ var all = clOptions.all;
324
326
  var command = params[0];
325
327
 
326
328
  if (!command) return false;
@@ -384,30 +386,34 @@ async function run() {
384
386
  {
385
387
  case 'init': {
386
388
  let names = getNames(params);
387
- await processManifest('install', names, OPTIONS);
389
+ await processManifest('install', names, clOptions);
388
390
  await runInstall();
389
391
  break;
390
392
  }
391
393
 
392
394
  case 'app': {
393
395
  let names = getNames(params);
394
- await processManifest('app', names, OPTIONS);
395
- await addAppJson(names, OPTIONS);
396
+ await processManifest('app', names, clOptions);
397
+ await addAppJson(names, clOptions);
396
398
  break;
397
399
  }
398
400
 
399
401
  case 'feature': {
400
402
  let names = getNames(params);
401
- processManifest('feature', names, OPTIONS);
403
+ processManifest('feature', names, clOptions);
402
404
  break;
403
405
  }
404
406
 
405
407
  case 'build': {
406
- await build(params[1], config, OPTIONS, false);
408
+ await build(params[1], config, clOptions, false);
407
409
  }
408
410
 
409
411
  case 'watch': {
410
- watch(params[1], config, OPTIONS)
412
+ await watch(params[1], config, clOptions)
413
+ }
414
+
415
+ case 'test': {
416
+ await test(params[1], config, clOptions)
411
417
  }
412
418
  }
413
419
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polylith",
3
- "version": "0.1.24",
3
+ "version": "0.1.25",
4
4
  "description": "cli for the polylith environment",
5
5
  "bin": {
6
6
  "polylith": "bin/polylith.js"