gulpfile.js 24 KB

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