-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: wireup ssr.php and component.php
[-] wireup ssr.php and component.php [-] apply co-compile to debug scripts [-] apply co-compile to integration test
- Loading branch information
Showing
49 changed files
with
318 additions
and
1,159 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 |
---|---|---|
|
@@ -3,4 +3,5 @@ node_modules/ | |
npm-debug.log | ||
/test/e2e.spec.js | ||
coverage | ||
vendor/ | ||
vendor/ | ||
dist/ |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,15 +1,15 @@ | ||
#!/usr/bin/env node | ||
|
||
const { readFileSync } = require('fs') | ||
const { resolve, join } = require('path') | ||
const { read } = require('../test/data') | ||
|
||
const caseName = process.argv[2] | ||
const caseRoot = resolve(__dirname, '../test/cases') | ||
const caseDir = resolve(caseRoot, caseName) | ||
const jsSSRPath = join(caseDir, 'ssr.js') | ||
const dataPath = join(caseDir, 'data.json') | ||
|
||
const data = read(dataPath) | ||
const data = JSON.parse(readFileSync(dataPath, 'utf8')) | ||
const noDataOutput = /-ndo$/.test(caseDir) | ||
const jsRendered = require(jsSSRPath)(data, noDataOutput) | ||
process.stdout.write(jsRendered) |
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 was deleted.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,70 @@ | ||
import { exec } from './exec' | ||
import { ComponentParser } from '../transpilers/component-parser' | ||
import { readdirSync, writeFileSync, existsSync } from 'fs' | ||
import { resolve, join } from 'path' | ||
import { compileToSource as compileToJSSource } from '../js-ssr' | ||
import { compileToSource as compileToPHPSource } from '../php-ssr' | ||
import { Compiler as ToPHPCompiler } from '../transpilers/ts2php' | ||
import { Compiler as ToJSCompiler } from '../transpilers/ts2js' | ||
import camelCase from 'camelcase' | ||
|
||
const caseRoot = resolve(__dirname, '../../test/cases') | ||
const tsconfigPath = resolve(__dirname, '../../test/tsconfig.json') | ||
const cases = readdirSync(caseRoot) | ||
|
||
export function compileToJS (caseName) { | ||
const caseDir = join(caseRoot, caseName) | ||
const ts = join(caseDir, 'component.ts') | ||
const js = join(caseDir, 'component.js') | ||
const componentClass = existsSync(ts) ? require(ts).default : require(js) | ||
const fn = compileToJSSource(componentClass) | ||
writeFileSync(join(caseDir, 'ssr.js'), `module.exports = ${fn}`) | ||
} | ||
|
||
export function compileAllToJS () { | ||
for (const caseName of cases) compileToJS(caseName) | ||
} | ||
|
||
export function compileToPHP (caseName) { | ||
const caseDir = join(caseRoot, caseName) | ||
const ts = join(caseDir, 'component.ts') | ||
let componentClass | ||
let code = '' | ||
|
||
if (existsSync(ts)) { | ||
const ccp = new ToPHPCompiler({ | ||
tsconfigPath, | ||
nsPrefix: 'san\\components\\test\\' | ||
}) | ||
const component = new ComponentParser(ts, tsconfigPath).parseComponent() | ||
const ccj = new ToJSCompiler(tsconfigPath) | ||
componentClass = ccj.compileAndRun(component.get(ts))['default'] | ||
code += ccp.compileComponent(component) | ||
} else { | ||
const js = join(caseDir, 'component.js') | ||
componentClass = require(js) | ||
} | ||
|
||
const renderCode = compileToPHPSource( | ||
componentClass, | ||
{ funcName: 'render' } | ||
) | ||
|
||
code += | ||
`namespace san\\renderer\\${camelCase(caseName)} {\n` + | ||
` ${renderCode}` + | ||
`}\n` | ||
writeFileSync(join(caseDir, 'ssr.php'), `<?php ${code} ?>`) | ||
} | ||
|
||
export function compileAllToPHP () { | ||
for (const caseName of cases) compileToPHP(caseName) | ||
} | ||
|
||
export function renderByJS (caseName) { | ||
return exec(resolve(__dirname, `../../bin/render.js`), [caseName]) | ||
} | ||
|
||
export function renderByPHP (caseName) { | ||
return exec(resolve(__dirname, `../../bin/render.php`), [caseName]) | ||
} |
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 @@ | ||
import { compileAllToJS, compileToJS } from './case' | ||
|
||
const caseName = process.argv[2] | ||
if (caseName === '--all') compileAllToJS() | ||
else compileToJS(caseName) |
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,6 @@ | ||
import { compileToPHP, compileAllToPHP } from './case' | ||
|
||
const caseName = process.argv[2] | ||
|
||
if (caseName === '--all') compileAllToPHP() | ||
else compileToPHP(caseName) |
File renamed without changes.
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,23 @@ | ||
import chalk from 'chalk' | ||
import { readFileSync } from 'fs' | ||
import { resolve } from 'path' | ||
import { renderByJS, compileToJS } from './case' | ||
import { measure, startMeasure } from '../utils/timing' | ||
|
||
const caseName = process.argv[2] | ||
const htmlPath = resolve(__dirname, '../test/cases', caseName, 'result.html') | ||
const expected = readFileSync(htmlPath, 'utf8') | ||
|
||
console.log(chalk.green('[COMP JS]'), measure(() => compileToJS(caseName))) | ||
|
||
check(`[EXPECTED] ${caseName}`, () => expected) | ||
check(`[SSR JS] ${caseName}`, () => renderByJS(caseName)) | ||
|
||
function check (title, render) { | ||
const renderJSMeasure = startMeasure() | ||
const html = render() | ||
const color = html === expected ? 'green' : 'red' | ||
console.log(chalk[color](title), renderJSMeasure.duration()) | ||
console.log(html + '\n') | ||
if (html !== expected) process.exit(1) | ||
} |
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,23 @@ | ||
import chalk from 'chalk' | ||
import { readFileSync } from 'fs' | ||
import { resolve } from 'path' | ||
import { renderByPHP, compileToPHP } from './case' | ||
import { measure, startMeasure } from '../utils/timing' | ||
|
||
const caseName = process.argv[2] | ||
const htmlPath = resolve(__dirname, '../test/cases', caseName, 'result.html') | ||
const expected = readFileSync(htmlPath, 'utf8') | ||
|
||
console.log(chalk.green('[COMP PHP]'), measure(() => compileToPHP(caseName))) | ||
|
||
check(`[EXPECTED] ${caseName}`, () => expected) | ||
check(`[SSR PHP] ${caseName}`, () => renderByPHP(caseName)) | ||
|
||
function check (title, render) { | ||
const renderJSMeasure = startMeasure() | ||
const html = render() | ||
const color = html === expected ? 'green' : 'red' | ||
console.log(chalk[color](title), renderJSMeasure.duration()) | ||
console.log(html + '\n') | ||
if (html !== expected) process.exit(1) | ||
} |
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
Oops, something went wrong.