Skip to content

Commit 1e7c192

Browse files
committed
Initial code.
0 parents  commit 1e7c192

File tree

4 files changed

+110
-0
lines changed

4 files changed

+110
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

cli.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env node
2+
/* Copyright 2016 Mozilla Foundation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
var fs = require('fs');
18+
var convertTxtToMap = require('./index');
19+
20+
var argv = require('yargs')
21+
.usage('Usage: $0 [--sourceRoot <sourceRoot>] [--file <filename>] [--output <output-file>] <txtmap-file>')
22+
.demandCommand(1)
23+
.nargs('output', 1).alias('o', 'output')
24+
.nargs('file', 1).alias('f', 'file')
25+
.nargs('sourceRoot', 1).alias('s', 'sourceRoot')
26+
.argv;
27+
28+
var txtmapPath = argv._[0];
29+
var outputPath = argv.output;
30+
31+
var opt = {};
32+
if (argv.sourceRoot)
33+
opt.sourceRoot = argv.sourceRoot;
34+
if (argv.file)
35+
opt.file = argv.file;
36+
37+
var txt = fs.readFileSync(txtmapPath).toString();
38+
39+
var map = convertTxtToMap(txt, opt);
40+
41+
if (outputPath)
42+
fs.writeFileSync(outputPath, map);
43+
else
44+
console.log(map);

index.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* Copyright 2016 Mozilla Foundation
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
var SourceMapGenerator = require('source-map').SourceMapGenerator;
17+
18+
module.exports = function (txt, opt) {
19+
var map = new SourceMapGenerator(opt || {});
20+
21+
var lines = txt.split('\n').forEach(function (line) {
22+
var parts = line.split(':');
23+
if (parts.length < 2)
24+
return;
25+
var offset = +parts[0];
26+
var file = parts[1];
27+
var line = ++parts[2];
28+
29+
map.addMapping({
30+
generated: {
31+
line: offset,
32+
column: 0
33+
},
34+
source: file,
35+
original: {
36+
line: line,
37+
column: 0
38+
}
39+
});
40+
});
41+
return map.toString();
42+
};

package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "txt2map4wasm",
3+
"version": "1.0.2",
4+
"description": "Translates wasm text source map to JSON map",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"bin": {
10+
"txt2map4wasm": "./cli.js"
11+
},
12+
"keywords": [],
13+
"repository": {
14+
"type": "git",
15+
"url": "https://github.com/yurydelendik/txt2map4wasm.git"
16+
},
17+
"author": "Yury Delendik",
18+
"license": "Apache-2.0",
19+
"dependencies": {
20+
"source-map": "^0.5.6",
21+
"yargs": "^7.1.0"
22+
}
23+
}

0 commit comments

Comments
 (0)