-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
Uses the code by @toolness from http://processing.toolness.org/general/2016/03/16/typescript-to-the-rescue.html
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,14 +100,17 @@ | |
"whatwg-fetch": "^2.0.3" | ||
}, | ||
"main": "./lib/p5.js", | ||
"types": "./lib/p5.d.ts", | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Zalastax
Author
Member
|
||
"files": [ | ||
"license.txt", | ||
"lib/p5.min.js", | ||
"lib/p5.js", | ||
"lib/addons/p5.sound.js", | ||
"lib/addons/p5.sound.min.js", | ||
"lib/addons/p5.dom.js", | ||
"lib/addons/p5.dom.min.js" | ||
"lib/addons/p5.dom.min.js", | ||
"lib/p5.d.ts", | ||
"lib/p5.global-mode.d.ts" | ||
], | ||
"description": "[![Build Status](https://travis-ci.org/processing/p5.js.svg?branch=master)](https://travis-ci.org/processing/p5.js) [![npm version](https://badge.fury.io/js/p5.svg)](https://www.npmjs.com/package/p5)", | ||
"bugs": { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
var fs = require('fs'); | ||
|
||
function shortenDescription(desc) { | ||
var match = desc.match(/^((.|\n)+?\.)\s/); | ||
|
||
if (match) { | ||
return match[1]; | ||
} | ||
return desc; | ||
} | ||
|
||
function createEmitter(filename) { | ||
var indentLevel = 0; | ||
var lastText = ''; | ||
var currentSourceFile; | ||
var fd = fs.openSync(filename, 'w'); | ||
|
||
var emit = function(text) { | ||
var indentation = []; | ||
var finalText; | ||
|
||
for (var i = 0; i < indentLevel; i++) { | ||
indentation.push(' '); | ||
} | ||
|
||
finalText = indentation.join('') + text + '\n'; | ||
fs.writeSync(fd, finalText); | ||
|
||
lastText = text; | ||
}; | ||
|
||
emit.description = function(desc) { | ||
if (!desc) { | ||
return; | ||
} | ||
|
||
emit.sectionBreak(); | ||
emit('/**'); | ||
shortenDescription(desc).split('\n').forEach(function(line) { | ||
emit(' * ' + line); | ||
}); | ||
emit(' */'); | ||
}; | ||
|
||
emit.setCurrentSourceFile = function(file) { | ||
if (file !== currentSourceFile) { | ||
currentSourceFile = file; | ||
emit.sectionBreak(); | ||
emit('// ' + file); | ||
emit.sectionBreak(); | ||
} | ||
}; | ||
|
||
emit.sectionBreak = function() { | ||
if (lastText !== '' && !/\{$/.test(lastText)) { | ||
emit(''); | ||
} | ||
}; | ||
|
||
emit.getIndentLevel = function() { | ||
return indentLevel; | ||
}; | ||
|
||
emit.indent = function() { | ||
indentLevel++; | ||
}; | ||
|
||
emit.dedent = function() { | ||
indentLevel--; | ||
}; | ||
|
||
emit.close = function() { | ||
fs.closeSync(fd); | ||
}; | ||
|
||
emit('// This file was auto-generated. Please do not edit it.\n'); | ||
|
||
return emit; | ||
} | ||
|
||
module.exports = createEmitter; |
@Zalastax Is there a reason why
./lib/p5.global-mode.d.ts
wasn't used here? I ask because the global def gives us intellisense for all the global methods like rect, createCanvas etc... The global def also includesp5.d.ts
so we still get the p5 class object references too.Example sketch.js