-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost-build.mjs
36 lines (30 loc) · 1.43 KB
/
post-build.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import fs from 'fs';
import { readdirSync } from 'fs';
const builds = JSON.parse(fs.readFileSync("polymer.json").toString()).builds
, buildNames = readdirSync('./build').filter( b=> b!=="polymer.json");
buildNames.map( build=>
{ let stubName = `./build/${build}/index.html`
, stub = fs.readFileSync(stubName).toString()
, basePath = builds.find( b=> b.name == build ).basePath;
stub = stub.substring( stub.indexOf("<script>") )
.replace( /(\<html\>|\<head\>|\<\/head\>|\<body\>|\<\/body\>|\<\/html\>)/g ,"")
.replace( /src\=\"node_modules/g ,`src="${basePath}/node_modules`)
.replace( /src\=\"src/g ,`src="${basePath}/src`)
.replace( /define\(\w*\[\w*\'src/g ,`define(['${basePath}/src`)
.replace( /.indexOf\(\"\:\/\/\"\)/ ,`.indexOf("://")&&b.indexOf("/")`) // define( absUrl ) bug fix
;
fs.writeFileSync( stubName, stub );
});
// prefix demo/* with build/*/index.html
readdirSync(`./demo`)
.filter( name => name.endsWith('.html') )
.map( name =>
{ const txt = fs.readFileSync(`./demo/${name}`).toString();
buildNames.map( build=>
{ let fName = `./build/${build}/demo/${name}`
, stubName = `./build/${build}/index.html`
, stub = fs.readFileSync(stubName).toString();
fs.writeFileSync( fName, "<!DOCTYPE html>"+stub + txt );
})
});
fs.copyFileSync('package-lock.json', 'build/package-lock.json');