Created
April 17, 2018 09:08
-
-
Save paulsonnentag/fd0f187cd501bde639e96b169a2cae35 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const path = require('path'); | |
const {spaceName, paperNumbers} = require('./config.json'); | |
const knex = require('knex')({ | |
client: 'pg', | |
connection: process.env.DATABASE_URL, | |
}); | |
const initialCode = fs.readFileSync(path.join(__dirname, 'initial-code.js'), 'utf8') | |
function getInitialCode (id) { | |
return `// Program ${id} | |
` + initialCode | |
} | |
(async () => { | |
// delete existing programs in space | |
await knex('programs').where({spaceName}).delete() | |
// create program with initial code for each paper | |
await Promise.all(paperNumbers.map((number, index) => { | |
const code = getInitialCode(index + 1) | |
console.log(`create paper #${number}`) | |
return knex('programs').insert({spaceName, number, originalCode: code, currentCode: code}) | |
})); | |
console.log('done'); | |
process.exit(1) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment