polylith 0.1.35 → 0.1.37

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
@@ -106,7 +106,6 @@ async function getApp(spec, options) {
106
106
  return app;
107
107
  }
108
108
 
109
-
110
109
  async function walkApps(name, config, options, cb) {
111
110
  var specs = getAppSpecs(name, config, options);
112
111
  var apps = [];
@@ -123,8 +122,6 @@ async function walkApps(name, config, options, cb) {
123
122
 
124
123
  }
125
124
 
126
-
127
-
128
125
  /**
129
126
  * Call this method to build all the applications specified on the command line
130
127
  *
@@ -144,7 +141,6 @@ export async function build(name, config, options, watch) {
144
141
  return apps;
145
142
  }
146
143
 
147
-
148
144
  async function server(options) {
149
145
  var server = new PolylithServer(options, options.dest);
150
146
  await server.create(options.apps);
@@ -152,7 +148,6 @@ async function server(options) {
152
148
  }
153
149
 
154
150
  export async function watch(name, config, options) {
155
- console.log('watch', name, config, options);
156
151
  var apps = await build(name, config, options, true);
157
152
 
158
153
  for (let app of apps) {
@@ -162,6 +157,12 @@ export async function watch(name, config, options) {
162
157
  await server({...options, apps: apps});
163
158
  }
164
159
 
160
+ export async function run(name, config, options) {
161
+ var apps = await build(name, config, options, false);
162
+
163
+ await server({...options, apps: apps});
164
+ }
165
+
165
166
  export async function test(name, config, options) {
166
167
  var apps = await walkApps(name, config, options, async function(app) {
167
168
  return await app.test();
package/bin/polylith.js CHANGED
@@ -7,7 +7,7 @@ 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, test } from './apps.js';
10
+ import { watch, build, test, run } from './apps.js';
11
11
 
12
12
  var exec = promisify(child_process.exec);
13
13
  var argv = minimist(process.argv.slice(2))
@@ -73,14 +73,13 @@ function getOption(name, short) {
73
73
  }
74
74
 
75
75
  /**
76
- * Call this method to read the polylith configuration file. This is assumed to
77
- * be in the working directory.
76
+ * Caqll this method to read a single configuration JSON file,
78
77
  *
79
- * @returns {Object} the json parsed object from the config file, or the default
80
- * options if the file does not exist
78
+ * @param {String} filename the path of the file to read
79
+ *
80
+ * @returns {Object} the configuration
81
81
  */
82
- async function readConfig() {
83
- var filename = path.join(workingDir(), 'polylith.json');
82
+ async function readOneConfig(filename) {
84
83
  var exists = await fileExists(filename);
85
84
  var config = {};
86
85
 
@@ -88,7 +87,7 @@ async function readConfig() {
88
87
  try {
89
88
  config = JSON.parse(await readFile(filename, 'utf-8'));
90
89
  } catch (e) {
91
- console.warn('unable to load polylith configuration file');
90
+ console.warn('unable to load polylith configuration file ', filename);
92
91
  console.warn(e.message);
93
92
  }
94
93
  }
@@ -96,6 +95,27 @@ async function readConfig() {
96
95
  return config;
97
96
  }
98
97
 
98
+ /**
99
+ * Call this method to read the polylith configuration file and the environment
100
+ * specific configuration file. This is assumed to be in the working directory.
101
+ *
102
+ * @returns {Object} the json parsed object from the config file, or the default
103
+ * options if the file does not exist
104
+ */
105
+ async function readConfig() {
106
+ var envExt = process.env.NODE_ENV ? '.' + process.env.NODE_ENV : false;
107
+ var filename = path.join(workingDir(), 'polylith.json');
108
+ var envFilename = path.join(workingDir(), `polylith${envExt}.json`)
109
+ var config = await readOneConfig(filename);
110
+ var envConfig = {};
111
+
112
+ if (envExt) {
113
+ envConfig = await readOneConfig(envFilename);
114
+ }
115
+
116
+ return {...config, ...envConfig}
117
+ }
118
+
99
119
  /**
100
120
  * Call this method to sort the top level keys of the given object.
101
121
  *
@@ -136,7 +156,7 @@ async function writeConfig(config) {
136
156
  * Call this method to get the current options. Order of precedence is default,
137
157
  * polylith.json and command line
138
158
  */
139
- async function setOptions() {
159
+ async function getOptions() {
140
160
  var config = await readConfig();
141
161
 
142
162
  clOptions = {...clOptions, ...config};
@@ -219,19 +239,19 @@ function camelCase(name) {
219
239
  }
220
240
 
221
241
  /**
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.
242
+ * Call this method to normalize the name so that it is in snake case: each
243
+ * individual part is lower case and separated by '_'. The passed name is
244
+ * assumed to be either separated with one of [' ', '-', '_'] or is in camel
245
+ * case or pascal case.
225
246
  *
226
247
  * @param {String} name the name to normalize
227
248
  *
228
- * @returns {String} the normalized string which will be all lowercase with each
229
- part separated with '_';
249
+ * @returns {String} the normalized string which will be in snake case;
230
250
  */
231
251
  function normalizeCase(name) {
232
252
  if (!name) return;
233
253
 
234
- // default to pascal case, because we will break it into pieces based on
254
+ // start with pascal case, because we will break it into pieces based on
235
255
  // each part starting with an upercase letter.
236
256
  name = pascalCase(name);
237
257
 
@@ -374,7 +394,7 @@ function checkLocalPolylith() {
374
394
  * Call this function to execure the command from the command line
375
395
  */
376
396
  async function run() {
377
- await setOptions();
397
+ await getOptions();
378
398
  var config = await readConfig();
379
399
 
380
400
  if (!verifyParams() || argv.help || argv.h) {
@@ -418,6 +438,10 @@ async function run() {
418
438
  await test(params[1], config, clOptions)
419
439
  break;
420
440
  }
441
+
442
+ case 'run': {
443
+ await run(params[1], config, clOptions)
444
+ }
421
445
  }
422
446
  }
423
447
 
package/bin/utils.js CHANGED
@@ -28,7 +28,6 @@ export function fileToPath(filename) {
28
28
  return path.dirname(filename);
29
29
  }
30
30
 
31
-
32
31
  /**
33
32
  * call this function to check if the given file exists
34
33
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polylith",
3
- "version": "0.1.35",
3
+ "version": "0.1.37",
4
4
  "description": "cli for the polylith environment",
5
5
  "bin": {
6
6
  "polylith": "bin/polylith.js"