Commit a7b81287 authored by Isabella Skořepová's avatar Isabella Skořepová
Browse files

upgrade and cleanup and yarn

parent 3ae5cd3e
image: node:12
image: node:14
# Needs following env vars:
# - LFTP_PASSWORD
......@@ -17,7 +17,7 @@ deploy:
- apt update
- apt -y install rsync
- rm -rf build
- npm ci
- yarn
- node ./index.js --prod
- echo "$DEPLOY_SSH_KEY" > sshkey
- chmod 600 sshkey
......
......@@ -8,16 +8,17 @@ Tento software pro psaní článků NENÍ nutné instalovat.
# Jak to zprovoznit na fedoře
# Nainstalovat nodejs
sudo dnf -y install nodejs
npm install
sudo dnf -y install nodejs yarn
yarn
./index.js
# Jak to zprovoznit na windows
- Budeme potřebovat [git](https://git-scm.com/download/win)
- Dále budeme potřebovat [nodejs](https://nodejs.org/en/) - stáhněte si tu verzi,
na které je nápis Stable (pod tím Latest Features).
- U obou nástrojů silně doporučuji neměnit žádná nastavení!
- Dále budeme potřebovat [nodejs](https://nodejs.org/en/) - stáhněte si verzi
14.x.x (snad to tady nezapomenu aktualizovat).
- Take bude potřeba [yarn](https://classic.yarnpkg.com/en/docs/install)
- U všech nástrojů silně doporučuji neměnit žádná nastavení!
Po instalaci obou věcí přejděte do nějaké složky pomocí průzkumníka (POZOR! název
této složky ani žádné rodičovské nesmí obsahovat mezery) a klikněte na
......@@ -25,7 +26,7 @@ této složky ani žádné rodičovské nesmí obsahovat mezery) a klikněte na
git clone https://git.ok1kvk.cz/ok1kvk.cz/content.git
cd content
npm install
yarn
node index.js
Nyní by se vám měl otevřít prohlížeč na [localhost:1337](http://localhost:1337)
......
This diff is collapsed.
......@@ -11,50 +11,47 @@
"license": "UNSPECIFIED",
"dependencies": {
"@emotion/cache": "^11.0.0-next.10",
"@emotion/react": "^11.0.0-next.10",
"@emotion/server": "^11.0.0-next.10",
"browser-sync": "^2.26.7",
"chokidar": "^3.3.0",
"@emotion/react": "^11.0.0-next.14",
"@emotion/server": "^11.0.0-next.14",
"browser-sync": "^2.26.12",
"chokidar": "^3.4.2",
"cli": "^1.0.1",
"highlight.js": "^9.16.2",
"jimp": "^0.8.5",
"jsesc": "^2.5.2",
"latinize": "^0.4.0",
"highlight.js": "^10.1.2",
"jimp": "^0.16.0",
"latinize": "^0.4.1",
"marked": "^0.7.0",
"mkdirp": "^0.5.1",
"moment": "^2.24.0",
"mkdirp": "^1.0.4",
"moment": "^2.27.0",
"node-fs-extra": "^0.8.2",
"node-sass": "^4.13.0",
"nodegit": ">=0.26.2",
"nodemon": "^1.19.4",
"nunjucks": "^3.2.0",
"nunjucks-date-filter": "^0.1.1",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"node-sass": "^4.14.1",
"nodemon": "^2.0.4",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"syntax-error": "^1.4.0",
"toml": "^3.0.0",
"toml-js": "0.0.8",
"walk": "^2.3.14"
},
"devDependencies": {
"@babel/cli": "^7.7.7",
"@babel/core": "^7.7.7",
"@babel/preset-env": "^7.7.7",
"@babel/preset-react": "^7.7.4",
"@babel/preset-typescript": "^7.7.7",
"@types/react": "^16.9.17",
"@types/react-dom": "^16.9.4",
"babel-eslint": "^10.0.3",
"babel-plugin-auto-import": "^1.0.5",
"eslint": "^6.6.0",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-config-prettier": "^6.5.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-prettier": "^3.1.1",
"@babel/cli": "^7.10.5",
"@babel/core": "^7.11.1",
"@babel/preset-env": "^7.11.0",
"@babel/preset-react": "^7.10.4",
"@babel/preset-typescript": "^7.10.4",
"@types/node": "^14.0.27",
"@types/react": "^16.9.46",
"@types/react-dom": "^16.9.8",
"babel-eslint": "^10.1.0",
"babel-plugin-auto-import": "^1.1.0",
"eslint": "^7.7.0",
"eslint-config-airbnb-base": "^14.2.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-prettier": "^3.1.4",
"istanbul": "^0.4.5",
"mocha": "^6.2.2",
"prettier": "^1.18.2",
"typescript": "^3.7.4",
"mocha": "^8.1.1",
"prettier": "^2.0.5",
"typescript": "^3.9.7",
"unit.js": "^2.1.1"
},
"optionalDependencies": {}
......
const moment = require('moment')
const cli = require('cli')
const path = require('path')
const sass = require('node-sass')
const fs = require('fs')
const { promisify } = require('util')
const fsextra = require('node-fs-extra')
const chokidar = require('chokidar')
const config = require('./config')
const pipeline = require('./sitegin')
cli.main(function(args, options) {
cli.main((args, options) => {
console.log(options)
try {
sitegin(config())
......@@ -14,18 +20,13 @@ cli.main(function(args, options) {
})
function sitegin({ config }) {
const pipeline = require('./sitegin')
const sass = require('node-sass')
const fs = require('fs')
// Main builder function
// If builder is not running - run it
// If it is running - schedule rerun after it finishes
let isRunning = false
let runAgain = false
let first = false
let doSync = function() {}
let doSync = () => {}
function run() {
const startTime = moment()
runAgain = false
......@@ -42,7 +43,7 @@ function sitegin({ config }) {
console.log('Running generator')
isRunning = true
pipeline()
.then(function() {
.then(() => {
isRunning = false
console.log(
'Generator finished in',
......@@ -56,7 +57,7 @@ function sitegin({ config }) {
}
if (runAgain) run()
})
.catch(function(e) {
.catch((e) => {
isRunning = false
console.log(
'Generator crashed in',
......@@ -77,7 +78,7 @@ function sitegin({ config }) {
if (!config.prod) {
const sync = require('browser-sync').create()
doSync = function() {
doSync = () => {
sync.reload('*')
}
sync.init({
......@@ -93,7 +94,6 @@ function sitegin({ config }) {
// article or theme reload
if (!config.prod) {
const chokidar = require('chokidar')
const watches = [
path.join(__dirname, '..', 'content', 'articles'),
path.join(__dirname, '..', 'theme'),
......@@ -101,7 +101,7 @@ function sitegin({ config }) {
console.log('Watching', watches, 'for changes')
chokidar
.watch(watches, { ignoreInitial: true })
.on('all', function(event, path) {
.on('all', (event, path) => {
console.log('Content or theme changed. Rebuilding...')
console.log('Change event:', event, 'on path:', path)
run()
......@@ -112,41 +112,38 @@ function sitegin({ config }) {
function copyStaticFiles(builddir) {
// STATIC FILES
const fsextra = require('node-fs-extra')
fsextra.copy(
path.join(__dirname, '..', 'static'),
builddir,
function(file) {
(file) => {
return !(file.match('\\.git') || file.match('static/articles'))
},
function() {
() => {
console.log('copy static done')
},
)
fsextra.copy(
path.join(__dirname, '..', 'static', 'articles'),
`${builddir}/clanek`,
function() {
() => {
console.log('copy static/articles done')
},
)
}
function rendersass(builddir) {
async function rendersass(builddir) {
// SASS
const sass = require('node-sass')
const fs = require('fs')
const mkdirp = require('mkdirp')
sass.render(
{ file: path.join(__dirname, '..', 'theme-source', 'sass', 'style.scss') },
function(err, result) {
if (err === null) {
console.log('compiled sass')
mkdirp(`${builddir}/theme`, () => {
fs.writeFile(`${builddir}/theme/style.css`, result.css, () => {})
})
} else console.log('error ', err)
},
)
try {
const result = await promisify(sass.render)({
file: path.join(__dirname, '..', 'theme-source', 'sass', 'style.scss'),
})
console.log('compiled sass')
await fs.promises.mkdir(`${builddir}/theme`, { recursive: true })
await fs.promises.writeFile(`${builddir}/theme/style.css`, result.css)
console.log('wrote sass')
} catch (e) {
console.log('error ', e)
}
}
const toml = require('toml')
const moment = require('moment')
const jsesc = require('jsesc')
const fs = require('fs')
const path = require('path')
const { promisify } = require('util')
const readPageWorker = (content_, obj, authors) => {
let content = content_
......@@ -12,7 +12,6 @@ const readPageWorker = (content_, obj, authors) => {
content = content.substring(headLength)
const fmEnd = content.indexOf(head)
if (fmEnd < 0) {
console.log(jsesc(content))
throw new Error(
`Cannot find terminating ${head.substring(0, headLength - 1)}\n in file ${
obj.filename
......@@ -40,22 +39,20 @@ const readPageWorker = (content_, obj, authors) => {
return obj
}
module.exports = async obj => {
module.exports = async (obj) => {
console.log('Build step: ParseHugo')
const authors = new Map()
JSON.parse(
fs.readFileSync(
path.join(path.join(__dirname, '..', 'content'), 'authors.json'),
'utf8',
),
).forEach(author => {
const authorsjson = await promisify(fs.readFile)(
path.join(path.join(__dirname, '..', 'content'), 'authors.json'),
'utf8',
)
for (const author of JSON.parse(authorsjson)) {
authors.set(author.name, author)
})
}
const pages = []
obj.pages.forEach(page => {
obj.pages.forEach((page) => {
pages.push(readPageWorker(page.content, page, authors))
})
// eslint-disable-next-line no-param-reassign
obj.pages = pages
return obj
return { ...obj, pages }
}
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment