gulpfile.js 24 KB

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