-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathexport.js
More file actions
59 lines (52 loc) · 1.58 KB
/
export.js
File metadata and controls
59 lines (52 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
module.exports.command = 'export <codemod-name>';
module.exports.desc = 'Export the current transform to ast-explorer';
module.exports.builder = function builder(yargs) {
yargs.positional('codemod-name', {
describe: 'the name of the codemod to export',
});
};
module.exports.handler = function handler(options) {
const fs = require('fs-extra');
let { codemodName } = options;
const Octokit = require('@octokit/rest');
const octokit = new Octokit({ auth: 'acabfddbefb244cb3e674fa84046a907c78f2294' });
let files = {
'astexplorer.json': {
content: `{
"v": 2,
"parserID": "recast",
"toolID": "jscodeshift",
"settings": {
"recast": null,
},
"versions": {
"recast": "0.18.2",
"jscodeshift": "0.6.4"
}
}`,
},
'source.js': {
content: 'console.log("hello world");',
},
'tranform.js': {
content: fs.readFileSync(`${process.cwd()}/transforms/${codemodName}/index.js`, 'utf-8'),
},
};
octokit.gists
.create({
files,
})
.then(({ data }) => {
// https://api.github.com/gists/de5cff0a12c2aaf129f94b775306af6f
console.log(data);
// Getting the revision url and replace it with astexplorer format
//let url = data.history[0].url.replace('api.github.com/gists', 'astexplorer.net/#/gist');
let gistId = data.id;
let url = `https://astexplorer.net/#/gist/${gistId}`;
const exec = require('child_process').exec;
exec(`open ${url}`);
})
.catch(err => {
console.log('Error: ', err);
});
};