Skip to content

Commit 9fc05fa

Browse files
Interfacedl1bbcsg
authored andcommitted
Version 2.6.0
GitOrigin-RevId: 8e9dbb3acb16b0be3eb4047cf2a62c23aaba6374
1 parent 68f5c6f commit 9fc05fa

24 files changed

Lines changed: 905 additions & 389 deletions

.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ module.exports = {
6363
],
6464
extends: 'interfaced/node',
6565
rules: {
66-
'jsdoc/no-undefined-types': "off" // Introduces circular dependencies
66+
'jsdoc/no-undefined-types': 'off', // Introduces circular dependencies
67+
'no-console': 'error' // Winston logger should be used for output
6768
}
6869
},
6970
{

CHANGELOG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
# Change log
22

3+
## 2.6.0 (release date: 03.02.2020)
4+
5+
### Tools
6+
* Build process was refactored, CLI commands and Platform API were affected. See [migrations/2.5.0.md](./docs/migrations/2.5.0.md) for more details.
7+
* `zb build` now only accepts one platform and can't build for several at once.
8+
* `AbstractPlatform.buildApp` method is deprecated in favor of `AbstractPlatform.pack`.
9+
* Include entities now only get included in build for the platform that specified them.
10+
* Console output and logging was improved and now can be controlled with `--log-level` or `-l` flag, see `zb --help`.
11+
* `generated/package-info` was removed.
12+
313
## 2.5.0 (release date 23.01.2020)
414

515
### Framework
616
* ENTER key events caused by mouse clicks now no longer propagates down widget tree.
7-
* generated/package-info was deprecated and several defines were introduced to replace it. See [migrations/2.5.0.md](./docs/migrations/2.5.0.md) for more details.
17+
* `generated/package-info` was deprecated and several defines were introduced to replace it. See [migrations/2.5.0.md](./docs/migrations/2.5.0.md) for more details.
818
* Version checker will now tolerate prerelease versions.
919

1020
### Tools

bin/cli.js

Lines changed: 71 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ const {findPackageJson} = require('../lib/utils');
1616
const Application = require('../lib/application');
1717
const TemplateHelper = require('../lib/template-helper');
1818
const Scaffolding = require('../lib/scaffolding');
19+
const {rootLogger, createChild} = require('../lib/logger');
20+
const logger = createChild('CLI');
1921

2022

2123
/**
@@ -40,6 +42,7 @@ class CLI {
4042
if (this._application) {
4143
locations = locations.concat(this._application.getPathHelper().getTemplateLocations());
4244
}
45+
logger.silly(`Template locations: \n\t${locations.join('\n\t')}`);
4346
return locations;
4447
}
4548
);
@@ -57,6 +60,7 @@ class CLI {
5760
* Prepare app and start developer mode HTTP server.
5861
*/
5962
run() {
63+
logger.verbose(`Starting dev server`);
6064
this._assertApplication();
6165

6266
this._application.ready()
@@ -67,31 +71,41 @@ class CLI {
6771
* Build code and exit
6872
*/
6973
buildCode() {
74+
logger.verbose(`Building generated application code`);
7075
this._assertApplication();
7176

7277
this._application.ready()
7378
.then(() => this._application.buildCode());
7479
}
7580

7681
/**
77-
* @param {Array<string>} targets Platform names.
82+
* @param {string} target Platform name
7883
*/
79-
build(targets) {
84+
build(target) {
85+
logger.verbose(`Building application for ${target}`);
8086
this._assertApplication();
8187

82-
const platformsToCompile = this._application.getPlatforms().filter((platform) =>
83-
targets.includes(platform.getName()) || targets.includes('all')
84-
);
88+
const platform = this._application.getPlatforms().find((platform) => platform.getName() === target);
8589

8690
this._application.ready()
87-
.then(() => this._application.compile(platformsToCompile));
91+
.then(() => this._application.build(platform))
92+
.catch((e) => {
93+
if (e instanceof Error) {
94+
logger.error(e.toString());
95+
logger.debug(e.stack);
96+
} else {
97+
logger.error(e);
98+
}
99+
process.exit(2);
100+
});
88101
}
89102

90103
/**
91104
* @param {string} name
92105
* @param {string} path
93106
*/
94107
addScene(name, path) {
108+
logger.verbose(`Generating scene ${name} at ${path}`);
95109
this._assertApplication();
96110

97111
const appName = this._application.getConfig().project.name;
@@ -103,6 +117,7 @@ class CLI {
103117
* @param {string} path
104118
*/
105119
addPopup(name, path) {
120+
logger.verbose(`Generating popup ${name} at ${path}`);
106121
this._assertApplication();
107122

108123
const appName = this._application.getConfig().project.name;
@@ -114,6 +129,7 @@ class CLI {
114129
* @param {string} path
115130
*/
116131
addWidget(name, path) {
132+
logger.verbose(`Generating widget ${name} at ${path}`);
117133
this._assertApplication();
118134

119135
const appName = this._application.getConfig().project.name;
@@ -124,6 +140,7 @@ class CLI {
124140
* @param {string} target
125141
*/
126142
generateAliases(target) {
143+
logger.verbose(`Generating aliases map in ${target}`);
127144
this._assertApplication();
128145

129146
this._application.ready().then(() => {
@@ -133,14 +150,16 @@ class CLI {
133150
for (const [key, value] of this._application.getAliases()) {
134151
map[key] = value;
135152
}
153+
154+
logger.debug(`Aliases: \n${JSON.stringify(map, null, '\t')}`);
136155
const content = this._templateHelper.render('webpack.config.js.tpl', {map});
137156

138157
fs.writeFile(filename, content, 'utf8', (error) => {
139158
if (error) {
140-
console.error('Error writing aliases map:', error.message);
159+
logger.error(`Error writing aliases map: ${error.message}`);
141160
process.exit(1);
142161
} else {
143-
console.log('Aliases map generated in', chalk.cyan(filename));
162+
logger.output(`Aliases map generated in ${chalk.underline(filename)}`);
144163
}
145164
});
146165
});
@@ -154,28 +173,39 @@ class CLI {
154173
/* eslint-disable newline-per-chained-call */
155174
yargs
156175
.array('config').default('config', [])
157-
.array('addon').default('addon', []);
176+
.array('addon').default('addon', [])
177+
.string('log-level')
178+
.alias('log-level', 'l')
179+
.default('log-level', 'info')
180+
.choices('log-level', Object.keys(logger.levels));
181+
182+
rootLogger.level = yargs.argv.logLevel;
158183

159184
// @see {https://github.com/yargs/yargs/issues/1336}
160185
const configs = Array.isArray(yargs.argv.config) ?
161186
yargs.argv.config.reduce((flat, value) => flat.concat(value), []) :
162187
[yargs.argv.config];
163188

164189
const app = this._createApplication(configs, yargs.argv.addon);
165-
const buildTargets = ['all'];
190+
const buildTargets = [];
166191
let projectConfig = null;
167192

168193
if (app) {
169194
projectConfig = app.getConfig().project;
170-
app.getPlatforms()
171-
.forEach((platform) => {
172-
buildTargets.push(platform.getName());
173-
yargs.command(
174-
platform.getName(),
175-
`${platform.getName()} platform CLI commands`,
176-
(yargs) => platform.buildCLI(yargs, app)
177-
);
178-
});
195+
const platforms = app.getPlatforms();
196+
197+
logger.silly(`Application supports platforms: ${platforms.map((p) => p.getName()).join(', ')}`);
198+
199+
platforms.forEach((platform) => {
200+
buildTargets.push(platform.getName());
201+
yargs.command(
202+
platform.getName(),
203+
`${platform.getName()} platform CLI commands`,
204+
(yargs) => platform.buildCLI(yargs, app)
205+
);
206+
});
207+
} else {
208+
logger.debug(`Application was not created, running without it`);
179209
}
180210

181211
return yargs
@@ -193,11 +223,11 @@ class CLI {
193223
)
194224
.command('buildCode', 'Generate lifecycle code', (yargs) => this.buildCode(yargs))
195225
.command(
196-
'build <platform..>',
197-
'Build artifact for one or several platforms',
226+
'build <platform>',
227+
'Build artifact for specific platform',
198228
(yargs) => {
199229
yargs.positional('platform', {
200-
describe: 'platform name(s)',
230+
describe: 'platform name',
201231
choices: buildTargets
202232
});
203233
},
@@ -277,13 +307,13 @@ class CLI {
277307
* @protected
278308
*/
279309
init(name, root) {
280-
const data = {
281-
name
282-
};
310+
logger.verbose(`Creating boilerplate application "${name}" in ${root}`);
283311

284-
this._templateHelper.renderDir('boilerplate', root, data);
312+
this._templateHelper.renderDir('boilerplate', root, {
313+
name
314+
});
285315

286-
console.log(`Boilerplate ZombieBox application ${name} created at`, root);
316+
logger.output(`Boilerplate ZombieBox application "${name}" created at ${root}`);
287317
}
288318

289319
/**
@@ -297,11 +327,19 @@ class CLI {
297327
return this._application;
298328
}
299329

330+
logger.silly(
331+
`Trying to instantiate Application` +
332+
(rawConfigs.length ? `\n\tConfigs: ${rawConfigs.join(', ')}` : '') +
333+
(rawAddons.length ? `\n\tAddons: ${rawAddons.join(', ')}` : '')
334+
);
335+
300336
const packageJson = findPackageJson(
301337
process.cwd(),
302338
(packageJson) => packageJson.dependencies && packageJson.dependencies.hasOwnProperty('zombiebox')
303339
);
304340

341+
logger.debug(`Application package.json path: ${chalk.underline(packageJson)}`);
342+
305343
if (!packageJson) {
306344
return null;
307345
}
@@ -318,8 +356,11 @@ class CLI {
318356
try {
319357
this._application = new Application(path.dirname(packageJson), configs, addons);
320358
} catch (e) {
321-
console.error(e.message);
322-
console.warn('Failed to create ZombieBox Application instance. CLI functionality will be limited');
359+
logger.warn(
360+
`Could not create Application instance, ` +
361+
`CLI commands that require it will not work: ${e.toString()}`
362+
);
363+
logger.debug(e.stack);
323364
}
324365
return this._application;
325366
}
@@ -329,7 +370,7 @@ class CLI {
329370
*/
330371
_assertApplication() {
331372
if (!this._application) {
332-
console.error('Could not find ZombieBox application');
373+
logger.error('Cannot execute this command without application');
333374
process.exit(1);
334375
}
335376
}

docs/migrations/2.6.0.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Version 2.6.0
2+
3+
## `zb build` CLI command
4+
5+
`zb build` no longer accepts a list of platforms or a special argument `all`. Invoke this command several times to compile for several platforms.
6+
7+
I.e. instead of `zb build tizen webos` use `zb build tizen` followed by `zb build webos`.
8+
9+
## `AbstractPlatform.pack`
10+
11+
`AbstractPlatform.pack` is meant to repalce `AbstractPlatform.buildApp`. The difference is that the new method is invoked after application `index.html` and static files were processed and only needs to pack them into platform artifact and does not need to call `BuildHelper` methods to build html application.
12+
13+
To migrate, platforms should replace `buildApp` implementation with `pack`, remove calls to `writeIndexHTML` and `copyStaticFiles`, assume `index.html` and all the necessary files already exist in build dir and proceed with platform-specific processing and packaging an artifact.
14+
15+
No migration should be necessary for application as the changes are backwards compatible, albeit this requires running compilation twice.
16+
17+
## `generated/package-info` removal
18+
19+
`generated/package-info` was properly removed following its deprecation in 2.5.0. See 2.5.0 [migration guide](./2.5.0.md).

lib/addons/abstract-platform.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const Application = require('../application');
1616
class AbstractPlatform extends AbstractAddon {
1717
/**
1818
* Build application in given dir.
19+
* @deprecated
1920
* @abstract
2021
* @param {Application} application
2122
* @param {string} distDir
@@ -24,6 +25,17 @@ class AbstractPlatform extends AbstractAddon {
2425
buildApp(application, distDir) {
2526
throw new Error(`AbstractPlatform.buildApp is not implemented in ${this.getName()}`);
2627
}
28+
29+
/**
30+
* Packages application that was built in distDir
31+
* @abstract
32+
* @param {Application} application
33+
* @param {string} distDir
34+
* @return {Promise}
35+
*/
36+
async pack(application, distDir) {
37+
throw new Error(`AbstractPlatform.pack is not implemented in ${this.getName()}`);
38+
}
2739
}
2840

2941

lib/addons/loader.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const {findPackageJson} = require('../utils');
1414
const AbstractAddon = require('./abstract-addon');
1515
const AbstractPlatform = require('./abstract-platform');
1616
const AbstractExtension = require('./abstract-extension');
17+
const logger = require('../logger').createChild('AddonLoader');
1718

1819
/* eslint-disable global-require */
1920

@@ -73,16 +74,21 @@ class AddonLoader {
7374
* @param {Object} packageJson
7475
*/
7576
loadFromPackageJson(packageJson) {
76-
Object.keys(packageJson['dependencies'] || {})
77-
.filter((packageName) => packageName.startsWith(PACKAGE_PREFIX))
78-
.map((packageName) => this._resolvePackagePath(packageName))
77+
const dependencies = Object.keys(packageJson['dependencies'] || {})
78+
.filter((packageName) => packageName.startsWith(PACKAGE_PREFIX));
79+
80+
logger.debug(`Addons found in package.json: \n\t${dependencies.join('\n\t')}`);
81+
82+
dependencies.map((packageName) => this._resolvePackagePath(packageName))
7983
.forEach((packagePath) => this.loadAddon(packagePath));
8084
}
8185

8286
/**
8387
* @param {string} addonPath
8488
*/
8589
loadAddon(addonPath) {
90+
logger.debug(`Loading addon from ${chalk.underline(addonPath)}`);
91+
8692
const Addon = require(addonPath);
8793

8894
const addon = /** @type {AbstractAddon} */ (new Addon());
@@ -109,11 +115,11 @@ class AddonLoader {
109115
this._loadedAddons.push({instance: addon, packageJson});
110116

111117
const type =
112-
addon instanceof AbstractPlatform ? 'Platform' :
113-
addon instanceof AbstractExtension ? 'Extension' :
114-
'Addon';
118+
addon instanceof AbstractPlatform ? 'platform' :
119+
addon instanceof AbstractExtension ? 'extension' :
120+
'addon';
115121

116-
console.log(`${type} ${chalk.green(addon.getName())} loaded`);
122+
logger.info(`Loaded ${type} ${chalk.green(addon.getName())}`);
117123
}
118124

119125
/**

0 commit comments

Comments
 (0)