Skip to content

Commit 3c6bb66

Browse files
committed
refactor create setup project
1 parent 68c2992 commit 3c6bb66

File tree

17 files changed

+68
-118
lines changed

17 files changed

+68
-118
lines changed

lib/build/build.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var validate = require('./validators');
44
var info_1 = require('./parser/info');
55
var readme_1 = require('./readme');
66
var cleanup_1 = require('./parser/cleanup');
7-
function build(lines) {
7+
function parseAndBuild(lines) {
88
var result = {
99
info: {
1010
title: '',
@@ -18,15 +18,15 @@ function build(lines) {
1818
};
1919
return info_1.info(result, lines, index);
2020
}
21-
function default_1(filePath, output) {
21+
function build(filePath, output) {
2222
if (output === void 0) { output = './coderoad.json'; }
2323
validate.filePath(filePath);
2424
var lines = fs_1.readFileSync(filePath, 'utf8').split('\n');
25-
var result = cleanup_1.cleanup(build(lines));
25+
var result = cleanup_1.cleanup(parseAndBuild(lines));
2626
if (validate.result(result)) {
2727
fs_1.writeFileSync(output, result, 'utf8');
2828
}
2929
readme_1.createReadme();
3030
}
3131
Object.defineProperty(exports, "__esModule", { value: true });
32-
exports.default = default_1;
32+
exports.default = build;

lib/build/parser/chapter.js

Lines changed: 0 additions & 42 deletions
This file was deleted.

lib/build/parser/tutorialDir.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

lib/cli.js

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#! /usr/bin/env node
2-
32
"use strict";
43
var program = require('commander');
54
var chalk_1 = require('chalk');
@@ -10,34 +9,39 @@ var tutorials_1 = require('./tutorials/tutorials');
109
var publish_1 = require('./publish/publish');
1110
var update_1 = require('./update/update');
1211
program
13-
.version('0.3.27')
14-
.usage('[options] <keywords>')
15-
.option('-b, --build [path/to/tutorial.md]', 'tutorial markdown file', /^.+\.md$/i)
16-
.option('-c, --create [name]', 'tutorial name')
17-
.option('-p, --publish [version]', 'publish tutorial to npm with new version number')
18-
.option('-t, --tutorials', 'list of tutorial packages')
19-
.option('-s, --search [query]', 'search for tutorial package')
20-
.option('-r, --run', 'run tutorial')
21-
.parse(process.argv);
12+
.version('0.3.27')
13+
.usage('[options] <keywords>')
14+
.option('-b, --build [path/to/tutorial.md]', 'tutorial markdown file', /^.+\.md$/i)
15+
.option('-c, --create [name]', 'tutorial name')
16+
.option('-p, --publish [version]', 'publish tutorial to npm with new version number')
17+
.option('-t, --tutorials', 'list of tutorial packages')
18+
.option('-s, --search [query]', 'search for tutorial package')
19+
.option('-r, --run', 'run tutorial')
20+
.parse(process.argv);
2221
update_1.checkForUpdate();
2322
if (program.build) {
24-
var tutorial = program.args[0] || 'tutorial/tutorial.md';
25-
var output = 'coderoad.json';
26-
process.stdout.write(chalk_1.grey("building coderoad.json for " + tutorial + "..."));
27-
build_1.default(tutorial, output);
28-
} else if (program.create) {
29-
var packageName = program.args[0];
30-
create_1.default(packageName);
31-
} else if (program.search) {
32-
var query = program.args[0];
33-
search_1.default(query);
34-
} else if (program.tutorials) {
35-
tutorials_1.default();
36-
} else if (program.publish) {
37-
var version = program.args[0];
38-
publish_1.default(version);
39-
} else {
40-
program.help();
23+
var tutorial = program.args[0] || 'tutorial/tutorial.md';
24+
var output = 'coderoad.json';
25+
process.stdout.write(chalk_1.grey("building coderoad.json for " + tutorial + "..."));
26+
build_1.default(tutorial, output);
27+
}
28+
else if (program.create) {
29+
var packageName = program.args[0];
30+
create_1.default(packageName);
31+
}
32+
else if (program.search) {
33+
var query = program.args[0];
34+
search_1.default(query);
35+
}
36+
else if (program.tutorials) {
37+
tutorials_1.default();
38+
}
39+
else if (program.publish) {
40+
var version = program.args[0];
41+
publish_1.default(version);
42+
}
43+
else {
44+
program.help();
4145
}
4246
process.stdout.write(chalk_1.green(' ✓\n'));
4347
process.exit(0);

lib/create/create.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ function create(name) {
77
process.stdout.write("Creating demo tutorial \"coderoad-" + name + "\"...");
88
Promise.all([
99
write_demo_1.createPackageJson(name),
10-
write_demo_1.createTutorialMd(),
11-
write_demo_1.createTestFiles()
10+
write_demo_1.createTutorialMd()
1211
]).then(function () {
1312
build_1.default('tutorial/tutorial.md', 'coderoad.json');
1413
});

lib/create/write-demo.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@ function createFolder(pathToFolder) {
1616
}
1717
function createTutorialMd() {
1818
return new Promise(function (resolve, reject) {
19+
createFile('.gitignore');
1920
createFolder('tutorial');
2021
createFile(path_1.join('tutorial', 'tutorial.md'));
21-
createFolder(path_1.join('tutorial', '1'));
22-
createFolder(path_1.join('tutorial', '1', '01'));
23-
createFile(path_1.join('tutorial', '1', '01', 'page-one.md'));
24-
createFolder(path_1.join('tutorial', '1', '02'));
25-
createFile(path_1.join('tutorial', '1', '02', 'page-two.md'));
22+
createFolder(path_1.join('tutorial', '01'));
23+
createFile(path_1.join('tutorial', '01', 'page-one.md'));
24+
createFile(path_1.join('tutorial', '01', '01.spec.js'));
25+
createFile(path_1.join('tutorial', '01', '02.spec.js'));
26+
createFolder(path_1.join('tutorial', '02'));
27+
createFile(path_1.join('tutorial', '02', 'page-two.md'));
28+
createFile(path_1.join('tutorial', '02', '01.spec.js'));
29+
createFile(path_1.join('tutorial', '02', '02.spec.js'));
2630
resolve();
2731
});
2832
}
@@ -43,12 +47,3 @@ function createPackageJson(name) {
4347
});
4448
}
4549
exports.createPackageJson = createPackageJson;
46-
function createTestFiles() {
47-
return new Promise(function (resolve, reject) {
48-
createFile(path_1.join('tutorial', '1', '01', '01.spec.js'));
49-
createFile(path_1.join('tutorial', '1', '01', '02.spec.js'));
50-
createFile(path_1.join('tutorial', '1', '02', '01.spec.js'));
51-
createFile(path_1.join('tutorial', '1', '02', '02.spec.js'));
52-
});
53-
}
54-
exports.createTestFiles = createTestFiles;

setup/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
tutorial/.tmp.*
File renamed without changes.
File renamed without changes.

setup/tutorial/1/01/page-one.md renamed to setup/tutorial/01/page-one.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function doSomething(parameter) {
1717
Try making your own basic functions.
1818

1919
+ write a function `addOne` that adds one to a number
20-
@test('1/01/01')
20+
@test('01/01')
2121
@action(open('page-01.js'))
2222
@action(set(
2323
```
@@ -29,7 +29,7 @@ function addOne(x) {
2929
))
3030

3131
+ write a function `subtractOne` that subtracts one from a number
32-
@test('1/01/02')
32+
@test('01/02')
3333
@action(insert(
3434
```
3535
File renamed without changes.
File renamed without changes.

setup/tutorial/1/02/page-two.md renamed to setup/tutorial/02/page-two.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Writing basic functions continued.
55
We'll write two more basic functions, this time without any help.
66

77
+ write a function `divideOne` divides a number by 1
8-
@test('1/02/01')
8+
@test('02/01')
99
@action(open('page-02.js'))
1010
@action(set(
1111
```
@@ -17,7 +17,7 @@ function divideOne(x) {
1717
))
1818

1919
+ write a function `mutiplyone` that multiplies a number by 1
20-
@test('1/02/02')
20+
@test('02/02')
2121
@action(insert(
2222
```
2323

setup/tutorial/tutorial.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Tutorial Title
22
Tutorial description.
33

4-
@import('1/01/page-one')
5-
6-
@import('1/02/page-two')
4+
@import('01/page-one')
5+
@import('02/page-two')

src/build/build.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {info} from './parser/info';
44
import {createReadme} from './readme';
55
import {cleanup} from './parser/cleanup';
66

7-
function build(lines: string[]): CR.Output {
7+
function parseAndBuild(lines: string[]): CR.Output {
88
let result: CR.Output = {
99
info: {
1010
title: '',
@@ -19,14 +19,14 @@ function build(lines: string[]): CR.Output {
1919
return info(result, lines, index);
2020
}
2121

22-
export default function(filePath: string, output = './coderoad.json'): void {
22+
export default function build(filePath: string, output = './coderoad.json'): void {
2323
// VALIDATE: path name
2424
validate.filePath(filePath);
2525

2626
// Read
2727
let lines: string[] = readFileSync(filePath, 'utf8').split('\n');
2828
// Build
29-
let result = cleanup(build(lines));
29+
let result = cleanup(parseAndBuild(lines));
3030

3131
if (validate.result(result)) {
3232
// Safe to Write coderoad.json

src/create/create.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {validatePackageName} from './validate';
2-
import {createPackageJson, createTutorialMd, createTestFiles} from './write-demo';
2+
import {createPackageJson, createTutorialMd} from './write-demo';
33
import build from '../build/build';
44

55
export default function create(name: string): void {
@@ -12,9 +12,9 @@ export default function create(name: string): void {
1212
// npm package
1313
Promise.all([
1414
createPackageJson(name),
15-
createTutorialMd(),
16-
createTestFiles()
15+
createTutorialMd()
1716
]).then(() => {
1817
build('tutorial/tutorial.md', 'coderoad.json');
1918
});
19+
2020
}

src/create/write-demo.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@ function createFolder(pathToFolder: string): void {
1818

1919
export function createTutorialMd(): void {
2020
return new Promise((resolve, reject) => {
21+
createFile('.gitignore');
2122
createFolder('tutorial');
2223
createFile(join('tutorial', 'tutorial.md'));
23-
createFolder(join('tutorial', '1'));
24-
createFolder(join('tutorial', '1', '01'));
25-
createFile(join('tutorial', '1', '01', 'page-one.md'));
26-
createFolder(join('tutorial', '1', '02'));
27-
createFile(join('tutorial', '1', '02', 'page-two.md'));
24+
createFolder(join('tutorial', '01'));
25+
createFile(join('tutorial', '01', 'page-one.md'));
26+
createFile(join('tutorial', '01', '01.spec.js'));
27+
createFile(join('tutorial', '01', '02.spec.js'));
28+
createFolder(join('tutorial', '02'));
29+
createFile(join('tutorial', '02', 'page-two.md'));
30+
createFile(join('tutorial', '02', '01.spec.js'));
31+
createFile(join('tutorial', '02', '02.spec.js'));
2832
resolve();
2933
});
3034
}
@@ -43,12 +47,3 @@ export function createPackageJson(name: string): void {
4347
}
4448
});
4549
}
46-
47-
export function createTestFiles(): void {
48-
return new Promise((resolve, reject) => {
49-
createFile(join('tutorial', '1', '01', '01.spec.js'));
50-
createFile(join('tutorial', '1', '01', '02.spec.js'));
51-
createFile(join('tutorial', '1', '02', '01.spec.js'));
52-
createFile(join('tutorial', '1', '02', '02.spec.js'));
53-
});
54-
}

0 commit comments

Comments
 (0)