Skip to content

Commit bb1bd8e

Browse files
committed
write cleaner demo paths
1 parent 0d6236a commit bb1bd8e

File tree

2 files changed

+29
-31
lines changed

2 files changed

+29
-31
lines changed

lib/create/write-demo.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,23 @@ function createFolder(pathToFolder) {
2525
console.log(e);
2626
}
2727
}
28-
var tutorialFolders = function (dir) { return [
29-
path_1.join(dir, 'tutorial'),
30-
path_1.join(dir, 'tutorial', '01'),
31-
path_1.join(dir, 'tutorial', '02')
32-
]; };
28+
var tutorialFolders = [[], ['01'], ['02']];
3329
var tutorialDemo = [
34-
path_1.join('tutorial', 'tutorial.md'),
35-
path_1.join('tutorial', '01', 'index.md'),
36-
path_1.join('tutorial', '01', '01.js'),
37-
path_1.join('tutorial', '01', '02.js'),
38-
path_1.join('tutorial', '02', 'index.md'),
39-
path_1.join('tutorial', '02', '01.js'),
40-
path_1.join('tutorial', '02', '02.js')
30+
['tutorial.md'],
31+
['01', 'index.md'],
32+
['01', '01.js'],
33+
['01', '02.js'],
34+
['02', 'index.md'],
35+
['02', '01.js'],
36+
['02', '02.js'],
4137
];
4238
function createTutorialMd(dir) {
4339
return new Promise(function (resolve, reject) {
4440
createFile(dir, '.gitignore');
45-
if (!node_file_exists_1.default(path_1.join(dir, 'tutorial'))) {
46-
tutorialFolders(dir).forEach(function (folder) { return createFolder(folder); });
47-
tutorialDemo.forEach(function (file) { return createFile(dir, file); });
41+
var tutorialDir = path_1.join(dir, 'tutorial');
42+
if (!node_file_exists_1.default(path_1.join(tutorialDir))) {
43+
tutorialFolders.forEach(function (folder) { return createFolder(path_1.join.apply(void 0, [dir, 'tutorial'].concat(folder))); });
44+
tutorialDemo.forEach(function (file) { return createFile(dir, path_1.join.apply(void 0, ['tutorial'].concat(file))); });
4845
}
4946
resolve(true);
5047
});

src/create/write-demo.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {readFileSync, writeFileSync, mkdirSync} from 'fs';
22
import {join} from 'path';
3-
import {sortPackageJson} from 'sort-package-json'
3+
import {sortPackageJson} from 'sort-package-json';
44
import fileExists from 'node-file-exists';
55

66
function createFile(dir: string, pathToFile: string): void {
@@ -25,28 +25,29 @@ function createFolder(pathToFolder: string): void {
2525
}
2626
}
2727

28-
const tutorialFolders = dir => [
29-
join(dir, 'tutorial'),
30-
join(dir, 'tutorial', '01'),
31-
join(dir, 'tutorial', '02')
32-
];
28+
const tutorialFolders = [[], ['01'], ['02']];
3329

3430
const tutorialDemo = [
35-
join('tutorial', 'tutorial.md'),
36-
join('tutorial', '01', 'index.md'),
37-
join('tutorial', '01', '01.js'),
38-
join('tutorial', '01', '02.js'),
39-
join('tutorial', '02', 'index.md'),
40-
join('tutorial', '02', '01.js'),
41-
join('tutorial', '02', '02.js')
31+
['tutorial.md'],
32+
['01', 'index.md'],
33+
['01', '01.js'],
34+
['01', '02.js'],
35+
['02', 'index.md'],
36+
['02', '01.js'],
37+
['02', '02.js'],
4238
];
4339

4440
export function createTutorialMd(dir: string): Promise<boolean> {
4541
return new Promise((resolve, reject) => {
4642
createFile(dir, '.gitignore');
47-
if (!fileExists(join(dir, 'tutorial'))) {
48-
tutorialFolders(dir).forEach((folder) => createFolder(folder));
49-
tutorialDemo.forEach((file) => createFile(dir, file));
43+
const tutorialDir = join(dir, 'tutorial');
44+
if (!fileExists(join(tutorialDir))) {
45+
tutorialFolders.forEach(
46+
folder => createFolder(join(dir, 'tutorial', ...folder))
47+
);
48+
tutorialDemo.forEach(
49+
file => createFile(dir, join('tutorial', ...file))
50+
);
5051
}
5152
resolve(true);
5253
});

0 commit comments

Comments
 (0)