Skip to content

Commit 58b7cde

Browse files
authored
Merge pull request #1004 from pattern-lab/feature/twig-edition-prep
twig edition prep
2 parents bd0d64e + 83c8e42 commit 58b7cde

File tree

12 files changed

+134
-38
lines changed

12 files changed

+134
-38
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ The below assumes a new directory and project is required. This is likely what y
3030
```bash
3131
mkdir new-project
3232
cd new-project
33-
npm init -y && npx @pattern-lab/cli -c patternlab init
33+
npx @pattern-lab/cli -c patternlab init
3434
```
3535
> If you get an error stating that `npx` is not installed, ensure you are on `npm 5.2.0` or later by running `npm -v` or install it globally with `npm install -g npx`. [Learn more about npx.](https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b)
3636
1. Follow the on-screen prompts to choose your Edition and a Starterkit should you want one.

packages/cli/bin/cli-actions/init.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22
const patternlab = require('@pattern-lab/core');
3+
const merge = require('deepmerge');
34
const ask = require('../ask');
45
const scaffold = require('../scaffold');
56
const installEdition = require('../install-edition');
@@ -50,14 +51,22 @@ const init = options =>
5051
patternlabConfig,
5152
projectDir
5253
); // 3.1
53-
patternlabConfig = Object.assign(patternlabConfig, newConf); // 3.2
54+
if (newConf) {
55+
patternlabConfig = merge(patternlabConfig, newConf); // 3.2
56+
}
5457
spinner.succeed(`⊙ patternlab → Installed edition: ${edition}`);
5558
}
5659
if (starterkit) {
5760
spinner.text = `⊙ patternlab → Installing starterkit ${starterkit}`;
5861
spinner.start();
59-
yield installStarterkit(starterkit, patternlabConfig);
62+
const starterkitConfig = yield installStarterkit(
63+
starterkit,
64+
patternlabConfig
65+
);
6066
spinner.succeed(`⊙ patternlab → Installed starterkit: ${starterkit}`);
67+
if (starterkitConfig) {
68+
patternlabConfig = merge(patternlabConfig, starterkitConfig);
69+
}
6170
} // 4
6271
yield writeJsonAsync(
6372
path.resolve(projectDir, 'patternlab-config.json'),

packages/cli/bin/inquiries/edition.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ const editionSetup = [
1414
name: 'edition',
1515
message: 'Which edition do you want to use (defaults to edition-node)?',
1616
choices: [
17+
{
18+
name: 'edition-twig (php engine)',
19+
value: '@pattern-lab/edition-twig',
20+
},
1721
{
1822
name: 'edition-node',
1923
value: '@pattern-lab/edition-node',

packages/cli/bin/inquiries/starterkit.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,26 @@ const starterkitSetup = [
2121
name: 'starterkit-mustache-foundation',
2222
value: 'starterkit-mustache-foundation',
2323
},
24-
{
25-
name: 'starterkit-twig-base',
26-
value: 'starterkit-twig-base',
27-
},
24+
// {
25+
// name: 'starterkit-twig-base',
26+
// value: 'starterkit-twig-base',
27+
// },
2828
{
2929
name: 'starterkit-twig-demo',
30-
value: 'starterkit-twig-demo',
30+
value: '@pattern-lab/starterkit-twig-demo',
3131
},
3232
{
3333
name: 'starterkit-mustache-materialdesign',
3434
value: 'starterkit-mustache-materialdesign',
3535
},
36-
{
37-
name: 'starterkit-twig-drupal-demo',
38-
value: 'starterkit-twig-drupal-demo',
39-
},
40-
{
41-
name: 'starterkit-twig-drupal-minimal',
42-
value: 'starterkit-twig-drupal-minimal',
43-
},
36+
// {
37+
// name: 'starterkit-twig-drupal-demo',
38+
// value: 'starterkit-twig-drupal-demo',
39+
// },
40+
// {
41+
// name: 'starterkit-twig-drupal-minimal',
42+
// value: 'starterkit-twig-drupal-minimal',
43+
// },
4444
{
4545
name: 'starterkit-mustache-webdesignday',
4646
value: 'starterkit-mustache-webdesignday',

packages/cli/bin/install-edition.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const path = require('path');
4+
const merge = require('deepmerge');
45
const EOL = require('os').EOL;
56
const {
67
checkAndInstallPackage,
@@ -21,6 +22,7 @@ const installEdition = (edition, config, projectDir) => {
2122
* 4. Do custom post-install procedures for different core editions:
2223
* 4.1 Copy gulpfile.js for edition-node-gulp
2324
* 4.2 Copy scripts for edition-node
25+
* 4.3 Copy items for edition-twig
2426
*/
2527
const sourceDir = config.paths.source.root;
2628
yield checkAndInstallPackage(edition); // 1
@@ -51,6 +53,29 @@ const installEdition = (edition, config, projectDir) => {
5153
);
5254
break;
5355
}
56+
// 4.3
57+
case '@pattern-lab/edition-twig': {
58+
const editionPath = path.resolve('./node_modules', edition);
59+
const editionConfigPath = path.resolve(
60+
editionPath,
61+
'patternlab-config.json'
62+
);
63+
const editionConfig = require(editionConfigPath);
64+
65+
pkg.scripts = Object.assign(
66+
{},
67+
pkg.scripts || {},
68+
yield getJSONKey(edition, 'scripts')
69+
);
70+
71+
yield copyAsync(
72+
path.resolve(editionPath, 'alter-twig.php'),
73+
path.resolve(sourceDir, '../', 'alter-twig.php')
74+
);
75+
76+
config = merge(config, editionConfig);
77+
break;
78+
}
5479
}
5580
yield writeJsonAsync(path.resolve(projectDir, 'package.json'), pkg, {
5681
spaces: 2,
Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
'use strict';
22
const path = require('path');
3-
const checkAndInstallPackage = require('./utils').checkAndInstallPackage;
4-
const copyAsync = require('./utils').copyAsync;
5-
const wrapAsync = require('./utils').wrapAsync;
3+
const fs = require('fs-extra');
4+
const {
5+
copyAsync,
6+
wrapAsync,
7+
checkAndInstallPackage,
8+
readJsonAsync,
9+
} = require('./utils');
610

711
const installStarterkit = (starterkit, config) =>
812
wrapAsync(function*() {
913
const sourceDir = config.paths.source.root;
1014
const name = starterkit.value || starterkit;
1115
const url = name.startsWith('@pattern-lab/') ? name : `pattern-lab/${name}`;
1216
yield checkAndInstallPackage(name, url);
13-
yield copyAsync(
14-
path.resolve('./node_modules', name, 'dist'),
15-
path.resolve(sourceDir)
16-
);
17-
return name;
17+
const kitPath = path.resolve('./node_modules', name);
18+
yield copyAsync(path.resolve(kitPath, 'dist'), path.resolve(sourceDir));
19+
let kitConfig;
20+
const kitConfigPath = path.resolve(kitPath, 'patternlab-config.json');
21+
if (fs.existsSync(kitConfigPath)) {
22+
kitConfig = yield readJsonAsync(kitConfigPath);
23+
}
24+
return kitConfig;
1825
});
1926

2027
module.exports = installStarterkit;

packages/cli/bin/scaffold.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22
const path = require('path');
3+
const execa = require('execa');
4+
const fs = require('fs');
35
const wrapAsync = require('./utils').wrapAsync;
46
const mkdirsAsync = require('./utils').mkdirsAsync;
57

@@ -14,6 +16,9 @@ const mkdirsAsync = require('./utils').mkdirsAsync;
1416
*/
1517
const scaffold = (projectDir, sourceDir, publicDir, exportDir) =>
1618
wrapAsync(function*() {
19+
if (!fs.existsSync(path.resolve(projectDir, 'package.json'))) {
20+
execa.sync('npm', ['init', '-y']);
21+
}
1722
/**
1823
* Create mandatory files structure
1924
* 1. Create project source directory

packages/cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"archiver": "2.1.1",
1515
"chalk": "2.4.1",
1616
"commander": "2.15.1",
17+
"deepmerge": "^2.1.1",
1718
"execa": "0.10.0",
1819
"fs-extra": "6.0.1",
1920
"glob": "7.1.2",

packages/create/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#! /usr/bin/env node
2+
const init = require('@pattern-lab/cli/bin/cli-actions/init');
3+
4+
init({});

packages/create/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "@pattern-lab/create",
3+
"version": "1.0.0",
4+
"description": "",
5+
"bin": "index.js",
6+
"scripts": {},
7+
"dependencies": {
8+
"@pattern-lab/cli": "0.0.2-alpha.0"
9+
},
10+
"author": "",
11+
"license": "MIT"
12+
}

0 commit comments

Comments
 (0)