-
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: first php rendered case - update-cmpt-merge-data
- Loading branch information
Showing
19 changed files
with
8,354 additions
and
1,623 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 +1 @@ | ||
{"php":"7.3.8","version":"2.15.1:v2.15.1#20064511ab796593a3990669eff5f5b535001f7c","indent":" ","lineEnding":"\n","rules":{"blank_line_after_namespace":true,"braces":true,"class_definition":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_constants":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline"},"no_break_comment":true,"no_closing_tag":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":true,"encoding":true,"full_opening_tag":true},"hashes":{"\/tmp\/vW6aolH\/2\/precode.php":1055820987,"\/tmp\/vW6aolH\/5\/precode.php":1055820987,"\/tmp\/vW6aolH\/10\/precode.php":1055820987,"\/tmp\/v8lP4Pr\/19\/precode.php":3830120851,"\/tmp\/vglPZER\/1202\/San.php":1939724901}} | ||
{"php":"7.3.8","version":"2.15.1:v2.15.1#20064511ab796593a3990669eff5f5b535001f7c","indent":" ","lineEnding":"\n","rules":{"blank_line_after_namespace":true,"braces":true,"class_definition":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_constants":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline"},"no_break_comment":true,"no_closing_tag":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":true,"encoding":true,"full_opening_tag":true},"hashes":{"\/tmp\/vW6aolH\/2\/precode.php":1055820987,"\/tmp\/vW6aolH\/5\/precode.php":1055820987,"\/tmp\/vW6aolH\/10\/precode.php":1055820987,"\/tmp\/v8lP4Pr\/19\/precode.php":3830120851,"\/tmp\/vglPZER\/1202\/San.php":1939724901,"\/tmp\/v2hKxnm\/74\/ssr.php":2976412624}} |
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
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 |
---|---|---|
@@ -1,30 +1,15 @@ | ||
#!/usr/bin/env node | ||
|
||
const { readFileSync } = require('fs') | ||
const { resolve, join } = require('path') | ||
const caseRoot = resolve(__dirname, '../test/cases') | ||
const { read } = require('../src/data') | ||
|
||
const caseName = process.argv[2] | ||
console.log(caseName) | ||
|
||
const caseDir = join(caseRoot, caseName) | ||
const caseRoot = resolve(__dirname, '../test/cases') | ||
const caseDir = resolve(caseRoot, caseName) | ||
const jsSSRPath = join(caseDir, 'ssr.js') | ||
const dataPath = join(caseDir, 'data.json') | ||
const htmlPath = join(caseDir, 'result.html') | ||
const ssrPath = join(caseDir, 'ssr.js') | ||
|
||
const expected = readFileSync(htmlPath, 'utf8') | ||
console.log('-----------expected--------------') | ||
console.log(expected) | ||
console.log() | ||
|
||
const data = read(dataPath) | ||
const noDataOutput = /-ndo$/.test(caseDir) | ||
const jsRendered = require(ssrPath)(data, noDataOutput) | ||
console.log('------------js-ssr---------------', result(jsRendered)) | ||
console.log(jsRendered) | ||
console.log() | ||
|
||
function result (html) { | ||
return html === expected ? 'PASS' : 'FAIL' | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
include('src/San.php'); | ||
|
||
$caseName = $argv[1]; | ||
$caseDir = "test/cases/" . $caseName; | ||
include($caseDir . '/ssr.php'); | ||
|
||
$dataStr = file_get_contents($caseDir . "/data.json"); | ||
$data = json_decode($dataStr, true); | ||
$noDataOutput = preg_match('/-ndo$/', $caseName); | ||
|
||
echo $render($data, $noDataOutput); |
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,58 @@ | ||
#!/usr/bin/env node | ||
|
||
const chalk = require('chalk') | ||
const { spawnSync } = require('child_process') | ||
const { readFileSync, writeFileSync } = require('fs') | ||
const compileToJSSource = require('../src/js-ssr').compileToSource | ||
const compileToPHPSource = require('../src/php-ssr').compileToSource | ||
const { resolve, join } = require('path') | ||
const caseRoot = resolve(__dirname, '../test/cases') | ||
|
||
const caseName = process.argv[2] | ||
const caseDir = join(caseRoot, caseName) | ||
const htmlPath = join(caseDir, 'result.html') | ||
const jsSSRPath = join(caseDir, 'ssr.js') | ||
const phpSSRPath = join(caseDir, 'ssr.php') | ||
const compPath = join(caseDir, 'component.js') | ||
|
||
// generate js ssr | ||
const ComponentClass = require(compPath) | ||
const fn = compileToJSSource(ComponentClass) | ||
writeFileSync(jsSSRPath, `module.exports = ${fn}`) | ||
|
||
// generate php ssr | ||
delete require.cache[require.resolve(compPath)] | ||
const ComponentClassForPHP = require(compPath) | ||
const php = compileToPHPSource(ComponentClassForPHP) | ||
writeFileSync(phpSSRPath, `<?php $render = ${php}; ?>`) | ||
|
||
// check | ||
const expected = readFileSync(htmlPath, 'utf8') | ||
console.log(chalk.green('[EXPECTED]')) | ||
console.log(expected) | ||
console.log() | ||
|
||
check(`[SSR: JS] ${jsSSRPath}`, render(caseName, 'js')) | ||
check(`[SSR: PHP] ${phpSSRPath}`, render(caseName, 'php')) | ||
|
||
function check (title, html) { | ||
const color = html === expected ? 'green' : 'red' | ||
console.log(chalk[color](title)) | ||
console.log(html) | ||
console.log() | ||
if (html !== expected) process.exit(1) | ||
} | ||
|
||
function render (caseName, target) { | ||
const bin = resolve(__dirname, `./render.${target}`) | ||
const proc = spawnSync(bin, [caseName]) | ||
if (proc.error || proc.stderr.length) { | ||
if (proc.error) console.error(proc.error) | ||
else { | ||
console.log('STDOUT:', proc.stdout.toString()) | ||
console.error('STDERR:', proc.stderr.toString()) | ||
} | ||
process.exit(1) | ||
} | ||
return proc.stdout.toString() | ||
} |
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
Empty file.
Oops, something went wrong.