Skip to content

Commit 9bdc202

Browse files
author
Cam Tullos
committed
Fixed arcli install to ensure modules directory creation and published @atomic-reactor/cli@2.2.29
1 parent d73c205 commit 9bdc202

File tree

4 files changed

+83
-6
lines changed

4 files changed

+83
-6
lines changed

arcli.js

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const cmds = globs => {
4545
try {
4646
req = require(cmd);
4747
} catch (err) {
48+
console.log(err);
4849
req = () => {};
4950
}
5051

commands/package/install/actions.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ module.exports = spinner => {
5050
name = _.compact(String(name).split('@'))[0];
5151
name = String(params.name).substr(0, 1) === '@' ? `@${name}` : name;
5252

53+
// Ensure module dir
54+
fs.ensureDirSync(normalize(cwd, app + '_modules'));
55+
5356
const appID = op.get(props, 'config.registry.app', 'ReactiumRegistry');
5457
const serverURL = op.get(props, 'config.registry.server', 'https://v1.reactium.io/api');
5558

@@ -97,9 +100,6 @@ module.exports = spinner => {
97100
download: () => {
98101
message(`Downloading ${chalk.cyan(`${name}@${version}`)}...`);
99102

100-
// Set module dir
101-
dir = normalize(cwd, app + '_modules', slugify(name));
102-
103103
// Create tmp directory
104104
tmp = normalize(dir + '_tmp');
105105
fs.ensureDirSync(tmp);

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
22
"name": "@atomic-reactor/cli",
3-
"version": "2.2.27",
3+
"version": "2.2.29",
44
"description": "A CLI for creating Atomic Reactor Awesomeness",
55
"main": "arcli-node.js",
66
"scripts": {
77
"test": "run-s test:*",
88
"test:reactium-install": "mocha ./test/reactium-install.spec.js",
99
"test:config-set": "mocha ./test/config-set.spec.js",
1010
"test:reactium-update": "mocha ./test/reactium-update.spec.js",
11-
"test:project-init": "mocha ./test/project-init.spec.js"
11+
"test:project-init": "mocha ./test/project-init.spec.js",
12+
"prepublishOnly": "node ./prepublish.js"
1213
},
1314
"author": "Reactium LLC",
1415
"license": "MIT",
@@ -82,4 +83,4 @@
8283
"lib": "lib",
8384
"test": "test"
8485
}
85-
}
86+
}

prepublish.js

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
const path = require('path');
2+
const chalk = require('chalk');
3+
const fs = require('fs-extra');
4+
const semver = require('semver');
5+
const op = require('object-path');
6+
const pkg = require('./package');
7+
const inquirer = require('inquirer');
8+
9+
const utils = {
10+
normalize: (...args) => path.normalize(path.join(process.cwd(), ...args)),
11+
12+
prefix: chalk.magenta(' > '),
13+
14+
suffix: chalk.magenta(': '),
15+
16+
validate: (val, field) => {
17+
switch (field) {
18+
case 'version':
19+
return !semver.valid(semver.coerce(val))
20+
? `invalid version: ${chalk.magenta(val)}`
21+
: true;
22+
23+
default:
24+
return !val ? `${field} is required` : true;
25+
}
26+
},
27+
};
28+
29+
const env = op.get(process.env, 'NODE_ENV');
30+
31+
const versionUpdater = async () => {
32+
const { normalize, prefix, suffix, validate } = utils;
33+
34+
const type = 'input';
35+
const pkgFilePath = normalize('package.json');
36+
const defaultVer = semver.inc(pkg.version, 'patch');
37+
38+
console.log('');
39+
console.log(` Publishing ${chalk.magenta(pkg.name)}...`);
40+
console.log('');
41+
42+
// Input version number
43+
const { version } = await inquirer.prompt([
44+
{
45+
type,
46+
prefix,
47+
suffix,
48+
type: 'input',
49+
name: 'version',
50+
default: defaultVer,
51+
message: chalk.cyan('Version'),
52+
validate: val => validate(val, 'version'),
53+
filter: val => semver.valid(semver.coerce(val)) || defaultVer,
54+
},
55+
]);
56+
57+
// Write package.json
58+
if (env !== 'test') {
59+
await Promise.all([
60+
fs.writeFile(
61+
pkgFilePath,
62+
JSON.stringify({ ...pkg, version }, null, 2),
63+
),
64+
]);
65+
}
66+
67+
console.log('');
68+
69+
if (env === 'test') {
70+
console.log(JSON.stringify({ version }, null, 2));
71+
console.log('');
72+
}
73+
};
74+
75+
versionUpdater();

0 commit comments

Comments
 (0)