Skip to content
This repository was archived by the owner on Sep 4, 2020. It is now read-only.

Commit 33f3880

Browse files
author
clouless
committed
1.8.0 inject stories source code for demo
1 parent 9c523f2 commit 33f3880

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

build.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,25 @@ if (argv.watch) {
185185
// START OR BUILD DEMO PROJECT
186186
//
187187
if (argv.demo) {
188+
const injectStorySourceCodeAndCopyCode = () => {
189+
shell.echo(chalk.blue('>> reading demo story source files'));
190+
const files = fs.readdirSync(relativePath('./src/demo/stories/'));
191+
if (files !== undefined && files !== null && files.length > 0) {
192+
let storySource = '';
193+
for (let i = 0; i < files.length; i++) {
194+
const storyName = files[i];
195+
let fileContent = fs.readFileSync(relativePath('./src/demo/stories/' + storyName));
196+
fileContent = `${fileContent}`.replace(/`/g, '\\`');
197+
storySource = storySource + `
198+
case '${storyName}': { return \`${fileContent}\`; }
199+
`;
200+
}
201+
shell.cp('-r', `./src/*`, `./dist-demo/src/`);
202+
let storiesIndex = fs.readFileSync(relativePath('./src/demo/story-index.ts'));
203+
storiesIndex = `${storiesIndex}`.replace(/[/][*]___INJECT_SOURCE___[*][/]/, storySource);
204+
fs.writeFileSync(relativePath('./dist-demo/src/demo/story-index.ts'), storiesIndex);
205+
}
206+
};
188207
const packageJson = JSON.parse(shell.cat(relativePath('./package.json')).stdout);
189208
shell.echo(chalk.blue('>> creating dist-demo'));
190209
if (shell.test('-d', relativePath('./dist-demo'))) {
@@ -198,7 +217,7 @@ if (argv.demo) {
198217
if (shell.test('-d', relativePath('./_dist_demo_node_modules'))) {
199218
shell.mv(relativePath('_dist_demo_node_modules'), relativePath('./dist-demo/node_modules'));
200219
}
201-
shell.cp('-r', `./src/*`, `./dist-demo/src/`);
220+
injectStorySourceCodeAndCopyCode();
202221
shell.cd(relativePath('./dist-demo/'));
203222
if (argv.install) {
204223
shell.echo(chalk.blue('>> injecting package.json dependencies into dist-demo/package.json'));
@@ -215,7 +234,7 @@ if (argv.demo) {
215234
gaze.on('all', (event, filepath) => {
216235
try {
217236
shell.echo(chalk.blue(`>> ${filepath} has changed. copying it to ./dist-demo/src/`));
218-
shell.cp('-r', relativePath(`./src`) + '/*', relativePath(`./dist-demo/src/`));
237+
injectStorySourceCodeAndCopyCode();
219238
} catch (err) {
220239
console.log(err);
221240
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cloukit/library-build-chain",
3-
"version": "1.7.1",
3+
"version": "1.8.0",
44
"description": "Common code to build cloukit Angular Modules",
55
"author": "Bernhard Grünewaldt",
66
"license": "MIT",

0 commit comments

Comments
 (0)