-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
75 additions
and
75 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,28 @@ | ||
const https = require('https'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const { spawnSync } = require('child_process'); | ||
const path = require('path'); | ||
const table = require('text-table'); | ||
const { green, magenta, red } = require('chalk'); | ||
const { resolve, highlightTheme } = require('hexo-theme-next/scripts/events/lib/utils'); | ||
|
||
https.get('https://api.github.com/repos/next-theme/hexo-theme-next/releases', { | ||
headers: { | ||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36' | ||
} | ||
}, res => { | ||
let data = ''; | ||
res.on('data', chunk => { | ||
data += chunk; | ||
}); | ||
res.on('end', () => { | ||
if (res.statusCode === 200) { | ||
data = JSON.parse(data); | ||
parse(data); | ||
} | ||
}); | ||
}).on('error', err => { | ||
console.error('Failded to download release messages.'); | ||
console.log(err); | ||
}); | ||
function test(color) { | ||
const reg = /^(#([\da-fA-F]{6}|[\da-fA-F]{3})|black|white|silver|grey|navy)$/; | ||
return reg.test(color); | ||
} | ||
|
||
function parse(data) { | ||
data.sort((a, b) => { | ||
return new Date(b.created_at) - new Date(a.created_at); | ||
}); | ||
data.forEach(release => { | ||
const version = release.tag_name.replace('v', ''); | ||
console.log('Processing version %s', version); | ||
const filename = path.join(__dirname, `../source/_posts/next-${version.split('.').join('-')}-released.md`); | ||
if (fs.existsSync(filename)) return; | ||
const time = release.published_at.replace('T', ' ').replace('Z', ''); | ||
const body = release.body | ||
.replace(/#(\d{1,4})/g, '[#$1](https://github.com/next-theme/hexo-theme-next/pull/$1)') | ||
.replace(/([0-9a-f]{7})([0-9a-f]{33})/g, '[$1](https://github.com/next-theme/hexo-theme-next/commit/$1$2)') | ||
.replace(/\r\n/g, '\n') | ||
.trim(); | ||
const content = `--- | ||
title: NexT ${version} Released | ||
date: ${time} | ||
--- | ||
const basename = resolve('highlight.js', 'styles/'); | ||
const list = ['', 'base16/'].flatMap(relative => { | ||
return fs.readdirSync(path.join(basename, relative)) | ||
.filter(name => name.endsWith('.css')) | ||
.map(name => highlightTheme((relative + name).replace('.css', ''))) | ||
.filter(({ background, foreground }) => { | ||
return !(test(background) && test(foreground)); | ||
}); | ||
}); | ||
|
||
${body} | ||
console.log(table(list.map(({ file, background, foreground }) => { | ||
return [green(file.replace(basename, '')), magenta(background.trim()), red(foreground.trim())]; | ||
}))); | ||
|
||
[Detailed changes for NexT v${version}](https://github.com/next-theme/hexo-theme-next/releases/tag/v${version}) | ||
`; | ||
fs.writeFileSync(filename, content); | ||
}); | ||
spawnSync('npm', ['version', data[0].tag_name.replace('v', ''), '-m', `Release ${data[0].tag_name}`, '--force'], { | ||
stdio: "inherit" | ||
}); | ||
} | ||
fs.writeFileSync(path.join(__dirname, '../source/highlight/unavailable.js'), `// This file is automatically generated using \`npm run highlight\` | ||
const unavailable = ${JSON.stringify(list.map(({ file }) => file.replace(basename, '').replace('.css', '')))}; | ||
`); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,55 @@ | ||
const fs = require('fs'); | ||
const https = require('https'); | ||
const path = require('path'); | ||
const table = require('text-table'); | ||
const { green, magenta, red } = require('chalk'); | ||
const { resolve, highlightTheme } = require('hexo-theme-next/scripts/events/lib/utils'); | ||
|
||
function test(color) { | ||
const reg = /^(#([\da-fA-F]{6}|[\da-fA-F]{3})|black|white|silver|grey|navy)$/; | ||
return reg.test(color); | ||
} | ||
const fs = require('fs'); | ||
const { spawnSync } = require('child_process'); | ||
|
||
const basename = resolve('highlight.js', 'styles/'); | ||
const list = ['', 'base16/'].flatMap(relative => { | ||
return fs.readdirSync(path.join(basename, relative)) | ||
.filter(name => name.endsWith('.css')) | ||
.map(name => highlightTheme((relative + name).replace('.css', ''))) | ||
.filter(({ background, foreground }) => { | ||
return !(test(background) && test(foreground)); | ||
}); | ||
https.get('https://api.github.com/repos/next-theme/hexo-theme-next/releases', { | ||
headers: { | ||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36' | ||
} | ||
}, res => { | ||
let data = ''; | ||
res.on('data', chunk => { | ||
data += chunk; | ||
}); | ||
res.on('end', () => { | ||
if (res.statusCode === 200) { | ||
data = JSON.parse(data); | ||
parse(data); | ||
} | ||
}); | ||
}).on('error', err => { | ||
console.error('Failded to download release messages.'); | ||
console.log(err); | ||
}); | ||
|
||
console.log(table(list.map(({ file, background, foreground }) => { | ||
return [green(file.replace(basename, '')), magenta(background.trim()), red(foreground.trim())]; | ||
}))); | ||
function parse(data) { | ||
data.sort((a, b) => { | ||
return new Date(b.created_at) - new Date(a.created_at); | ||
}); | ||
data.forEach(release => { | ||
const version = release.tag_name.replace('v', ''); | ||
console.log('Processing version %s', version); | ||
const filename = path.join(__dirname, `../source/_posts/next-${version.split('.').join('-')}-released.md`); | ||
if (fs.existsSync(filename)) return; | ||
const time = release.published_at.replace('T', ' ').replace('Z', ''); | ||
const body = release.body | ||
.replace(/#(\d{1,4})/g, '[#$1](https://github.com/next-theme/hexo-theme-next/pull/$1)') | ||
.replace(/([0-9a-f]{7})([0-9a-f]{33})/g, '[$1](https://github.com/next-theme/hexo-theme-next/commit/$1$2)') | ||
.replace(/\r\n/g, '\n') | ||
.trim(); | ||
const content = `--- | ||
title: NexT ${version} Released | ||
date: ${time} | ||
--- | ||
${body} | ||
fs.writeFileSync(path.join(__dirname, '../source/highlight/unavailable.js'), `// This file is automatically generated using \`npm run highlight\` | ||
const unavailable = ${JSON.stringify(list.map(({ file }) => file.replace(basename, '').replace('.css', '')))}; | ||
`); | ||
[Detailed changes for NexT v${version}](https://github.com/next-theme/hexo-theme-next/releases/tag/v${version}) | ||
`; | ||
fs.writeFileSync(filename, content); | ||
}); | ||
spawnSync('npm', ['version', data[0].tag_name.replace('v', ''), '-m', `Release ${data[0].tag_name}`, '--force'], { | ||
stdio: "inherit" | ||
}); | ||
} |
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