mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 05:50:11 +01:00
Move simpleserver script off of gulp
This commit is contained in:
parent
a06e20f8fe
commit
240b684846
34 changed files with 219 additions and 208 deletions
145
gulpfile.js
145
gulpfile.js
|
|
@ -4,13 +4,10 @@ const path = require('path');
|
|||
const fs = require('fs');
|
||||
const rimraf = require('rimraf');
|
||||
const cp = require('child_process');
|
||||
const yaserver = require('yaserver');
|
||||
const http = require('http');
|
||||
const CleanCSS = require('clean-css');
|
||||
const uncss = require('uncss');
|
||||
const File = require('vinyl');
|
||||
|
||||
const WEBSITE_GENERATED_PATH = path.join(__dirname, 'monaco-editor/website/playground/new-samples');
|
||||
/** @type {string} */
|
||||
const MONACO_EDITOR_VERSION = (function () {
|
||||
const packageJsonPath = path.join(__dirname, 'package.json');
|
||||
|
|
@ -254,145 +251,3 @@ gulp.task('prepare-website-branch', async function () {
|
|||
});
|
||||
console.log('RUN monaco-editor-website>git push origin gh-pages --force');
|
||||
});
|
||||
|
||||
const generateTestSamplesTask = function () {
|
||||
var sampleNames = fs.readdirSync(path.join(__dirname, 'monaco-editor/test/samples'));
|
||||
var samples = sampleNames.map(function (sampleName) {
|
||||
var samplePath = path.join(__dirname, 'monaco-editor/test/samples', sampleName);
|
||||
var sampleContent = fs.readFileSync(samplePath).toString();
|
||||
return {
|
||||
name: sampleName,
|
||||
content: sampleContent
|
||||
};
|
||||
});
|
||||
var prefix =
|
||||
'//This is a generated file via gulp generate-test-samples\ndefine([], function() { return';
|
||||
var suffix = '; });';
|
||||
fs.writeFileSync(
|
||||
path.join(__dirname, 'monaco-editor/test/samples-all.generated.js'),
|
||||
prefix + JSON.stringify(samples, null, '\t') + suffix
|
||||
);
|
||||
|
||||
var PLAY_SAMPLES = require(path.join(WEBSITE_GENERATED_PATH, 'all.js')).PLAY_SAMPLES;
|
||||
var locations = [];
|
||||
for (var i = 0; i < PLAY_SAMPLES.length; i++) {
|
||||
var sample = PLAY_SAMPLES[i];
|
||||
var sampleId = sample.id;
|
||||
var samplePath = path.join(WEBSITE_GENERATED_PATH, sample.path);
|
||||
|
||||
var html = fs.readFileSync(path.join(samplePath, 'sample.html'));
|
||||
var js = fs.readFileSync(path.join(samplePath, 'sample.js'));
|
||||
var css = fs.readFileSync(path.join(samplePath, 'sample.css'));
|
||||
|
||||
var result = [
|
||||
'<!DOCTYPE html>',
|
||||
'<!-- THIS IS A GENERATED FILE VIA gulp generate-test-samples -->',
|
||||
'<html>',
|
||||
'<head>',
|
||||
' <base href="..">',
|
||||
' <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />',
|
||||
'</head>',
|
||||
'<body>',
|
||||
'<style>',
|
||||
'/*----------------------------------------SAMPLE CSS START*/',
|
||||
'',
|
||||
css,
|
||||
'',
|
||||
'/*----------------------------------------SAMPLE CSS END*/',
|
||||
'</style>',
|
||||
'<a class="loading-opts" href="playground.generated/index.html">[<< BACK]</a> <br/>',
|
||||
'THIS IS A GENERATED FILE VIA gulp generate-test-samples',
|
||||
'',
|
||||
'<div id="bar" style="margin-bottom: 6px;"></div>',
|
||||
'',
|
||||
'<div style="clear:both"></div>',
|
||||
'<div id="outer-container" style="width:800px;height:450px;border: 1px solid grey">',
|
||||
'<!-- ----------------------------------------SAMPLE HTML START-->',
|
||||
'',
|
||||
html,
|
||||
'',
|
||||
'<!-- ----------------------------------------SAMPLE HTML END-->',
|
||||
'</div>',
|
||||
'<div style="clear:both"></div>',
|
||||
'',
|
||||
'<script src="../../metadata.js"></script>',
|
||||
'<script src="dev-setup.js"></script>',
|
||||
'<script>',
|
||||
'loadEditor(function() {',
|
||||
'/*----------------------------------------SAMPLE JS START*/',
|
||||
'',
|
||||
js,
|
||||
'',
|
||||
'/*----------------------------------------SAMPLE JS END*/',
|
||||
'});',
|
||||
'</script>',
|
||||
'</body>',
|
||||
'</html>'
|
||||
];
|
||||
fs.writeFileSync(
|
||||
path.join(__dirname, 'monaco-editor/test/playground.generated/' + sampleId + '.html'),
|
||||
result.join('\n')
|
||||
);
|
||||
locations.push({
|
||||
path: sampleId + '.html',
|
||||
name: sample.chapter + ' > ' + sample.name
|
||||
});
|
||||
}
|
||||
|
||||
var index = [
|
||||
'<!DOCTYPE html>',
|
||||
'<!-- THIS IS A GENERATED FILE VIA gulp generate-test-samples -->',
|
||||
'<html>',
|
||||
'<head>',
|
||||
' <base href="..">',
|
||||
'</head>',
|
||||
'<body>',
|
||||
'<a class="loading-opts" href="index.html">[<< BACK]</a><br/>',
|
||||
'THIS IS A GENERATED FILE VIA gulp generate-test-samples<br/><br/>',
|
||||
locations
|
||||
.map(function (location) {
|
||||
return (
|
||||
'<a class="loading-opts" href="playground.generated/' +
|
||||
location.path +
|
||||
'">' +
|
||||
location.name +
|
||||
'</a>'
|
||||
);
|
||||
})
|
||||
.join('<br/>\n'),
|
||||
'<script src="../../metadata.js"></script>',
|
||||
'<script src="dev-setup.js"></script>',
|
||||
'</body>',
|
||||
'</html>'
|
||||
];
|
||||
fs.writeFileSync(
|
||||
path.join(__dirname, 'monaco-editor/test/playground.generated/index.html'),
|
||||
index.join('\n')
|
||||
);
|
||||
};
|
||||
|
||||
function createSimpleServer(rootDir, port) {
|
||||
yaserver
|
||||
.createServer({
|
||||
rootDir: rootDir
|
||||
})
|
||||
.then((staticServer) => {
|
||||
const server = http.createServer((request, response) => {
|
||||
return staticServer.handle(request, response);
|
||||
});
|
||||
server.listen(port, '127.0.0.1', () => {
|
||||
console.log(`Running at http://127.0.0.1:${port}`);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
gulp.task('generate-test-samples', taskSeries(generateTestSamplesTask));
|
||||
|
||||
gulp.task(
|
||||
'simpleserver',
|
||||
taskSeries(generateTestSamplesTask, function () {
|
||||
const SERVER_ROOT = path.normalize(path.join(__dirname, '../'));
|
||||
createSimpleServer(SERVER_ROOT, 8080);
|
||||
createSimpleServer(SERVER_ROOT, 8088);
|
||||
})
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue