Skip to content

Commit

Permalink
fix(targets): allow web to be compiled for prod (#61)
Browse files Browse the repository at this point in the history
* fix(targets): allow web to be compiled for prod

* chore(targets): regenerate goldens
  • Loading branch information
roperzh committed Nov 14, 2019
1 parent 600cc44 commit c5d0dae
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 21 deletions.
3 changes: 2 additions & 1 deletion examples/poodle-surf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"build-ios": "diez-cli compile -t ios -o ios && cd ios && pod install",
"run-android": "diez-cli compile -t android -o android -d",
"build-android": "diez-cli compile -t android -o android",
"run-web": "diez-cli compile -t web -o web -d"
"run-web": "diez-cli compile -t web -o web -d",
"build-web": "diez compile -t web -o web --baseUrl /ds/ --staticRoot web/public/ds && cd web && yarn build"
},
"dependencies": {
"@diez/designsystem": "^1.0.0-beta.0",
Expand Down
2 changes: 2 additions & 0 deletions examples/poodle-surf/web/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*

public/ds
9 changes: 2 additions & 7 deletions packages/targets/sources/web/bindings/File.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class File {
constructor({src}) {
constructor ({src}) {
this.src = src;
}

Expand All @@ -15,12 +15,7 @@ class File {
Object.defineProperties(File.prototype, {
url: {
get () {
if (Environment.isDevelopment) {
return `${Environment.serverUrl}${this.src}`;
}

// TODO: figure out how this should actually work.
return this.src;
return `${Environment.serverUrl}${this.src}`;
},
},
});
Expand Down
2 changes: 2 additions & 0 deletions packages/targets/sources/web/sdk/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const Environment = {
{{#if devMode}}
serverUrl: 'http://{{{hostname}}}:{{{devPort}}}/',
{{else}}
serverUrl: '{{baseUrl}}',
{{/if}}
isDevelopment: {{{devMode}}},
};
Expand Down
2 changes: 1 addition & 1 deletion packages/targets/sources/web/web.component.handlebars
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class {{{componentName}}} {
{{#if singleton}}
constructor() {
constructor () {
{{#each properties}}
this.{{{@key}}} = {{{this.initializer}}};
{{/each}}
Expand Down
7 changes: 6 additions & 1 deletion packages/targets/src/targets/web.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,11 @@ export class WebCompiler extends TargetCompiler<WebOutput, WebBinding> {
* @abstract
*/
get staticRoot () {
return join(this.output.sdkRoot, 'static');
if (this.program.options.devMode) {
return join(this.output.sdkRoot, 'static');
}

return this.program.options.staticRoot || '/';
}

/**
Expand Down Expand Up @@ -256,6 +260,7 @@ export class WebCompiler extends TargetCompiler<WebOutput, WebBinding> {
const tokens = {
devPort,
hostname,
baseUrl: this.program.options.baseUrl,
hostPackageName: guessHostPackageName(this.program.options.outputPath),
devMode: !!this.program.options.devMode,
dependencies: Array.from(this.output.dependencies),
Expand Down
11 changes: 3 additions & 8 deletions packages/targets/test/goldens/Bindings-web/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const Environment = {
module.exports = {};

class File {
constructor({src}) {
constructor ({src}) {
this.src = src;
}

Expand All @@ -22,12 +22,7 @@ class File {
Object.defineProperties(File.prototype, {
url: {
get () {
if (Environment.isDevelopment) {
return `${Environment.serverUrl}${this.src}`;
}

// TODO: figure out how this should actually work.
return this.src;
return `${Environment.serverUrl}${this.src}`;
},
},
});
Expand Down Expand Up @@ -303,7 +298,7 @@ class HaikuComponent {
module.exports.HaikuComponent = HaikuComponent;

class Bindings {
constructor() {
constructor () {
this.image = new Image({file1x: new File({src: "assets/image%20with%20spaces.jpg"}), file2x: new File({src: "assets/image%20with%20spaces@2x.jpg"}), file3x: new File({src: "assets/image%20with%20spaces@3x.jpg"}), width: 246, height: 246});
this.svg = new SVG({src: "assets/image.svg"});
this.lottie = new Lottie({file: new File({src: "assets/lottie.json"})});
Expand Down
6 changes: 3 additions & 3 deletions packages/targets/test/goldens/Primitives-web/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const Environment = {
module.exports = {};

class ChildComponent {
constructor() {
constructor () {
this.diez = 10;
}

Expand All @@ -23,7 +23,7 @@ class ChildComponent {
module.exports.ChildComponent = ChildComponent;

class EmptyComponent {
constructor() {
constructor () {
}

update (payload) {
Expand All @@ -38,7 +38,7 @@ class EmptyComponent {
module.exports.EmptyComponent = EmptyComponent;

class Primitives {
constructor() {
constructor () {
this.number = 10;
this.integer = 10;
this.float = 10;
Expand Down

0 comments on commit c5d0dae

Please sign in to comment.