Skip to content

Commit cff4055

Browse files
init repo with update script and github action
0 parents  commit cff4055

9 files changed

+2631
-0
lines changed

Diff for: .eslintrc.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": ["@codecademy/eslint-config"],
3+
"overrides": [
4+
{
5+
"files": ["*.ts"],
6+
"rules": {
7+
"no-console": "off"
8+
}
9+
}
10+
]
11+
}

Diff for: .github/workflows/update-cotw.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: 'Update concept of the week'
2+
3+
jobs:
4+
ci:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: Codecademy/[email protected]
8+
with:
9+
command: 'update-cotw'
10+
github-token: ${{ secrets.ACTIONS_GITHUB_TOKEN }}
11+
- name: 'Commit changes'
12+
run: |
13+
cd docs
14+
git config user.email "[email protected]"
15+
git config user.name "codecademydev"
16+
git add ./bin/concept-of-the-week.txt
17+
git commit -m "🤖 update concept of the week"
18+
git push
19+
20+
on:
21+
schedule:
22+
- cron: '0 23 * * 3' # TODO: set to 0 13 * * 0 (every sunday at 1:00 pm UTC)

Diff for: .gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
docs
2+
node_modules
3+
*.swp
4+
*.swo

Diff for: .prettierignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
docs
2+
node_modules
3+
yarn.lock

Diff for: .prettierrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('@codecademy/prettier-config');

Diff for: package.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "codecademy-docs",
3+
"dependencies": {
4+
"glob": "^7.1.7"
5+
},
6+
"devDependencies": {
7+
"@codecademy/eslint-config": "^3.1.0",
8+
"@codecademy/prettier-config": "^0.1.10",
9+
"@codecademy/tsconfig": "^0.2.0",
10+
"@types/glob": "^7.1.4",
11+
"@types/node": "^16.4.3",
12+
"eslint": "^7.25.0",
13+
"prettier": "^2.2.1",
14+
"ts-node": "^10.3.1",
15+
"typescript": "^4.2.4"
16+
},
17+
"scripts": {
18+
"compile": "tsc --noEmit",
19+
"format": "prettier --ignore-path .prettierignore --write update-cotw.ts",
20+
"format:verify": "prettier update-cotw.ts --list-different",
21+
"lint": "eslint update-cotw.ts --max-warnings 0 ",
22+
"update-cotw": "ts-node update-cotw.ts"
23+
},
24+
"license": "UNLICENSED",
25+
"version": "1.0.0"
26+
}

Diff for: tsconfig.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"extends": "@codecademy/tsconfig",
3+
"compilerOptions": {
4+
"allowJs": true,
5+
"baseUrl": ".",
6+
"isolatedModules": true,
7+
"lib": ["dom", "dom.iterable", "esnext"],
8+
"noEmit": true,
9+
"noImplicitReturns": true,
10+
"module": "commonjs",
11+
"moduleResolution": "node",
12+
"resolveJsonModule": true
13+
},
14+
"exclude": ["node_modules"],
15+
"include": ["**/*.ts"]
16+
}

Diff for: update-cotw.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { execSync } from 'child_process';
2+
import fs from 'fs';
3+
import glob from 'glob';
4+
import path from 'path';
5+
6+
const storePath = path.join(__dirname, 'docs/bin/concept-of-the-week.txt');
7+
8+
const getRandomElement = (arr: any[]) =>
9+
arr[Math.floor(Math.random() * arr.length)];
10+
11+
execSync('git clone [email protected]:Codecademy/docs.git', {
12+
stdio: [0, 1, 2],
13+
});
14+
15+
const conceptPaths = glob.sync('docs/content/*/concepts/*/*.md');
16+
17+
const currentConceptPath = fs.existsSync(storePath)
18+
? fs.readFileSync(storePath)
19+
: '';
20+
21+
let newConceptPath: string;
22+
do {
23+
newConceptPath = getRandomElement(conceptPaths);
24+
} while (newConceptPath === currentConceptPath);
25+
26+
fs.writeFileSync(storePath, newConceptPath, 'utf8');
27+
28+
console.log(`Update successful: ${currentConceptPath} -> ${newConceptPath}`);

0 commit comments

Comments
 (0)