forked from liriliri/chii
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
203 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules | ||
dist | ||
dist | ||
front_end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
semi: false, | ||
singleQuote: true, | ||
trailingComma: 'all', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |