Skip to content

Commit

Permalink
Switch CodeMirror to peer dependency
Browse files Browse the repository at this point in the history
Fix mizzao#87 by allowing user to include any version of CodeMirror they like
via `meteor npm install codemirror`.  Also makes it easy to include
addons and themes.
  • Loading branch information
edemaine committed Aug 15, 2018
1 parent ca917a1 commit 189c4ae
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 137 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ Template.foo.config = function () {
};
```

CodeMirror is an peer NPM dependency: you must `meteor npm install codemirror`.
The advantage of this approach is that you can choose which version to include.
To include a CodeMirror [theme](https://codemirror.net/theme/) or
[addon](https://codemirror.net/doc/manual.html#addons), use an `import`
statement to include the module or CSS. For example:

```js
import 'codemirror/theme/monokai.css'; // theme
import 'codemirror/addon/fold/foldcode'; // addon
import 'codemirror/addon/fold/foldgutter'; // addon needing CSS
import 'codemirror/addon/fold/foldgutter.css'; // addon's CSS
```

## Server Configuration

See this [example config file](settings-example.json) for the various settings that you can use.
Expand Down
15 changes: 9 additions & 6 deletions demo/.meteor/packages
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
# 'meteor add' and 'meteor remove' will edit this file for you,
# but you can also edit it by hand.

autopublish
insecure
autopublish@1.0.7
insecure@1.0.7
standard-app-packages
stylus
stylus@=2.513.8
mizzao:sharejs
mizzao:sharejs-codemirror
mizzao:sharejs-ace
twbs:bootstrap
standard-minifiers
modules
ecmascript
[email protected]
[email protected]
standard-minifier-css
standard-minifier-js
shell-server
dynamic-import
2 changes: 1 addition & 1 deletion demo/.meteor/release
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1 +1 @@
METEOR@1.4.2.3
METEOR@1.7.0.4
122 changes: 64 additions & 58 deletions demo/.meteor/versions
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,78 +1,84 @@
allow-deny@1.0.5
allow-deny@1.1.0
[email protected]
autoupdate@1.3.12
babel-compiler@6.13.0
babel-runtime@1.0.1
[email protected].10
autoupdate@1.4.1
babel-compiler@7.1.1
babel-runtime@1.2.4
[email protected].11
[email protected]
[email protected].0
[email protected].3
[email protected]
boilerplate-generator@1.0.11
[email protected].9
[email protected].0
callback-hook@1.0.10
check@1.2.4
ddp@1.2.5
ddp-client@1.3.2
ddp-common@1.2.8
ddp-server@1.3.12
boilerplate-generator@1.5.0
[email protected].12
[email protected].3
callback-hook@1.1.0
check@1.3.1
ddp@1.4.0
ddp-client@2.3.3
ddp-common@1.4.0
ddp-server@2.2.0
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
http@1.2.10
id-map@1.0.9
http@1.4.1
id-map@1.1.0
[email protected]
[email protected].10
[email protected].0
[email protected].11
[email protected].1
[email protected]
[email protected].16
meteor@1.6.0
[email protected].20
meteor@1.9.2
[email protected]
minifier-css@1.2.15
minifier-js@1.2.15
minimongo@1.0.19
mizzao:sharejs@0.9.1
minifier-css@1.3.1
minifier-js@2.3.5
minimongo@1.4.4
mizzao:sharejs@0.10.1
mizzao:[email protected]
mizzao:[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
mizzao:[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
npm-mongo@2.2.16_1
[email protected].14
ordered-dict@1.0.9
promise@0.8.8
random@1.0.10
reactive-dict@1.1.8
npm-mongo@3.0.11
[email protected].16
ordered-dict@1.1.0
promise@0.11.1
random@1.1.0
reactive-dict@1.2.1
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected].0
[email protected].0
[email protected].0
[email protected].0
tracker@1.1.1
[email protected].2
[email protected].3
[email protected].2
[email protected].2
tracker@1.2.0
twbs:[email protected]
[email protected].12
[email protected].13
[email protected]
url@1.0.11
webapp@1.3.12
url@1.2.0
webapp@1.6.2
[email protected]
8 changes: 8 additions & 0 deletions demo/client/client.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import 'codemirror/addon/fold/foldcode';
import 'codemirror/addon/fold/foldgutter';
import 'codemirror/addon/fold/indent-fold';
import 'codemirror/addon/hint/show-hint';
import 'codemirror/addon/display/placeholder';

import 'codemirror/theme/monokai.css';
import 'codemirror/addon/fold/foldgutter.css';
import 'codemirror/addon/hint/show-hint.css';

Template.docList.helpers({
documents: function() {
Expand Down
5 changes: 4 additions & 1 deletion demo/package.json
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"description": "meteor-documents-demo =====================",
"main": "index.js",
"dependencies": {
"babel-runtime": "^6.20.0"
"@babel/runtime": "^7.0.0-beta.55",
"ace-builds": "^1.4.1",
"babel-runtime": "^6.20.0",
"codemirror": "^5.39.2"
},
"devDependencies": {},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion sharejs-base/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Npm.depends({
// Fork of 0.6.3 that doesn't require("mongodb"):
// https://github.com/meteor/meteor/issues/532#issuecomment-82635979
// Includes "Failed to parse" bugfix
share: "https://github.com/qeek/sharejs-tmp-fork/tarball/94c059bd4da24de8e6e90fb83484dd9c7b0efd59",
share: "https://github.com/mizzao/ShareJS/tarball/05b625ea1e7f7f27bd13ba7ed05102b38dd175e5",
browserchannel: '1.2.0'
});

Expand Down
2 changes: 1 addition & 1 deletion sharejs-base/sharejs-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Meteor } from 'meteor/meteor';

const Future = Npm.require('fibers/future');

export const ShareJS = ShareJS || {};
export const ShareJS = {};
// See docs for options. Uses mongo by default to enable persistence.

// Using special options from https://github.com/share/ShareJS/blob/master/src/server/index.coffee
Expand Down
25 changes: 13 additions & 12 deletions sharejs-codemirror/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ import { Template } from 'meteor/templating'
import { Blaze } from 'meteor/blaze'
import { ShareJSConnector } from 'meteor/mizzao:sharejs'

import CodeMirror from 'codemirror';
import 'codemirror/addon/fold/foldcode';
import 'codemirror/addon/fold/foldgutter';
import 'codemirror/addon/fold/indent-fold';
import 'codemirror/addon/hint/show-hint';
import 'codemirror/addon/display/placeholder';

import 'codemirror/lib/codemirror.css';
import 'codemirror/theme/monokai.css';
import 'codemirror/addon/fold/foldgutter.css';
import 'codemirror/addon/hint/show-hint.css';
try {
CodeMirror = require('codemirror');
import 'codemirror/lib/codemirror.css';
} catch (e) {
if (e.toString().match("Cannot find module")) {
console.error("Could not load NPM module `codemirror`, which is a peer " +
"dependency. You need to `meteor npm install --save codemirror`.");
return;
} else {
throw e;
}
}

import './cm'

Expand Down Expand Up @@ -59,4 +60,4 @@ class ShareJSCMConnector extends ShareJSConnector {
}
Template.registerHelper("sharejsCM", new Template('sharejsCM',function(){
return new ShareJSCMConnector(this).create();
}));
}));
4 changes: 3 additions & 1 deletion sharejs-codemirror/cm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 1 addition & 56 deletions sharejs-codemirror/package.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,10 @@
Package.describe({
name: "mizzao:sharejs-codemirror",
summary: "ShareJS with the CodeMirror Editor",
version: "5.22.0",
version: "5.39.2",
git: "https://github.com/mizzao/meteor-sharejs.git"
});

Npm.depends({
codemirror: "5.22.0"
});


// Ugly-ass function stolen from http://stackoverflow.com/a/20794116/586086
// TODO make this less ugly in future
function getFilesFromFolder(packageName, folder){
// local imports
var _ = Npm.require("underscore");
var fs = Npm.require("fs");
var path = Npm.require("path");
// helper function, walks recursively inside nested folders and return absolute filenames
function walk(folder){
var filenames = [];
// get relative filenames from folder
var folderContent = fs.readdirSync(folder);
// iterate over the folder content to handle nested folders
_.each(folderContent, function(filename) {
// build absolute filename
var absoluteFilename = path.join(folder, filename);
// get file stats
var stat = fs.statSync(absoluteFilename);
if(stat.isDirectory()){
// directory case => add filenames fetched from recursive call
filenames = filenames.concat(walk(absoluteFilename));
}
else{
// file case => simply add it
filenames.push(absoluteFilename);
}
});
return filenames;
}
// save current working directory (something like "/home/user/projects/my-project")
var cwd = process.cwd();

var isRunningFromApp = fs.existsSync(path.resolve("packages"));
var packagePath = isRunningFromApp ? path.resolve("packages", packageName) : "";
console.log(packagePath);

packagePath = path.resolve(packagePath);
// chdir to our package directory
process.chdir(path.join(packagePath));
// launch initial walk
var result = walk(folder);
// restore previous cwd
process.chdir(cwd);
return result;
}

Package.onUse(function (api) {
api.versionsFrom("1.3.2");

Expand All @@ -64,10 +13,6 @@ Package.onUse(function (api) {
api.use("mizzao:[email protected]");
api.imply("mizzao:sharejs");

// Add Ace files as assets that can be loaded by the client later
var codemirrorData = getFilesFromFolder("mizzao:sharejs-codemirror", ".npm/package/node_modules/codemirror");
api.addAssets(codemirrorData, 'client');

api.mainModule('client.js', 'client');
api.addFiles([
'templates.html'
Expand Down

0 comments on commit 189c4ae

Please sign in to comment.