gulpfile.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  1. const gulp = require('gulp');
  2. const metadata = require('./metadata');
  3. const es = require('event-stream');
  4. const path = require('path');
  5. const fs = require('fs');
  6. const rimraf = require('rimraf');
  7. const cp = require('child_process');
  8. const httpServer = require('http-server');
  9. const typedoc = require("gulp-typedoc");
  10. const CleanCSS = require('clean-css');
  11. const uncss = require('uncss');
  12. const File = require('vinyl');
  13. const ts = require('typescript');
  14. const WEBSITE_GENERATED_PATH = path.join(__dirname, 'website/playground/new-samples');
  15. const MONACO_EDITOR_VERSION = (function() {
  16. const packageJsonPath = path.join(__dirname, 'package.json');
  17. const packageJson = JSON.parse(fs.readFileSync(packageJsonPath).toString());
  18. const version = packageJson.version;
  19. if (!/\d+\.\d+\.\d+/.test(version)) {
  20. console.log('unrecognized package.json version: ' + version);
  21. process.exit(0);
  22. }
  23. return version;
  24. })();
  25. gulp.task('clean-release', function(cb) { rimraf('release', { maxBusyTries: 1 }, cb); });
  26. gulp.task('release', ['clean-release'], function() {
  27. return es.merge(
  28. // dev folder
  29. releaseOne('dev'),
  30. // min folder
  31. releaseOne('min'),
  32. // esm folder
  33. ESM_release(),
  34. // package.json
  35. gulp.src('package.json')
  36. .pipe(es.through(function(data) {
  37. var json = JSON.parse(data.contents.toString());
  38. json.private = false;
  39. data.contents = new Buffer(JSON.stringify(json, null, ' '));
  40. this.emit('data', data);
  41. }))
  42. .pipe(gulp.dest('release')),
  43. gulp.src('CHANGELOG.md')
  44. .pipe(gulp.dest('release')),
  45. // min-maps folder
  46. gulp.src('node_modules/monaco-editor-core/min-maps/**/*').pipe(gulp.dest('release/min-maps')),
  47. // webpack plugin
  48. gulp.src('webpack/**/*').pipe(gulp.dest('release/webpack')),
  49. // other files
  50. gulp.src([
  51. 'node_modules/monaco-editor-core/LICENSE',
  52. 'node_modules/monaco-editor-core/monaco.d.ts',
  53. 'node_modules/monaco-editor-core/ThirdPartyNotices.txt',
  54. 'README.md'
  55. ])
  56. .pipe(addPluginDTS())
  57. .pipe(addPluginThirdPartyNotices())
  58. .pipe(gulp.dest('release'))
  59. )
  60. });
  61. /**
  62. * Release to `dev` or `min`.
  63. */
  64. function releaseOne(type) {
  65. return es.merge(
  66. gulp.src('node_modules/monaco-editor-core/' + type + '/**/*')
  67. .pipe(addPluginContribs(type))
  68. .pipe(gulp.dest('release/' + type)),
  69. pluginStreams(type, 'release/' + type + '/')
  70. )
  71. }
  72. /**
  73. * Release plugins to `dev` or `min`.
  74. */
  75. function pluginStreams(type, destinationPath) {
  76. return es.merge(
  77. metadata.METADATA.PLUGINS.map(function(plugin) {
  78. return pluginStream(plugin, type, destinationPath);
  79. })
  80. );
  81. }
  82. /**
  83. * Release a plugin to `dev` or `min`.
  84. */
  85. function pluginStream(plugin, type, destinationPath) {
  86. var pluginPath = plugin.paths[`npm/${type}`]; // npm/dev or npm/min
  87. var contribPath = path.join(pluginPath, plugin.contrib.substr(plugin.modulePrefix.length)) + '.js';
  88. return (
  89. gulp.src([
  90. pluginPath + '/**/*',
  91. '!' + contribPath
  92. ])
  93. .pipe(es.through(function(data) {
  94. if (!/_\.contribution/.test(data.path)) {
  95. this.emit('data', data);
  96. return;
  97. }
  98. let contents = data.contents.toString();
  99. contents = contents.replace('define(["require", "exports"],', 'define(["require", "exports", "vs/editor/editor.api"],');
  100. data.contents = new Buffer(contents);
  101. this.emit('data', data);
  102. }))
  103. .pipe(gulp.dest(destinationPath + plugin.modulePrefix))
  104. );
  105. }
  106. /**
  107. * Edit editor.main.js:
  108. * - rename the AMD module 'vs/editor/editor.main' to 'vs/editor/edcore.main'
  109. * - append monaco.contribution modules from plugins
  110. * - append new AMD module 'vs/editor/editor.main' that stiches things together
  111. */
  112. function addPluginContribs(type) {
  113. return es.through(function(data) {
  114. if (!/editor\.main\.js$/.test(data.path)) {
  115. this.emit('data', data);
  116. return;
  117. }
  118. var contents = data.contents.toString();
  119. // Rename the AMD module 'vs/editor/editor.main' to 'vs/editor/edcore.main'
  120. contents = contents.replace(/"vs\/editor\/editor\.main\"/, '"vs/editor/edcore.main"');
  121. var extraContent = [];
  122. var allPluginsModuleIds = [];
  123. metadata.METADATA.PLUGINS.forEach(function(plugin) {
  124. allPluginsModuleIds.push(plugin.contrib);
  125. var pluginPath = plugin.paths[`npm/${type}`]; // npm/dev or npm/min
  126. var contribPath = path.join(__dirname, pluginPath, plugin.contrib.substr(plugin.modulePrefix.length)) + '.js';
  127. var contribContents = fs.readFileSync(contribPath).toString();
  128. // Check for the anonymous define call case 1
  129. // transform define(function() {...}) to define("moduleId",["require"],function() {...})
  130. var anonymousContribDefineCase1 = contribContents.indexOf('define(function');
  131. if (anonymousContribDefineCase1 >= 0) {
  132. contribContents = (
  133. contribContents.substring(0, anonymousContribDefineCase1)
  134. + `define("${plugin.contrib}",["require"],function`
  135. + contribContents.substring(anonymousContribDefineCase1 + 'define(function'.length)
  136. );
  137. }
  138. // Check for the anonymous define call case 2
  139. // transform define([ to define("moduleId",[
  140. var anonymousContribDefineCase2 = contribContents.indexOf('define([');
  141. if (anonymousContribDefineCase2 >= 0) {
  142. contribContents = (
  143. contribContents.substring(0, anonymousContribDefineCase2)
  144. + `define("${plugin.contrib}",[`
  145. + contribContents.substring(anonymousContribDefineCase2 + 'define(['.length)
  146. );
  147. }
  148. var contribDefineIndex = contribContents.indexOf('define("' + plugin.contrib);
  149. if (contribDefineIndex === -1) {
  150. contribDefineIndex = contribContents.indexOf('define(\'' + plugin.contrib);
  151. if (contribDefineIndex === -1) {
  152. console.error('(1) CANNOT DETERMINE AMD define location for contribution', pluginPath);
  153. process.exit(-1);
  154. }
  155. }
  156. var depsEndIndex = contribContents.indexOf(']', contribDefineIndex);
  157. if (contribDefineIndex === -1) {
  158. console.error('(2) CANNOT DETERMINE AMD define location for contribution', pluginPath);
  159. process.exit(-1);
  160. }
  161. contribContents = contribContents.substring(0, depsEndIndex) + ',"vs/editor/editor.api"' + contribContents.substring(depsEndIndex);
  162. contribContents = contribContents.replace(
  163. 'define("vs/basic-languages/_.contribution",["require","exports"],',
  164. 'define("vs/basic-languages/_.contribution",["require","exports","vs/editor/editor.api"],',
  165. );
  166. extraContent.push(contribContents);
  167. });
  168. extraContent.push(`define("vs/editor/editor.main", ["vs/editor/edcore.main","${allPluginsModuleIds.join('","')}"], function() {});`);
  169. var insertIndex = contents.lastIndexOf('//# sourceMappingURL=');
  170. if (insertIndex === -1) {
  171. insertIndex = contents.length;
  172. }
  173. contents = contents.substring(0, insertIndex) + '\n' + extraContent.join('\n') + '\n' + contents.substring(insertIndex);
  174. data.contents = new Buffer(contents);
  175. this.emit('data', data);
  176. });
  177. }
  178. function ESM_release() {
  179. return es.merge(
  180. gulp.src('node_modules/monaco-editor-core/esm/**/*')
  181. .pipe(ESM_addImportSuffix())
  182. .pipe(ESM_addPluginContribs('release/esm'))
  183. .pipe(gulp.dest('release/esm')),
  184. ESM_pluginStreams('release/esm/')
  185. )
  186. }
  187. /**
  188. * Release plugins to `esm`.
  189. */
  190. function ESM_pluginStreams(destinationPath) {
  191. return es.merge(
  192. metadata.METADATA.PLUGINS.map(function(plugin) {
  193. return ESM_pluginStream(plugin, destinationPath);
  194. })
  195. );
  196. }
  197. /**
  198. * Release a plugin to `esm`.
  199. * Adds a dependency to 'vs/editor/editor.api' in contrib files in order for `monaco` to be defined.
  200. * Rewrites imports for 'monaco-editor-core/**'
  201. */
  202. function ESM_pluginStream(plugin, destinationPath) {
  203. const DESTINATION = path.join(__dirname, destinationPath);
  204. let pluginPath = plugin.paths[`esm`];
  205. return (
  206. gulp.src([
  207. pluginPath + '/**/*'
  208. ])
  209. .pipe(es.through(function(data) {
  210. if (!/\.js$/.test(data.path)) {
  211. this.emit('data', data);
  212. return;
  213. }
  214. let contents = data.contents.toString();
  215. const info = ts.preProcessFile(contents);
  216. for (let i = info.importedFiles.length - 1; i >= 0; i--) {
  217. const importText = info.importedFiles[i].fileName;
  218. const pos = info.importedFiles[i].pos;
  219. const end = info.importedFiles[i].end;
  220. if (!/(^\.\/)|(^\.\.\/)/.test(importText)) {
  221. // non-relative import
  222. if (!/^monaco-editor-core/.test(importText)) {
  223. console.error(`Non-relative import for unknown module: ${importText} in ${data.path}`);
  224. process.exit(0);
  225. }
  226. const myFileDestPath = path.join(DESTINATION, plugin.modulePrefix, data.relative);
  227. const importFilePath = path.join(DESTINATION, importText.substr('monaco-editor-core/esm/'.length));
  228. let relativePath = path.relative(path.dirname(myFileDestPath), importFilePath);
  229. if (!/(^\.\/)|(^\.\.\/)/.test(relativePath)) {
  230. relativePath = './' + relativePath;
  231. }
  232. contents = (
  233. contents.substring(0, pos + 1)
  234. + relativePath
  235. + contents.substring(end + 1)
  236. );
  237. }
  238. }
  239. data.contents = new Buffer(contents);
  240. this.emit('data', data);
  241. }))
  242. .pipe(es.through(function(data) {
  243. if (!/monaco\.contribution\.js$/.test(data.path)) {
  244. this.emit('data', data);
  245. return;
  246. }
  247. const myFileDestPath = path.join(DESTINATION, plugin.modulePrefix, data.relative);
  248. const apiFilePath = path.join(DESTINATION, 'vs/editor/editor.api');
  249. let relativePath = path.relative(path.dirname(myFileDestPath), apiFilePath);
  250. if (!/(^\.\/)|(^\.\.\/)/.test(relativePath)) {
  251. relativePath = './' + relativePath;
  252. }
  253. let contents = data.contents.toString();
  254. contents = (
  255. `import '${relativePath}';\n` +
  256. contents
  257. );
  258. data.contents = new Buffer(contents);
  259. this.emit('data', data);
  260. }))
  261. .pipe(ESM_addImportSuffix())
  262. .pipe(gulp.dest(destinationPath + plugin.modulePrefix))
  263. );
  264. }
  265. function ESM_addImportSuffix() {
  266. return es.through(function(data) {
  267. if (!/\.js$/.test(data.path)) {
  268. this.emit('data', data);
  269. return;
  270. }
  271. let contents = data.contents.toString();
  272. const info = ts.preProcessFile(contents);
  273. for (let i = info.importedFiles.length - 1; i >= 0; i--) {
  274. const importText = info.importedFiles[i].fileName;
  275. const pos = info.importedFiles[i].pos;
  276. const end = info.importedFiles[i].end;
  277. if (/\.css$/.test(importText)) {
  278. continue;
  279. }
  280. contents = (
  281. contents.substring(0, pos + 1)
  282. + importText + '.js'
  283. + contents.substring(end + 1)
  284. );
  285. }
  286. data.contents = new Buffer(contents);
  287. this.emit('data', data);
  288. });
  289. }
  290. /**
  291. * - Rename esm/vs/editor/editor.main.js to esm/vs/editor/edcore.main.js
  292. * - Create esm/vs/editor/editor.main.js that that stiches things together
  293. */
  294. function ESM_addPluginContribs(dest) {
  295. const DESTINATION = path.join(__dirname, dest);
  296. return es.through(function(data) {
  297. if (!/editor\.main\.js$/.test(data.path)) {
  298. this.emit('data', data);
  299. return;
  300. }
  301. this.emit('data', new File({
  302. path: data.path.replace(/editor\.main/, 'edcore.main'),
  303. base: data.base,
  304. contents: data.contents
  305. }));
  306. const mainFileDestPath = path.join(DESTINATION, 'vs/editor/editor.main.js');
  307. let mainFileImports = [];
  308. metadata.METADATA.PLUGINS.forEach(function(plugin) {
  309. const contribDestPath = path.join(DESTINATION, plugin.contrib);
  310. let relativePath = path.relative(path.dirname(mainFileDestPath), contribDestPath);
  311. if (!/(^\.\/)|(^\.\.\/)/.test(relativePath)) {
  312. relativePath = './' + relativePath;
  313. }
  314. mainFileImports.push(relativePath);
  315. });
  316. let mainFileContents = (
  317. mainFileImports.map((name) => `import '${name}';`).join('\n')
  318. + `\n\nexport * from './edcore.main';`
  319. );
  320. this.emit('data', new File({
  321. path: data.path,
  322. base: data.base,
  323. contents: new Buffer(mainFileContents)
  324. }));
  325. });
  326. }
  327. /**
  328. * Edit monaco.d.ts:
  329. * - append monaco.d.ts from plugins
  330. */
  331. function addPluginDTS() {
  332. return es.through(function(data) {
  333. if (!/monaco\.d\.ts$/.test(data.path)) {
  334. this.emit('data', data);
  335. return;
  336. }
  337. var contents = data.contents.toString();
  338. var extraContent = [];
  339. metadata.METADATA.PLUGINS.forEach(function(plugin) {
  340. var pluginPath = plugin.paths[`npm/min`]; // npm/dev or npm/min
  341. var dtsPath = path.join(pluginPath, '../monaco.d.ts');
  342. try {
  343. let plugindts = fs.readFileSync(dtsPath).toString();
  344. plugindts = plugindts.replace('declare module', 'declare namespace');
  345. extraContent.push(plugindts);
  346. } catch (err) {
  347. return;
  348. }
  349. });
  350. contents = [
  351. '/*!-----------------------------------------------------------',
  352. ' * Copyright (c) Microsoft Corporation. All rights reserved.',
  353. ' * Type definitions for monaco-editor v'+MONACO_EDITOR_VERSION,
  354. ' * Released under the MIT license',
  355. '*-----------------------------------------------------------*/',
  356. ].join('\n') + '\n' + contents + '\n' + extraContent.join('\n');
  357. // Ensure consistent indentation and line endings
  358. contents = cleanFile(contents);
  359. data.contents = new Buffer(contents);
  360. {
  361. let lines = contents.split('\n');
  362. let killNextCloseCurlyBrace = false;
  363. for (let i = 0; i < lines.length; i++) {
  364. let line = lines[i];
  365. if (killNextCloseCurlyBrace) {
  366. if ('}' === line) {
  367. lines[i] = '';
  368. killNextCloseCurlyBrace = false;
  369. continue;
  370. }
  371. if (line.indexOf(' ') === 0) {
  372. lines[i] = line.substr(4);
  373. }
  374. continue;
  375. }
  376. if ('declare namespace monaco {' === line) {
  377. lines[i] = '';
  378. killNextCloseCurlyBrace = true;
  379. continue;
  380. }
  381. if (line.indexOf('declare namespace monaco.') === 0) {
  382. lines[i] = line.replace('declare namespace monaco.', 'export namespace ');
  383. }
  384. }
  385. this.emit('data', new File({
  386. path: path.join(path.dirname(data.path), 'esm/vs/editor/editor.api.d.ts'),
  387. base: data.base,
  388. contents: new Buffer(lines.join('\n'))
  389. }));
  390. }
  391. fs.writeFileSync('website/playground/monaco.d.ts.txt', contents);
  392. fs.writeFileSync('monaco.d.ts', contents);
  393. this.emit('data', data);
  394. });
  395. }
  396. /**
  397. * Normalize line endings and ensure consistent 4 spaces indentation
  398. */
  399. function cleanFile(contents) {
  400. return contents.split(/\r\n|\r|\n/).map(function(line) {
  401. var m = line.match(/^(\t+)/);
  402. if (!m) {
  403. return line;
  404. }
  405. var tabsCount = m[1].length;
  406. var newIndent = '';
  407. for (var i = 0; i < 4 * tabsCount; i++) {
  408. newIndent += ' ';
  409. }
  410. return newIndent + line.substring(tabsCount);
  411. }).join('\n');
  412. }
  413. /**
  414. * Edit ThirdPartyNotices.txt:
  415. * - append ThirdPartyNotices.txt from plugins
  416. */
  417. function addPluginThirdPartyNotices() {
  418. return es.through(function(data) {
  419. if (!/ThirdPartyNotices\.txt$/.test(data.path)) {
  420. this.emit('data', data);
  421. return;
  422. }
  423. var contents = data.contents.toString();
  424. var extraContent = [];
  425. metadata.METADATA.PLUGINS.forEach(function(plugin) {
  426. if (!plugin.thirdPartyNotices) {
  427. return;
  428. }
  429. console.log('ADDING ThirdPartyNotices from ' + plugin.thirdPartyNotices);
  430. var thirdPartyNoticeContent = fs.readFileSync(plugin.thirdPartyNotices).toString();
  431. thirdPartyNoticeContent = thirdPartyNoticeContent.split('\n').slice(8).join('\n');
  432. extraContent.push(thirdPartyNoticeContent);
  433. });
  434. contents += '\n' + extraContent.join('\n');
  435. data.contents = new Buffer(contents);
  436. this.emit('data', data);
  437. });
  438. }
  439. // --- website
  440. gulp.task('clean-website', function(cb) { rimraf('../monaco-editor-website', { maxBusyTries: 1 }, cb); });
  441. gulp.task('website', ['clean-website'], function() {
  442. function replaceWithRelativeResource(dataPath, contents, regex, callback) {
  443. return contents.replace(regex, function(_, m0) {
  444. var filePath = path.join(path.dirname(dataPath), m0);
  445. return callback(m0, fs.readFileSync(filePath));
  446. });
  447. }
  448. var waiting = 0;
  449. var done = false;
  450. return (
  451. es.merge(
  452. gulp.src([
  453. 'website/**/*',
  454. '!website/typedoc-theme/**'
  455. ], { dot: true })
  456. .pipe(es.through(function(data) {
  457. if (!data.contents || !/\.(html)$/.test(data.path) || /new-samples/.test(data.path)) {
  458. return this.emit('data', data);
  459. }
  460. var contents = data.contents.toString();
  461. contents = contents.replace(/\.\.\/release\/dev/g, 'node_modules/monaco-editor/min');
  462. contents = contents.replace(/{{version}}/g, MONACO_EDITOR_VERSION);
  463. // contents = contents.replace('&copy; 2017 Microsoft', '&copy; 2017 Microsoft [' + builtTime + ']');
  464. // Preload xhr contents
  465. contents = replaceWithRelativeResource(data.path, contents, /<pre data-preload="([^"]+)".*/g, function(m0, fileContents) {
  466. return (
  467. '<pre data-preload="' + m0 + '" style="display:none">'
  468. + fileContents.toString('utf8')
  469. .replace(/&/g, '&amp;')
  470. .replace(/</g, '&lt;')
  471. .replace(/>/g, '&gt;')
  472. + '</pre>'
  473. );
  474. });
  475. // Inline fork.png
  476. contents = replaceWithRelativeResource(data.path, contents, /src="(\.\/fork.png)"/g, function(m0, fileContents) {
  477. return (
  478. 'src="data:image/png;base64,' + fileContents.toString('base64') + '"'
  479. );
  480. });
  481. var allCSS = '';
  482. var tmpcontents = replaceWithRelativeResource(data.path, contents, /<link data-inline="yes-please" href="([^"]+)".*/g, function(m0, fileContents) {
  483. allCSS += fileContents.toString('utf8');
  484. return '';
  485. });
  486. tmpcontents = tmpcontents.replace(/<script.*/g, '');
  487. tmpcontents = tmpcontents.replace(/<link.*/g, '');
  488. waiting++;
  489. uncss(tmpcontents, {
  490. raw: allCSS,
  491. ignore: [/\.alert\b/, /\.alert-error\b/, /\.playground-page\b/]
  492. }, function(err, output) {
  493. waiting--;
  494. if (!err) {
  495. output = new CleanCSS().minify(output).styles;
  496. var isFirst = true;
  497. contents = contents.replace(/<link data-inline="yes-please" href="([^"]+)".*/g, function(_, m0) {
  498. if (isFirst) {
  499. isFirst = false;
  500. return '<style>' + output + '</style>';
  501. }
  502. return '';
  503. });
  504. }
  505. // Inline javascript
  506. contents = replaceWithRelativeResource(data.path, contents, /<script data-inline="yes-please" src="([^"]+)".*/g, function(m0, fileContents) {
  507. return '<script>' + fileContents.toString('utf8') + '</script>';
  508. });
  509. data.contents = new Buffer(contents.split(/\r\n|\r|\n/).join('\n'));
  510. this.emit('data', data);
  511. if (done && waiting === 0) {
  512. this.emit('end');
  513. }
  514. }.bind(this));
  515. }, function() {
  516. done = true;
  517. if (waiting === 0) {
  518. this.emit('end');
  519. }
  520. }))
  521. .pipe(gulp.dest('../monaco-editor-website')),
  522. gulp.src('monaco.d.ts')
  523. .pipe(typedoc({
  524. mode: 'file',
  525. out: '../monaco-editor-website/api',
  526. includeDeclarations: true,
  527. theme: 'website/typedoc-theme',
  528. entryPoint: 'monaco',
  529. name: 'Monaco Editor API v' + MONACO_EDITOR_VERSION,
  530. readme: 'none',
  531. hideGenerator: true
  532. }))
  533. )
  534. .pipe(es.through(function(data) {
  535. this.emit('data', data);
  536. }, function() {
  537. // temporarily create package.json so that npm install doesn't bark
  538. fs.writeFileSync('../monaco-editor-website/package.json', '{}');
  539. fs.writeFileSync('../monaco-editor-website/.nojekyll', '');
  540. cp.execSync('npm install monaco-editor', {
  541. cwd: path.join(__dirname, '../monaco-editor-website')
  542. });
  543. fs.unlink('../monaco-editor-website/package.json');
  544. cp.execSync('git init', {
  545. cwd: path.join(__dirname, '../monaco-editor-website')
  546. });
  547. cp.execSync('git checkout -b gh-pages', {
  548. cwd: path.join(__dirname, '../monaco-editor-website')
  549. });
  550. cp.execSync('git add .', {
  551. cwd: path.join(__dirname, '../monaco-editor-website')
  552. });
  553. cp.execSync('git commit -m "Publish website"', {
  554. cwd: path.join(__dirname, '../monaco-editor-website')
  555. });
  556. cp.execSync('git remote add origin https://github.com/Microsoft/monaco-editor.git', {
  557. cwd: path.join(__dirname, '../monaco-editor-website')
  558. });
  559. console.log('RUN monaco-editor-website>git push origin gh-pages --force')
  560. this.emit('end');
  561. }))
  562. );
  563. });
  564. gulp.task('generate-test-samples', function() {
  565. var sampleNames = fs.readdirSync(path.join(__dirname, 'test/samples'));
  566. var samples = sampleNames.map(function(sampleName) {
  567. var samplePath = path.join(__dirname, 'test/samples', sampleName);
  568. var sampleContent = fs.readFileSync(samplePath).toString();
  569. return {
  570. name: sampleName,
  571. content: sampleContent
  572. };
  573. });
  574. var prefix = '//This is a generated file via gulp generate-test-samples\ndefine([], function() { return';
  575. var suffix = '; });'
  576. fs.writeFileSync(path.join(__dirname, 'test/samples-all.generated.js'), prefix + JSON.stringify(samples, null, '\t') + suffix );
  577. var PLAY_SAMPLES = require(path.join(WEBSITE_GENERATED_PATH, 'all.js')).PLAY_SAMPLES;
  578. var locations = [];
  579. for (var i = 0; i < PLAY_SAMPLES.length; i++) {
  580. var sample = PLAY_SAMPLES[i];
  581. var sampleId = sample.id;
  582. var samplePath = path.join(WEBSITE_GENERATED_PATH, sample.path);
  583. var html = fs.readFileSync(path.join(samplePath, 'sample.html'));
  584. var js = fs.readFileSync(path.join(samplePath, 'sample.js'));
  585. var css = fs.readFileSync(path.join(samplePath, 'sample.css'));
  586. var result = [
  587. '<!DOCTYPE html>',
  588. '<!-- THIS IS A GENERATED FILE VIA gulp generate-test-samples -->',
  589. '<html>',
  590. '<head>',
  591. ' <base href="..">',
  592. ' <meta http-equiv="X-UA-Compatible" content="IE=edge" />',
  593. ' <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />',
  594. '</head>',
  595. '<body>',
  596. '<style>',
  597. '/*----------------------------------------SAMPLE CSS START*/',
  598. '',
  599. css,
  600. '',
  601. '/*----------------------------------------SAMPLE CSS END*/',
  602. '</style>',
  603. '<a class="loading-opts" href="playground.generated/index.html">[&lt;&lt; BACK]</a> <br/>',
  604. 'THIS IS A GENERATED FILE VIA gulp generate-test-samples',
  605. '',
  606. '<div id="bar" style="margin-bottom: 6px;"></div>',
  607. '',
  608. '<div style="clear:both"></div>',
  609. '<div id="outer-container" style="width:800px;height:450px;border: 1px solid grey">',
  610. '<!-- ----------------------------------------SAMPLE HTML START-->',
  611. '',
  612. html,
  613. '',
  614. '<!-- ----------------------------------------SAMPLE HTML END-->',
  615. '</div>',
  616. '<div style="clear:both"></div>',
  617. '',
  618. '<script src="../metadata.js"></script>',
  619. '<script src="dev-setup.js"></script>',
  620. '<script>',
  621. 'loadEditor(function() {',
  622. '/*----------------------------------------SAMPLE JS START*/',
  623. '',
  624. js,
  625. '',
  626. '/*----------------------------------------SAMPLE CSS END*/',
  627. '});',
  628. '</script>',
  629. '</body>',
  630. '</html>',
  631. ];
  632. fs.writeFileSync(path.join(__dirname, 'test/playground.generated/' + sampleId + '.html'), result.join('\n'));
  633. locations.push({
  634. path: sampleId + '.html',
  635. name: sample.chapter + ' &gt; ' + sample.name
  636. })
  637. }
  638. var index = [
  639. '<!DOCTYPE html>',
  640. '<!-- THIS IS A GENERATED FILE VIA gulp generate-test-samples -->',
  641. '<html>',
  642. '<head>',
  643. ' <base href="..">',
  644. '</head>',
  645. '<body>',
  646. '<a class="loading-opts" href="index.html">[&lt;&lt; BACK]</a><br/>',
  647. 'THIS IS A GENERATED FILE VIA gulp generate-test-samples<br/><br/>',
  648. locations.map(function(location) {
  649. return '<a class="loading-opts" href="playground.generated/' + location.path + '">' + location.name + '</a>';
  650. }).join('<br/>\n'),
  651. '<script src="../metadata.js"></script>',
  652. '<script src="dev-setup.js"></script>',
  653. '</body>',
  654. '</html>',
  655. ]
  656. fs.writeFileSync(path.join(__dirname, 'test/playground.generated/index.html'), index.join('\n'));
  657. });
  658. gulp.task('simpleserver', ['generate-test-samples'], function(cb) {
  659. httpServer.createServer({ root: '../', cache: 5 }).listen(8080);
  660. httpServer.createServer({ root: '../', cache: 5 }).listen(8088);
  661. console.log('LISTENING on 8080 and 8088');
  662. });