Skip to content

Commit

Permalink
Added better default files for foreground and background
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasBomholtz committed May 3, 2022
1 parent c42c3ff commit 8716c17
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 4 deletions.
5 changes: 5 additions & 0 deletions examples/bare/background/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const Wappsto = require('wappsto-wapp');

Wappsto.startLogging();

console.log('Background wapp started and stopped');
5 changes: 5 additions & 0 deletions examples/bare/background/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"wappsto-wapp": "*"
}
}
18 changes: 18 additions & 0 deletions examples/bare/foreground/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdn.jsdelivr.net/npm/wappsto-wapp@latest/dist/wappsto-wapp.min.js"></script>
<script src="main.js"></script>
<title>Foreground Wapp</title>
</head>

<body>
<h1>Foreground Wapp</h1>

<script type="text/javascript">
start();
</script>
</body>
</html>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 10 additions & 2 deletions lib/wapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,16 @@ class Wapp {
dirs.concat(this.wapp_folders_create).forEach((f) => {
const path = folderMapping[f] || f;
files.createFolders(`${path}/.`);
if (createExamples && exampleFiles[f]) {
const exPath = `${__dirname}/../examples/${f}`;

if (exampleFiles[f]) {
let exPath = `${__dirname}/../examples/`;
if (createExamples) {
exPath += 'simple';
} else {
exPath += 'bare';
}
exPath += `/${f}`;

exampleFiles[f].forEach((file) => {
fs.copyFileSync(`${exPath}/${file}`, `${path}/${file}`);
});
Expand Down
11 changes: 9 additions & 2 deletions test/wapp.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ test('create new empty wapp', async (t) => {
t.deepEqual(files.fileExists('manifest.json'), true);
t.deepEqual(files.directoryExists('foreground'), true);
t.deepEqual(files.directoryExists('background'), false);
t.deepEqual(files.fileExists('foreground/index.html'), false);
t.deepEqual(files.fileExists('foreground/index.html'), true);
t.deepEqual(files.fileExists('foreground/main.js'), true);

const manifest = files.loadJsonFile('manifest.json');
t.deepEqual(manifest.name, answer.name);
Expand All @@ -107,6 +108,11 @@ test('create new empty wapp', async (t) => {
test('update empty files', async (t) => {
const wapp = new Wapp();

if (files.directoryExists('foreground')) {
files.deleteFile('foreground/main.js');
files.deleteFile('foreground/index.html');
}

const updatedFiles = await wapp.update();
t.deepEqual(updatedFiles, []);
});
Expand Down Expand Up @@ -418,7 +424,8 @@ test('create new custom wapp', async (t) => {
t.deepEqual(files.directoryExists('customForeground'), true);
t.deepEqual(files.directoryExists('customBackground'), false);
t.deepEqual(files.directoryExists('background'), false);
t.deepEqual(files.fileExists('customForeground/index.html'), false);
t.deepEqual(files.fileExists('customForeground/index.html'), true);
t.deepEqual(files.fileExists('customForeground/main.js'), true);

const manifest = files.loadJsonFile('manifest.json');
t.deepEqual(manifest.name, answer.name);
Expand Down

0 comments on commit 8716c17

Please sign in to comment.