Skip to content

Commit

Permalink
2.5.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
JayCanuck committed Aug 12, 2019
2 parents 668d683 + 2fcdc2f commit 08b2ddd
Show file tree
Hide file tree
Showing 17 changed files with 340 additions and 81 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
## 2.5.0 (August 12, 2019)

### pack

* Redesigned `option-parser` with encapsulated theme option support and environment variable overriding.
* Fixed V8 snapshot failure when attempting to polyfill `<TypedArray>.toLocaleString`, but `Int8Array.prototype.toLocaleString` already exists.
* Fixed bug where undefined `ri` values would result in `Infinity` pixel values.

### test

* Added mock support for `<Element>.animate`.
* Added support for theme-based iLib resbundle resource paths.
* Fixed `.env` files not being processed and loaded into `process.env`.

### template

* Added support for `type` template property (used during project creation messages if `prepare` is not overriden). Defaults to `'app'`.
* Fixed bug where template function parameters `defaultGenerator` and `type` could be accidentally overriden via command line arguments.

## 2.4.1 (July 14, 2019)

* Fixed alias prioritization for iLib to correctly locate/index iLib when build framework builds.
Expand Down
1 change: 1 addition & 0 deletions bin/enact.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ if (process.argv.indexOf('-v') >= 0 || process.argv.indexOf('--version') >= 0) {
case 'transpile':
case 'pack':
case 'clean':
case 'info':
case 'test':
case 'eject':
case 'template':
Expand Down
16 changes: 10 additions & 6 deletions commands/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ const minimist = require('minimist');
const validatePackageName = require('validate-npm-package-name');

const ENACT_DEV_NPM = '@enact/cli';
const CORE_JS_NPM = 'core-js@2';
const CORE_JS_NPM = 'core-js@3';
const INCLUDED = path.dirname(require.resolve('@enact/template-moonstone'));
const TEMPLATE_DIR = path.join(process.env.APPDATA || os.homedir(), '.enact');

const defaultGenerator = {
overwrite: false,
install: true,
type: 'app',
validate: ({template, name}) => {
const validation = validatePackageName(name);

Expand Down Expand Up @@ -53,7 +54,7 @@ const defaultGenerator = {
}
}
},
prepare: ({directory, name}) => {
prepare: ({directory, name, type}) => {
// After the workspace is ensured to exist, but before template is copied
const validFiles = [
// Generic project fragments and outside tool configs.
Expand Down Expand Up @@ -82,9 +83,9 @@ const defaultGenerator = {
];
const rel = path.relative(process.cwd(), directory);
if (!rel || rel === '.') {
console.log('Creating a new Enact app...');
console.log(`Creating a new Enact ${type}...`);
} else {
console.log(`Creating a new Enact app in ${rel}...`);
console.log(`Creating a new Enact ${type} in ${rel}...`);
}

console.log();
Expand Down Expand Up @@ -146,8 +147,11 @@ const defaultGenerator = {
};

function displayHelp() {
let e = 'node ' + path.relative(process.cwd(), __filename);
if (require.main !== module) e = 'enact create';

console.log(' Usage');
console.log(' enact create [options] [<directory>]');
console.log(` ${e} [options] [<directory>]`);
console.log();
console.log(' Arguments');
console.log(' directory Optional destination directory');
Expand Down Expand Up @@ -248,7 +252,7 @@ function npmInstall(directory, verbose, ...rest) {

function api(opts = {}) {
return resolveTemplateGenerator(opts.template).then(({generator, templatePath}) => {
const params = Object.assign({opts, defaultGenerator}, opts);
const params = Object.assign({}, opts, {opts, defaultGenerator, type: generator.type});

return new Promise(resolve => resolve(generator.validate && generator.validate(params)))
.then(() => fs.ensureDir(opts.directory))
Expand Down
5 changes: 4 additions & 1 deletion commands/eject.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ const bareTasks = {
};

function displayHelp() {
let e = 'node ' + path.relative(process.cwd(), __filename);
if (require.main !== module) e = 'enact eject';

console.log(' Usage');
console.log(' enact eject [options]');
console.log(` ${e} [options]`);
console.log();
console.log(' Options');
console.log(' -b, --bare Abandon Enact CLI command enhancements');
Expand Down
174 changes: 174 additions & 0 deletions commands/info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
/* eslint-env node, es6 */
const path = require('path');
const fs = require('fs');
const chalk = require('chalk');
const spawn = require('cross-spawn');
const minimist = require('minimist');
const resolveSync = require('resolve').sync;

function displayHelp() {
let e = 'node ' + path.relative(process.cwd(), __filename);
if (require.main !== module) e = 'enact info';

console.log(' Usage');
console.log(` ${e} [options]`);
console.log();
console.log(' Options');
console.log(' --dev Include dev dependencies');
console.log(' --cli Display CLI information');
console.log(' -v, --version Display version information');
console.log(' -h, --help Display help information');
console.log();
process.exit(0);
}

function logVersion(pkg, rel = __dirname) {
try {
const jsonPath = resolveSync(pkg + '/package.json', {basedir: rel});
const meta = require(jsonPath);
const dir = path.dirname(jsonPath);
if (fs.lstatSync(dir).isSymbolicLink()) {
const realDir = fs.realpathSync(dir);
const git = gitInfo(realDir);
console.log(meta.name + ': ' + (git || meta.version));
console.log(chalk.cyan('\tSymlinked from'), realDir);
} else {
console.log(meta.name + ': ' + meta.version);
}
} catch (e) {
console.log(pkg + ': ' + chalk.red('<unknown>'));
}
}

function gitInfo(dir) {
const git = (args = []) => {
try {
const result = spawn.sync('git', args, {encoding: 'utf8', cwd: dir, env: process.env});
if (!result.error && result.status === 0) return result.stdout.trim();
} catch (e) {}
};
const tag = git(['describe', '--tags', '--exact-match']);
if (tag) {
return chalk.green(`${tag} (git)`);
} else {
const branch = git(['symbolic-ref', '-q', '--short', 'HEAD']) || 'HEAD';
const commit = git(['rev-parse', '--short', 'HEAD']);
if (commit) return chalk.green(`${branch} @ ${commit} (git)`);
}
}

function globalModules() {
try {
const result = spawn.sync('npm', ['config', 'get', 'prefix', '-g'], {
cwd: process.cwd(),
env: process.env
});
if (result.error || result.status !== 0 || !(result.stdout = result.stdout.trim())) {
return require('global-modules');
} else if (process.platform === 'win32' || ['msys', 'cygwin'].includes(process.env.OSTYPE)) {
return path.resolve(result.stdout, 'node_modules');
} else {
return path.resolve(result.stdout, 'lib/node_modules');
}
} catch (e) {
return require('global-modules');
}
}

function api({cliInfo = false, dev = false} = {}) {
return new Promise((resolve, reject) => {
try {
if (cliInfo) {
// Display info on CLI itself
const gm = globalModules();
const gCLI = path.join(gm, '@enact', 'cli');
const isGlobal =
fs.existsSync(gCLI) &&
path.dirname(require.resolve(path.join(gCLI, 'package.json'))) === path.dirname(__dirname);
console.log(chalk.yellow.bold('==Enact CLI Info=='));
if (isGlobal && fs.lstatSync(gCLI).isSymbolicLink()) {
const ver = gitInfo(__dirname) || require('../package.json').version;
console.log(`Enact CLI: ${ver}`);
console.log(chalk.cyan('\tSymlinked from'), path.dirname(__dirname));
} else {
console.log(`@enact/cli: ${require('../package.json').version}`);
}
console.log(`Installed Globally: ${isGlobal}`);
if (isGlobal) console.log(`Global Modules: ${gm}`);
console.log();

// Display info on in-house components, likely to be linked in
console.log(chalk.yellow.bold('==Enact Components=='));
[
'@enact/dev-utils',
'eslint-config-enact',
'eslint-plugin-enact',
'postcss-resolution-independence'
].forEach(dep => logVersion(dep));
console.log();

// Display info on notable 3rd party components
console.log(chalk.yellow.bold('==Third Party Components=='));
console.log(`Babel: ${require('@babel/core/package.json').version}`);
console.log(`ESLint: ${require('eslint/package.json').version}`);
console.log(`Jest: ${require('jest/package.json').version}`);
console.log(`LESS: ${require('less/package.json').version}`);
console.log(`Webpack: ${require('webpack/package.json').version}`);
} else {
const app = require('@enact/dev-utils').optionParser;
const meta = require(path.join(app.context, 'package.json'));
const bl = require(resolveSync('browserslist', {
basedir: path.dirname(require.resolve('@enact/dev-utils/package.json')),
preserveSymlinks: false
}));
app.setEnactTargetsAsDefault();
console.log(chalk.yellow.bold('==Project Info=='));
console.log(`Name: ${app.name}`);
console.log(`Version: ${gitInfo(app.context) || meta.version}`);
console.log(`Path: ${app.context}`);
console.log(`Theme: ${(app.theme || {}).name}`);
if (app.proxer) console.log(`Serve Proxy: ${app.proxy}`);
if (app.template) console.log(`Template: ${app.template}`);
if (app.externalStartup) console.log(`External Startup: ${app.externalStartup}`);
if (app.deep) console.log(`Deep: ${app.deep}`);
if (app.forceCSSModules) console.log(`Force CSS Modules: ${app.forceCSSModules}`);
console.log(`Resolution Independence: ${JSON.stringify(app.ri)}`);
console.log(`Browserslist: ${bl.loadConfig({path: app.context})}`);
console.log(`Environment: ${app.environment}`);
console.log();
console.log(chalk.yellow.bold('==Dependencies=='));
if (meta.dependencies) {
Object.keys(meta.dependencies).forEach(dep => {
logVersion(dep, app.context);
});
}
if (dev && meta.devDependencies) {
console.log();
console.log(chalk.yellow.bold('==Dev Dependencies=='));
Object.keys(meta.devDependencies).forEach(dep => {
logVersion(dep, app.context);
});
}
}
resolve();
} catch (e) {
reject(e);
}
});
}

function cli(args) {
const opts = minimist(args, {
boolean: ['cli', 'help'],
alias: {h: 'help'}
});
if (opts.help) displayHelp();

api({cliInfo: opts.cli, dev: opts.dev}).catch(err => {
console.error(chalk.red('ERROR: ') + 'Failed to display info.\n' + err.message);
process.exit(1);
});
}

module.exports = {api, cli};
if (require.main === module) cli(process.argv.slice(2));
5 changes: 4 additions & 1 deletion commands/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ const minimist = require('minimist');
const packageRoot = require('@enact/dev-utils').packageRoot;

function displayHelp() {
let e = 'node ' + path.relative(process.cwd(), __filename);
if (require.main !== module) e = 'enact link';

console.log(' Usage');
console.log(' enact link [options]');
console.log(` ${e} [options]`);
console.log();
console.log(' Options');
console.log(' --verbose Verbose output logging');
Expand Down
12 changes: 7 additions & 5 deletions commands/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,13 @@ function watch(config) {

function api(opts = {}) {
if (opts.meta) {
let meta;
try {
meta = JSON.parse(opts.meta);
} catch (e) {
throw new Error('Invalid metadata; must be a valid JSON string.\n' + e.message);
let meta = opts.meta;
if (typeof meta === 'string') {
try {
meta = JSON.parse(opts.meta);
} catch (e) {
throw new Error('Invalid metadata; must be a valid JSON string.\n' + e.message);
}
}
app.applyEnactMeta(meta);
}
Expand Down
15 changes: 9 additions & 6 deletions commands/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,38 @@ const INCLUDED = path.dirname(require.resolve('@enact/template-moonstone'));
const DEFAULT_LINK = path.join(TEMPLATE_DIR, 'default');

function displayHelp() {
let e = 'node ' + path.relative(process.cwd(), __filename);
if (require.main !== module) e = 'enact template';

console.log(' Usage');
console.log(' enact template <action> ...');
console.log(` ${e} <action> ...`);
console.log();
console.log(' Actions');
console.log(' enact template install [source] [name]');
console.log(` ${e} install [source] [name]`);
console.log(chalk.dim(' Install a template from a local or remote source'));
console.log();
console.log(' source Git URI, npm package or local directory');
console.log(' (default: cwd)');
console.log(' name Specific name for the template');
console.log();
console.log(' enact template link [directory] [name]');
console.log(` ${e} link [directory] [name]`);
console.log(chalk.dim(' Symlink a directory into template management'));
console.log();
console.log(' directory Local directory path to link');
console.log(' (default: cwd)');
console.log(' name Specific name for the template');
console.log();
console.log(' enact template remove <name>');
console.log(` ${e} remove <name>`);
console.log(chalk.dim(' Remove a template by name'));
console.log();
console.log(' name Name of template to remove');
console.log();
console.log(' enact template default [name]');
console.log(` ${e} default [name]`);
console.log(chalk.dim(' Choose a default template for "enact create"'));
console.log();
console.log(' name Specific template to set default');
console.log();
console.log(' enact template list');
console.log(` ${e} list`);
console.log(chalk.dim(' List all templates installed/linked'));
console.log();
console.log(' Options');
Expand Down
5 changes: 4 additions & 1 deletion commands/transpile.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ const lessPlugins = [
];

function displayHelp() {
let e = 'node ' + path.relative(process.cwd(), __filename);
if (require.main !== module) e = 'enact transpile';

console.log(' Usage');
console.log(' enact transpile [options]');
console.log(` ${e} [options]`);
console.log();
console.log(' Options');
console.log(' -i, --ignore Pattern of filepaths to ignore');
Expand Down
Loading

0 comments on commit 08b2ddd

Please sign in to comment.