Skip to content

Commit

Permalink
feat: debug build script
Browse files Browse the repository at this point in the history
  • Loading branch information
surunzi committed Apr 14, 2020
1 parent 1b439bf commit f4b690e
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
dist
dist
front_end
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "Chrome devtools framework",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"format": "prettier src/*.{html,js,json} *.js --write",
"build:debug": "node scripts/build_debug"
},
"repository": {
"type": "git",
Expand All @@ -18,5 +19,10 @@
"bugs": {
"url": "https://github.com/liriliri/chi/issues"
},
"homepage": "https://github.com/liriliri/chi#readme"
"homepage": "https://github.com/liriliri/chi#readme",
"devDependencies": {
"licia": "^1.21.0",
"ncp": "^2.0.0",
"prettier": "^2.0.4"
}
}
5 changes: 5 additions & 0 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
semi: false,
singleQuote: true,
trailingComma: 'all',
}
150 changes: 150 additions & 0 deletions scripts/build_debug.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
const path = require('path')
const concat = require('licia/concat')
const rmdir = require('licia/rmdir')
const endWith = require('licia/endWith')
const ncp = require('ncp').ncp
const fs = {
...require('fs'),
...require('fs').promises
}

const pathFolders = [
path.resolve(__dirname, '../src'),
path.resolve(__dirname, '../devtools-frontend/front_end')
]

const outFolder = path.resolve(__dirname, '../front_end')

function lookupFile(fileName) {
for (const pathFolder of pathFolders) {
const absoluteFileName = path.join(pathFolder, fileName);
if (fs.existsSync(absoluteFileName))
return absoluteFileName
}
return ''
}

async function loadSource(fileName) {
return await fs.readFile(lookupFile(fileName), 'utf8')
}

async function loadAppDescriptor(appName) {
let descriptor = {
modules: []
}

while (true) {
const source = await loadSource(appName + '.json')
const content = JSON.parse(source)
if (content.modules) {
descriptor.modules = concat(descriptor.modules, content.modules)
}
if (content.extends) {
appName = content.extends
} else {
break
}
}

return descriptor
}

async function copyModule(name) {
const descriptor = JSON.parse(await loadSource(name + '/module.json'))
const outDir = path.join(outFolder, name)
let files = descriptor.modules || []
files.push('module.json')
files = concat(files, descriptor.resources || [])
for (let file of files) {
const srcPath = lookupFile(name + '/' + file)
const destPath = path.join(outDir, file)
await copyFile(srcPath, destPath)
}
}

async function copyFile(srcPath, destPath) {
await mkdir(path.dirname(destPath))
await fs.copyFile(srcPath, destPath)
}

async function copyApp(appName) {
const files = [
appName + '.js',
appName + '.html',
appName + '.json',
'root.js',
'shell.js',
'RuntimeInstantiator.js'
]

while (true) {
const descriptor = await loadSource(appName + '.json')
const content = JSON.parse(descriptor)
if (content.extends) {
appName = content.extends
files.push(appName + '.json')
} else {
break
}
}

for (let file of files) {
const srcPath = lookupFile(file)
const destPath = path.join(outFolder, file)
await copyFile(srcPath, destPath)
}
}

async function mkdir(dir) {
try {
await fs.stat(dir)
} catch (e) {
await fs.mkdir(dir, {
recursive: true
})
}
}

async function buildApp(appName) {
await copyApp(appName)
const descriptor = await loadAppDescriptor(appName)
const modules = descriptor.modules.map(module => module.name)
for (let module of modules) {
await copyModule(module)
}
}

function copyImages() {
const promises = pathFolders.map(pathFolder => {
return new Promise(async (resolve, reject) => {
const srcPath = path.join(pathFolder, 'Images')
const outPath = path.join(outFolder, 'Images')
await mkdir(outPath)
if (fs.existsSync(srcPath)) {
ncp(srcPath, outPath, {
filter(name) {
return !endWith(name, '.md') && !endWith(name, '.hashes')
}
}, err => {
if (err) return reject(err)
resolve()
})
} else {
resolve()
}
})
})

return Promise.all(promises)
}

async function buildApps(appNames) {
await copyImages()
for (let appName of appNames) {
await buildApp(appName)
}
}

rmdir(outFolder, async () => {
await buildApps(['empty_app'])
})
17 changes: 10 additions & 7 deletions src/empty_app.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<!doctype html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Security-Policy" content="object-src 'none'; script-src 'self' 'unsafe-eval' 'unsafe-inline' https://chrome-devtools-frontend.appspot.com">
<meta name="referrer" content="no-referrer">
<head>
<meta charset="utf-8" />
<meta
http-equiv="Content-Security-Policy"
content="object-src 'none'; script-src 'self' 'unsafe-eval' 'unsafe-inline' https://chrome-devtools-frontend.appspot.com"
/>
<meta name="referrer" content="no-referrer" />
<script type="module" src="root.js"></script>
<script type="module" src="empty_app.js"></script>
</head>
<body class="undocked" id="-blink-dev-tools"></body>
</head>
<body class="undocked" id="-blink-dev-tools"></body>
</html>
5 changes: 4 additions & 1 deletion src/empty_app.js
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
import './shell.js'
import './shell.js'
import { startApplication } from './RuntimeInstantiator.js'

startApplication('empty_app')
26 changes: 24 additions & 2 deletions src/empty_app.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
{

}
"modules": [
{ "name": "bindings", "type": "autostart" },
{ "name": "common", "type": "autostart" },
{ "name": "components", "type": "autostart" },
{ "name": "console_counters", "type": "autostart" },
{ "name": "dom_extension", "type": "autostart" },
{ "name": "extensions", "type": "autostart" },
{ "name": "host", "type": "autostart" },
{ "name": "main", "type": "autostart" },
{ "name": "persistence", "type": "autostart" },
{ "name": "platform", "type": "autostart" },
{ "name": "protocol_client", "type": "autostart" },
{ "name": "sdk", "type": "autostart" },
{ "name": "browser_sdk", "type": "autostart" },
{ "name": "root", "type": "autostart" },
{ "name": "services", "type": "autostart" },
{ "name": "text_utils", "type": "autostart" },
{ "name": "ui", "type": "autostart" },
{ "name": "workspace", "type": "autostart" },

{ "name": "settings" }
],
"has_html": true
}

0 comments on commit f4b690e

Please sign in to comment.