Skip to content
Merged

Dev #885

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/cli/bin/cli-actions/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ const init = options =>

if (edition) {
spinner.text = `⊙ patternlab → Installing edition: ${edition}`;
const newConf = yield installEdition(edition, patternlabConfig); // 3.1
const newConf = yield installEdition(
edition,
patternlabConfig,
projectDir
); // 3.1
patternlabConfig = Object.assign(patternlabConfig, newConf); // 3.2
spinner.succeed(`⊙ patternlab → Installed edition: ${edition}`);
}
Expand Down
45 changes: 29 additions & 16 deletions packages/cli/bin/install-edition.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,63 @@
'use strict';

const path = require('path');
const pkg = require(path.resolve(process.cwd(), 'package.json'));
const EOL = require('os').EOL;
const {
checkAndInstallPackage,
copyAsync,
wrapAsync,
writeJsonAsync,
getJSONKey,
} = require('./utils');

const installEdition = (edition, config) =>
wrapAsync(function*() {
const installEdition = (edition, config, projectDir) => {
const pkg = require(path.resolve(projectDir, 'package.json'));

return wrapAsync(function*() {
/**
* 1. Trigger edition install
* 2. Copy over the mandatory edition files to sourceDir
* 3. Do custom post-install procedures for different core editions:
* 3.1 Copy gulpfile.js for edition-node-gulp
* 3. Copy dependencies defined in edition
* 4. Do custom post-install procedures for different core editions:
* 4.1 Copy gulpfile.js for edition-node-gulp
* 4.2 Copy scripts for edition-node
*/
const sourceDir = config.paths.source.root;
yield checkAndInstallPackage(edition); // 1
yield copyAsync(
path.resolve('./node_modules', edition, 'source', '_meta'),
path.resolve(sourceDir, '_meta')
); // 2
switch (edition) { // 3
// 3.1
pkg.dependencies = Object.assign(
{},
pkg.dependencies || {},
yield getJSONKey(edition, 'dependencies')
); // 3
switch (edition) { // 4
// 4.1
case '@pattern-lab/edition-node-gulp': {
yield copyAsync(
path.resolve('./node_modules', edition, 'gulpfile.js'),
path.resolve(sourceDir, '../', 'gulpfile.js')
);
break;
}
// 4.2
case '@pattern-lab/edition-node': {
const scriptsJSON = {
'pl:build': 'patternlab build --config ./patternlab-config.json',
'pl:help': 'patternlab --help',
'pl:install': 'patternlab install --config ./patternlab-config.json',
'pl:serve': 'patternlab serve --config ./patternlab-config.json',
'pl:version': 'patternlab --version',
};
pkg.scripts = Object.assign({}, pkg.scripts || {}, scriptsJSON);
yield writeJsonAsync('./package.json', pkg, { spaces: 2 });
pkg.scripts = Object.assign(
{},
pkg.scripts || {},
yield getJSONKey(edition, 'scripts')
);
break;
}
}
yield writeJsonAsync(path.resolve(projectDir, 'package.json'), pkg, {
spaces: 2,
EOL: EOL,
});
return config;
});
};

module.exports = installEdition;
10 changes: 10 additions & 0 deletions packages/cli/bin/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@ const checkAndInstallPackage = (packageName, url) =>
*/
const noop = () => {};

const getJSONKey = (packageName, key, fileName = 'package.json') =>
wrapAsync(function*() {
yield checkAndInstallPackage(packageName);
const packageJSON = yield fs.readJson(
path.resolve('node_modules', packageName, fileName)
);
return packageJSON[key];
});

module.exports = {
copyWithPattern,
copyAsync: fs.copy,
Expand All @@ -189,4 +198,5 @@ module.exports = {
wrapAsync,
checkAndInstallPackage,
noop,
getJSONKey,
};
10 changes: 5 additions & 5 deletions packages/edition-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
"bugs": "https://github.com/pattern-lab/patternlab-node/issues",
"author": "Brian Muenzenmeyer",
"scripts": {
"build": "patternlab build --config ./patternlab-config.json",
"help": "patternlab --help",
"install": "patternlab install --config ./patternlab-config.json",
"serve": "patternlab serve --config ./patternlab-config.json",
"version": "patternlab --version"
"pl:build": "patternlab build --config ./patternlab-config.json",
"pl:help": "patternlab --help",
"pl:install": "patternlab install --config ./patternlab-config.json",
"pl:serve": "patternlab serve --config ./patternlab-config.json",
"pl:version": "patternlab --version"
},
"license": "MIT",
"engines": {
Expand Down