Fixed example instance container (#221)
* fixed example inance container * added a space
This commit is contained in:
parent
51336baee6
commit
412d330f74
1 changed files with 103 additions and 44 deletions
|
@ -120,12 +120,19 @@ function getSketchesInCategories(categories) {
|
||||||
const examples = JSON.parse(res);
|
const examples = JSON.parse(res);
|
||||||
examples.forEach(example => {
|
examples.forEach(example => {
|
||||||
let projectName;
|
let projectName;
|
||||||
|
if (example.name === '02_Instance_Container.js') {
|
||||||
|
for (let i = 1; i < 5; i++) {
|
||||||
|
const instanceProjectName = category.name + ': ' + 'Instance Container ' + i;
|
||||||
|
projectsInOneCategory.push({sketchUrl: example.download_url, projectName: instanceProjectName});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if (example.name.split('_')[1]) {
|
if (example.name.split('_')[1]) {
|
||||||
projectName = category.name + ': '+ example.name.split('_').slice(1).join(' ').replace('.js', '');
|
projectName = category.name + ': '+ example.name.split('_').slice(1).join(' ').replace('.js', '');
|
||||||
} else {
|
} else {
|
||||||
projectName = category.name + ': '+ example.name.replace('.js', '');
|
projectName = category.name + ': '+ example.name.replace('.js', '');
|
||||||
}
|
}
|
||||||
projectsInOneCategory.push({sketchUrl: example.download_url, projectName: projectName});
|
projectsInOneCategory.push({sketchUrl: example.download_url, projectName: projectName});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return projectsInOneCategory;
|
return projectsInOneCategory;
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
|
@ -145,7 +152,15 @@ function getSketchContent(projectsInAllCategories) {
|
||||||
};
|
};
|
||||||
|
|
||||||
return rp(options).then(res => {
|
return rp(options).then(res => {
|
||||||
|
const noNumberprojectName = project.projectName.replace(/(\d+)/g, '');
|
||||||
|
if (noNumberprojectName === 'Instance Mode : Instance Container ') {
|
||||||
|
for (let i = 0; i < 4; i++) {
|
||||||
|
let splitedRes = res.split('*/')[1].split('</html>')[i] + '</html>\n';
|
||||||
|
project.sketchContent = splitedRes.replace('p5.js', 'https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.4/p5.min.js');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
project.sketchContent = res;
|
project.sketchContent = res;
|
||||||
|
}
|
||||||
return project;
|
return project;
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
throw err;
|
throw err;
|
||||||
|
@ -171,7 +186,50 @@ function createProjectsInP5user(projectsInAllCategories) {
|
||||||
|
|
||||||
async.eachSeries(projectsInAllCategories, (projectsInOneCategory, categoryCallback) => {
|
async.eachSeries(projectsInAllCategories, (projectsInOneCategory, categoryCallback) => {
|
||||||
async.eachSeries(projectsInOneCategory, (project, projectCallback) => {
|
async.eachSeries(projectsInOneCategory, (project, projectCallback) => {
|
||||||
let newProject = new Project({
|
let newProject;
|
||||||
|
const noNumberprojectName = project.projectName.replace(/(\d+)/g, '');
|
||||||
|
if (noNumberprojectName === 'Instance Mode : Instance Container ') {
|
||||||
|
newProject = new Project({
|
||||||
|
name: project.projectName,
|
||||||
|
user: user._id,
|
||||||
|
files: [
|
||||||
|
{
|
||||||
|
name: 'root',
|
||||||
|
id: r,
|
||||||
|
_id: r,
|
||||||
|
children: [a, b, c],
|
||||||
|
fileType: 'folder'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'sketch.js',
|
||||||
|
content: '// Instance Mode : Instance Container, please check its index.html file',
|
||||||
|
id: a,
|
||||||
|
_id: a,
|
||||||
|
isSelectedFile: true,
|
||||||
|
fileType: 'file',
|
||||||
|
children: []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'index.html',
|
||||||
|
content: project.sketchContent,
|
||||||
|
id: b,
|
||||||
|
_id: b,
|
||||||
|
fileType: 'file',
|
||||||
|
children: []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'style.css',
|
||||||
|
content: defaultCSS,
|
||||||
|
id: c,
|
||||||
|
_id: c,
|
||||||
|
fileType: 'file',
|
||||||
|
children: []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
_id: shortid.generate()
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
newProject = new Project({
|
||||||
name: project.projectName,
|
name: project.projectName,
|
||||||
user: user._id,
|
user: user._id,
|
||||||
files: [
|
files: [
|
||||||
|
@ -210,6 +268,7 @@ function createProjectsInP5user(projectsInAllCategories) {
|
||||||
],
|
],
|
||||||
_id: shortid.generate()
|
_id: shortid.generate()
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let assetsInProject = project.sketchContent.match(/assets\/[\w-]+\.[\w]*/g) || project.sketchContent.match(/assets\/[\w-]*/g) || [];
|
let assetsInProject = project.sketchContent.match(/assets\/[\w-]+\.[\w]*/g) || project.sketchContent.match(/assets\/[\w-]*/g) || [];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue