| 47 | } |
| 48 | |
| 49 | _createProject(data, onSuccess) { |
| 50 | const options = { |
| 51 | hostname: 'api.cloudflare.com', |
| 52 | port: 443, |
| 53 | path: `/client/v4/accounts/${this.v.get('CLOUDFLARE_ACCOUNT_ID')}/pages/projects/`, |
| 54 | method: 'POST', |
| 55 | headers: { |
| 56 | 'Authorization': `Bearer ${this.v.get('CLOUDFLARE_API_TOKEN')}`, |
| 57 | 'Content-Type': 'application/json', |
| 58 | 'Content-Length': data.length, |
| 59 | }, |
| 60 | }; |
| 61 | |
| 62 | const req = https.request(options, (res) => { |
| 63 | let body = ''; |
| 64 | res.on('data', (d) => { |
| 65 | body += d; |
| 66 | }); |
| 67 | res.on("end", () => { |
| 68 | try { |
| 69 | let json = JSON.parse(body); |
| 70 | onSuccess(json); |
| 71 | } catch (error) { |
| 72 | console.error(error.message); |
| 73 | process.exit(1); |
| 74 | } |
| 75 | }); |
| 76 | }); |
| 77 | |
| 78 | req.on('error', (e) => { |
| 79 | console.error(e); |
| 80 | process.exit(1); |
| 81 | }); |
| 82 | req.write(data) |
| 83 | req.end(); |
| 84 | } |
| 85 | |
| 86 | run() { |
| 87 | console.log(`Init project ${this.v.get('CLOUDFLARE_PROJECT_NAME')} [${this.currentEnv}]...`); |