Skip to content

Commit 7136c8c

Browse files
committed
refactor: update UIKit build to work in whatever PL folder the build script is called!
1 parent 01c6311 commit 7136c8c

File tree

10 files changed

+180
-103
lines changed

10 files changed

+180
-103
lines changed

packages/development-edition-engine-handlebars/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,19 @@ This Development Edition is a variant of [Edition Node](https://github.com/patte
1010
* Build and test against Handlebars pattern tree
1111

1212
> Development Editions of Pattern Lab provide the ability to work on and commit changes to select packages within the overall Pattern Lab [ecosystem](http://patternlab.io/docs/advanced-ecosystem-overview.html). This Edition is NOT stable.
13+
14+
15+
## Working on Pattern Lab's UI Locally
16+
17+
### Step 1: Install Dependencies
18+
Run the following in the root of the Pattern Lab repo:
19+
20+
```
21+
yarn run setup
22+
```
23+
24+
### Step 2 (Optional)
25+
If you want to build using a fuller set of examples than what comes with this default Handlebars demo, run `yarn run preview:hbs`. Otherwise skip to step 3.
26+
27+
### Step 3
28+
Finally, go back into this folder, `cd packages/development-edition-engine-handlebars`, and start up the local dev server which watches UIKit and the local Pattern Lab instance for changes, live reloads, etc by running `yarn dev`

packages/development-edition-engine-handlebars/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"pl:help": "patternlab --help",
99
"pl:install": "patternlab install --config ./patternlab-config.json",
1010
"pl:serve": "patternlab serve --config ./patternlab-config.json",
11-
"pl:version": "patternlab --version"
11+
"pl:version": "patternlab --version",
12+
"dev": "node ./node_modules/@pattern-lab/uikit-workshop/build-tools.js"
1213
},
1314
"keywords": [
1415
"Pattern Lab",

packages/edition-twig/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## Working on Pattern Lab's UI Locally
2+
3+
### Step 1: Install Dependencies
4+
Run the following in the root of the Pattern Lab repo:
5+
6+
```
7+
yarn run setup
8+
```
9+
10+
### Step 2
11+
Finally, go back into this folder, `cd packages/edition-twig`, and start up the local dev server which watches UIKit and the local Pattern Lab instance for changes, live reloads, etc by running `yarn dev`

packages/edition-twig/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"install": "patternlab install --config ./patternlab-config.json",
2020
"serve": "patternlab serve --config ./patternlab-config.json",
2121
"start": "npm run serve",
22-
"version": "patternlab --version"
22+
"version": "patternlab --version",
23+
"dev": "node ./node_modules/@pattern-lab/uikit-workshop/build-tools.js"
2324
},
2425
"dependencies": {
2526
"@pattern-lab/cli": "^5.3.0",

packages/uikit-workshop/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ yarn run setup
4242
If you want to build using a fuller set of examples than what comes with the default Handlebars demo, run `yarn run preview:hbs`. Otherwise skip to step 3.
4343

4444
### Step 3
45-
Finally go into the UIKit folder and start up the local dev server which watches UIKit and the Handlebars demo for changes, live reloads, etc.
45+
Finally, go into the `packages/development-edition-engine-handlebars` or `packages/edition-twig` folder and start up the local dev server which watches UIKit and the local Pattern Lab instance for changes, live reloads, etc by running `yarn dev`
4646

4747
```
48-
cd packages/uikit-workshop
49-
yarn start
48+
cd packages/development-edition-engine-handlebars
49+
yarn dev
5050
```
Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,7 @@
1-
const webpackServer = require('./build/webpack-server.js');
1+
const webpackServer = require('@pattern-lab/uikit-workshop/build/webpack-server.js');
22
const path = require('path');
3-
const fs = require('fs-extra');
4-
5-
fs.mkdirp('./node_modules/@pattern-lab/');
6-
// clear any previously generated dependency graph files if present
7-
if (fs.existsSync('./dependencyGraph.json')) {
8-
fs.unlinkSync('./dependencyGraph.json');
9-
}
10-
fs.ensureSymlink(__dirname, './node_modules/@pattern-lab/uikit-workshop');
11-
12-
const configKeysEndingWithASlash = [
13-
'root',
14-
'patterns',
15-
'data',
16-
'meta',
17-
'annotations',
18-
];
19-
20-
const configFilePath =
21-
'../development-edition-engine-handlebars/patternlab-config.json';
3+
const configFilePath = path.join(process.cwd(), './patternlab-config.json');
224
const config = require(configFilePath);
23-
24-
// adjust the config to output to a temp `www` folder locally for testing
25-
Object.keys(config.paths.source).forEach(key => {
26-
const value = config.paths.source[key];
27-
28-
if (typeof value === 'string' && value.includes('source')) {
29-
config.paths.source[key] = path.relative(
30-
__dirname,
31-
path.resolve(__dirname, path.dirname(configFilePath), value)
32-
);
33-
}
34-
35-
if (configKeysEndingWithASlash.includes(key)) {
36-
config.paths.source[key] = config.paths.source[key] + '/';
37-
}
38-
});
39-
40-
Object.keys(config.paths.public).forEach(key => {
41-
const value = config.paths.public[key];
42-
43-
if (typeof value === 'string' && value.includes('public')) {
44-
config.paths.public[key] = config.paths.public[key].replace(
45-
'public',
46-
'www'
47-
);
48-
}
49-
});
50-
515
const patternlab = require('@pattern-lab/core')(config);
526

537
// build + start watch mode
@@ -56,4 +10,7 @@ patternlab.build({
5610
cleanPublic: true,
5711
});
5812

59-
webpackServer.serve(patternlab);
13+
webpackServer.serve(
14+
patternlab,
15+
path.resolve(process.cwd(), config.paths.public.root)
16+
);

packages/uikit-workshop/build/webpack-server.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ const portfinder = require('portfinder');
1212

1313
const fileHashes = {};
1414

15-
// @todo: move these configs + make customizable?
16-
const buildDir = 'www';
17-
const root = path.resolve(__dirname, `../${buildDir}`);
18-
const preferredPort = 3000;
19-
portfinder.basePort = preferredPort;
15+
async function serve(patternlab, buildDir = 'public') {
16+
// @todo: move these configs + make customizable?
17+
const root = path.resolve(__dirname, `${buildDir}`);
18+
const preferredPort = 3000;
19+
portfinder.basePort = preferredPort;
2020

21-
async function serve(patternlab) {
2221
const webpackConfigs = await webpackConfig({
2322
watch: false,
2423
prod: false,
25-
buildDir: path.resolve(__dirname, `../${buildDir}`),
24+
buildDir: root,
25+
rootDir: process.cwd(),
2626
});
2727

2828
const port = await portfinder
@@ -47,7 +47,10 @@ async function serve(patternlab) {
4747
},
4848
// only reload the Webpack-generated HTML files when the contents have changed
4949
{
50-
match: [`${root}/*.html`, `${root}/styleguide/html/*.html`],
50+
match: [
51+
path.join(process.cwd(), `${root}/*.html`),
52+
path.join(process.cwd(), `${root}/styleguide/html/*.html`),
53+
],
5154
fn: async function(event, filePath) {
5255
let updatedHash = false;
5356

@@ -100,9 +103,9 @@ async function serve(patternlab) {
100103
app.use(
101104
webpackDevMiddleware(compiler, {
102105
quiet: true,
103-
stats: 'none',
106+
stats: 'errors-warnings',
104107
writeToDisk: true,
105-
logLevel: 'silent',
108+
logLevel: 'error',
106109
})
107110
);
108111

packages/uikit-workshop/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@
3535
"@pattern-lab/core": "^5.3.0",
3636
"@pattern-lab/engine-handlebars": "^5.0.0",
3737
"@pattern-lab/engine-mustache": "^5.0.0",
38-
"browser-sync": "^2.26.7",
3938
"better-opn": "^1.0.0",
39+
"browser-sync": "^2.26.7",
4040
"ejs": "^2.7.2",
4141
"express": "^4.17.1",
42-
"friendly-errors-webpack-plugin": "^1.7.0",
4342
"fs-extra": "^8.1.0",
4443
"hasha": "^5.1.0",
4544
"portfinder": "^1.0.25",
4645
"webpack-dev-middleware": "^3.7.2",
47-
"webpack-hot-middleware": "^2.25.0"
46+
"webpack-hot-middleware": "^2.25.0",
47+
"webpackbar": "^4.0.0"
4848
},
4949
"dependencies": {
5050
"@babel/core": "^7.6.4",

packages/uikit-workshop/webpack.config.js

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ const CopyPlugin = require('copy-webpack-plugin');
1313
const path = require('path');
1414
const argv = require('yargs').argv;
1515
const merge = require('webpack-merge');
16-
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
16+
const WebpackBar = require('webpackbar');
1717

1818
const cosmiconfig = require('cosmiconfig');
1919
const explorer = cosmiconfig('patternlab');
2020

2121
// @todo: wire these two ocnfigs up to use cosmicconfig!
2222
const defaultConfig = {
23+
rootDir: process.cwd(),
2324
buildDir: './dist',
2425
prod: argv.watch ? false : true, // or false for local dev
2526
sourceMaps: true,
@@ -129,9 +130,7 @@ module.exports = function(apiConfig) {
129130
];
130131

131132
const webpackConfig = {
132-
stats: {
133-
logging: 'none',
134-
},
133+
stats: 'errors-warnings',
135134
performance: {
136135
hints: false,
137136
},
@@ -143,7 +142,7 @@ module.exports = function(apiConfig) {
143142
},
144143
},
145144
output: {
146-
path: path.resolve(process.cwd(), `${config.buildDir}/styleguide`),
145+
path: path.resolve(config.rootDir, `${config.buildDir}/styleguide`),
147146
publicPath: `${config.publicPath}`,
148147
filename: '[name].js',
149148
chunkFilename: `js/[name]-chunk-[chunkhash].js`,
@@ -254,7 +253,7 @@ module.exports = function(apiConfig) {
254253
: [],
255254
},
256255
plugins: [
257-
new FriendlyErrorsWebpackPlugin(),
256+
new WebpackBar(),
258257
new CopyPlugin(config.copy),
259258
new NoEmitPlugin(['css/pattern-lab.js']),
260259
],
@@ -279,9 +278,15 @@ module.exports = function(apiConfig) {
279278

280279
const legacyConfig = merge(webpackConfig, {
281280
entry: {
282-
'js/patternlab-pattern': './src/scripts/patternlab-pattern.js',
283-
'js/patternlab-viewer': './src/scripts/patternlab-viewer.js',
284-
'css/pattern-lab': './src/sass/pattern-lab.scss',
281+
'js/patternlab-pattern': path.join(
282+
__dirname,
283+
'./src/scripts/patternlab-pattern.js'
284+
),
285+
'js/patternlab-viewer': path.join(
286+
__dirname,
287+
'./src/scripts/patternlab-viewer.js'
288+
),
289+
'css/pattern-lab': path.join(__dirname, './src/sass/pattern-lab.scss'),
285290
},
286291
module: {
287292
rules: [
@@ -309,9 +314,15 @@ module.exports = function(apiConfig) {
309314
mainFields: ['esnext', 'jsnext:main', 'browser', 'module', 'main'],
310315
},
311316
entry: {
312-
'js/patternlab-pattern': './src/scripts/patternlab-pattern.modern.js',
313-
'js/patternlab-viewer': './src/scripts/patternlab-viewer.modern.js',
314-
'css/pattern-lab': './src/sass/pattern-lab.scss',
317+
'js/patternlab-pattern': path.join(
318+
__dirname,
319+
'./src/scripts/patternlab-pattern.modern.js'
320+
),
321+
'js/patternlab-viewer': path.join(
322+
__dirname,
323+
'./src/scripts/patternlab-viewer.modern.js'
324+
),
325+
'css/pattern-lab': path.join(__dirname, './src/sass/pattern-lab.scss'),
315326
},
316327
output: {
317328
path: path.resolve(process.cwd(), `${config.buildDir}/styleguide`),
@@ -351,7 +362,7 @@ module.exports = function(apiConfig) {
351362
),
352363
new HtmlWebpackPlugin({
353364
filename: '../index.html',
354-
template: 'src/html/index.html',
365+
template: path.resolve(__dirname, 'src/html/index.html'),
355366
inject: false,
356367
}),
357368
new MiniCssExtractPlugin({

0 commit comments

Comments
 (0)