-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
major upgrade to the MemServer initialization
- Loading branch information
Showing
9 changed files
with
162 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require('@std/esm'); | ||
|
||
import MemServer from '../../index.js'; | ||
|
||
MemServer.start(); | ||
|
||
window.$.getJSON('/photos'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,17 @@ | ||
export default [ | ||
{ | ||
id: 1, | ||
name: 'Ski trip', | ||
href: 'ski-trip.jpeg' | ||
}, | ||
{ | ||
id: 2, | ||
name: 'Family photo', | ||
href: 'family-photo.jpeg' | ||
}, | ||
{ | ||
id: 3, | ||
name: 'Selfie', | ||
href: 'selfie.jpeg' | ||
} | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { Model } from 'memserver'; | ||
import Model from '../../../../lib/mem-server/model'; | ||
|
||
export default Model.extend({ | ||
export default Object.assign(Model, { | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,51 @@ | ||
export function start(options) { | ||
// read current path to see if there is memserver | ||
|
||
const MemServer = { | ||
DB: {}, | ||
Models: {}, | ||
Pretender: {}, | ||
Routes: [], | ||
start() { | ||
|
||
}, | ||
shutdown() { | ||
|
||
} | ||
import fs from 'fs'; | ||
import chalk from 'chalk'; | ||
import stringUtils from 'ember-cli-string-utils'; | ||
|
||
const inflect = require('i')(); // NOTE: make this ES6 import | ||
|
||
if (!fs.existsSync('memserver')) { | ||
throw new Error(chalk.red('/memserver folder doesn\'t exist for this directory!')); | ||
} | ||
|
||
const modelFileNames = fs.readdirSync('memserver/models'); | ||
const Models = modelFileNames.reduce((result, modelFileName) => { | ||
const ModelName = stringUtils.classify(modelFileName.slice(0, -3)); | ||
|
||
result[ModelName] = require(`./memserver/models/${modelFileName}`).default; // NOTE: make this ES6 import | ||
result[ModelName].modelName = ModelName; | ||
return result; | ||
}, {}); | ||
|
||
const DB = Object.keys(Models).reduce((result, modelName) => { | ||
console.log('modelName is', modelName); | ||
const fileName = stringUtils.dasherize(inflect.pluralize(modelName)); | ||
console.log('fileName is', fileName); | ||
const path = `./memserver/fixtures/${fileName}.js`; | ||
|
||
if (fs.existsSync(path)) { | ||
result[modelName] = require(path).default; // NOTE: make this ES6 import | ||
// TODO: maybe check ids must exist and all of them are integers | ||
} | ||
|
||
return result; | ||
}, {}); | ||
|
||
|
||
return MemServer | ||
} | ||
export default { | ||
DB: DB, | ||
Models: Models, | ||
Pretender: {}, | ||
Routes: [], | ||
start(options) { | ||
delete this.start; | ||
|
||
return this; | ||
}, | ||
shutdown() { | ||
|
||
} | ||
} | ||
|
||
|
||
// BUILD A CLI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters