feat(seed): add dasherized titles to unpacked filenames
This commit is contained in:
committed by
Mrugesh Mohapatra
parent
966b138f83
commit
4a77ba7af3
@ -3,10 +3,8 @@ import fs from 'fs-extra';
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import {UnpackedChallenge, ChallengeFile} from './unpackedChallenge';
|
import {UnpackedChallenge, ChallengeFile} from './unpackedChallenge';
|
||||||
|
|
||||||
const jsdiff = require('diff');
|
|
||||||
|
|
||||||
// Repack all challenges from all
|
// Repack all challenges from all
|
||||||
// seed/unpacked/00-foo/bar/000-id.html files
|
// seed/unpacked/00-foo/bar/000-xxx-id.html files
|
||||||
// into
|
// into
|
||||||
// seed/challenges/00-foo/bar.json files
|
// seed/challenges/00-foo/bar.json files
|
||||||
|
|
||||||
|
21
unpack.js
21
unpack.js
@ -15,9 +15,10 @@ import {UnpackedChallenge, ChallengeFile} from './unpackedChallenge';
|
|||||||
// todo: figure out embedded images etc. served from elsewhere in the project
|
// todo: figure out embedded images etc. served from elsewhere in the project
|
||||||
// todo: prettier/clearer CSS
|
// todo: prettier/clearer CSS
|
||||||
|
|
||||||
|
let unpackedDir = path.join(__dirname, 'unpacked');
|
||||||
|
|
||||||
// bundle up the test-running JS
|
// bundle up the test-running JS
|
||||||
function createUnpackedBundle() {
|
function createUnpackedBundle() {
|
||||||
let unpackedDir = path.join(__dirname, 'unpacked');
|
|
||||||
fs.mkdirp(unpackedDir, (err) => {
|
fs.mkdirp(unpackedDir, (err) => {
|
||||||
if (err && err.code !== 'EEXIST') {
|
if (err && err.code !== 'EEXIST') {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
@ -44,20 +45,34 @@ function createUnpackedBundle() {
|
|||||||
|
|
||||||
let currentlyUnpackingDir = null;
|
let currentlyUnpackingDir = null;
|
||||||
|
|
||||||
|
async function cleanUnpackedDir(unpackedChallengeBlockDir) {
|
||||||
|
let promiseToDelete = function(filePath) {
|
||||||
|
filePath = path.join(unpackedChallengeBlockDir, filePath);
|
||||||
|
return new Promise(() => fs.unlink(filePath));
|
||||||
|
};
|
||||||
|
let promises = fs.readdirSync(unpackedChallengeBlockDir)
|
||||||
|
.filter(filePath => (/\.html$/i).test(filePath))
|
||||||
|
.map(promiseToDelete);
|
||||||
|
await Promise.all(promises);
|
||||||
|
}
|
||||||
|
|
||||||
function unpackChallengeBlock(challengeBlock) {
|
function unpackChallengeBlock(challengeBlock) {
|
||||||
let challengeBlockPath = path.parse(challengeBlock.fileName);
|
let challengeBlockPath = path.parse(challengeBlock.fileName);
|
||||||
let unpackedChallengeBlockDir = path.join(
|
let unpackedChallengeBlockDir = path.join(
|
||||||
__dirname,
|
unpackedDir,
|
||||||
'unpacked',
|
|
||||||
challengeBlockPath.dir,
|
challengeBlockPath.dir,
|
||||||
challengeBlockPath.name
|
challengeBlockPath.name
|
||||||
);
|
);
|
||||||
|
|
||||||
fs.mkdirp(unpackedChallengeBlockDir, (err) => {
|
fs.mkdirp(unpackedChallengeBlockDir, (err) => {
|
||||||
if (err && err.code !== 'EEXIST') {
|
if (err && err.code !== 'EEXIST') {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remove existing unpacked files
|
||||||
|
cleanUnpackedDir(unpackedChallengeBlockDir);
|
||||||
|
|
||||||
if (currentlyUnpackingDir !== challengeBlockPath.dir) {
|
if (currentlyUnpackingDir !== challengeBlockPath.dir) {
|
||||||
currentlyUnpackingDir = challengeBlockPath.dir;
|
currentlyUnpackingDir = challengeBlockPath.dir;
|
||||||
console.log(`Unpacking into ${currentlyUnpackingDir}:`);
|
console.log(`Unpacking into ${currentlyUnpackingDir}:`);
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
import { dasherize } from '../common/utils';
|
||||||
|
|
||||||
const jsonLinePrefix = '//--JSON:';
|
const jsonLinePrefix = '//--JSON:';
|
||||||
const paragraphBreak = '<!--break-->';
|
const paragraphBreak = '<!--break-->';
|
||||||
@ -28,7 +29,6 @@ class ChallengeFile {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
readChunks() {
|
readChunks() {
|
||||||
// todo: make this work async
|
// todo: make this work async
|
||||||
// todo: make sure it works with encodings
|
// todo: make sure it works with encodings
|
||||||
@ -142,7 +142,7 @@ class UnpackedChallenge {
|
|||||||
// eslint-disable-next-line no-nested-ternary
|
// eslint-disable-next-line no-nested-ternary
|
||||||
let prefix = ((this.index < 10) ? '00' : (this.index < 100) ? '0' : '')
|
let prefix = ((this.index < 10) ? '00' : (this.index < 100) ? '0' : '')
|
||||||
+ this.index;
|
+ this.index;
|
||||||
return `${prefix}-${this.challenge.id}`;
|
return `${prefix}-${dasherize(this.challenge.title)}-${this.challenge.id}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
expandedDescription() {
|
expandedDescription() {
|
||||||
|
Reference in New Issue
Block a user