Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Harmonic programmatically #96

Open
jaydson opened this issue Dec 10, 2014 · 15 comments
Open

Using Harmonic programmatically #96

jaydson opened this issue Dec 10, 2014 · 15 comments

Comments

@jaydson
Copy link
Contributor

jaydson commented Dec 10, 2014

We can turn Harmonic into a module that can be loaded locally, so other modules can use it programmatically.
Example:

var harmonic = require('harmonic');
harmonic.init();
harmonic.newPost('my post');
harmonic.build();

I think that feature will be helpful in some way.

@UltCombo
Copy link
Member

Sounds good to me. The API would be useful for unit tests as well.

@jaydson
Copy link
Contributor Author

jaydson commented Dec 10, 2014

Yep! I'll create a branch for that.

UltCombo added a commit that referenced this issue Dec 24, 2014
…ith 6to5

Closes #86
Closes #87
Paving the way for #96 (allow APIs to receive a sitePath argument)

TODO check if build's copySrc is copying files which have been negated by globs before being re-included
TODO check why build task takes so long to finish when passing an absolute sitePath argument and CWD != sitePath (the `harmonic build`  in the unit test takes about 11 seconds to finish in Windows)
@UltCombo
Copy link
Member

How should the API look like?

Rough idea I had:

var harmonic = require('harmonic');

// Factory pattern (like express), to cover use cases that manipulate multiple Harmonic sites.
// The factory constructor takes a sitePath argument that is saved in the instance,
// to avoid repeating it in every .init()/.config()/.build()/.run() call.
var mySite = harmonic('path/to/my/site');

// all async methods return promises
var promise = mySite.init();

promise.then(function() {
    return mySite.build();
}).then(function() {
    console.log('all done!');
}, function(err) {
    console.log('Something went wrong', err);
});

I believe we should give this some priority, so we can write tests for the API instead of using child processes. This way we can throw more meaningful errors without as much effort, and the tests will run much faster which is great for the incremental build workflow (npm run dev) giving faster feedback.

@UltCombo
Copy link
Member

IMO we should make an API asap, expose it to users to experiment and gather feedback, then release Harmonic 1.0.0. From then on, we can follow semantic versioning. What do you think @jaydson?

@jaydson
Copy link
Contributor Author

jaydson commented Feb 3, 2015

Totally agree.
We just need to assign who will do what.

@UltCombo
Copy link
Member

UltCombo commented Feb 3, 2015

I believe it doesn't matter much who does it, as long as we agree on an API design. =]

@UltCombo
Copy link
Member

UltCombo commented Feb 3, 2015

I believe we can assign issues to ourselves when we start working on them, so others will know there's someone working on it.

@jaydson
Copy link
Contributor Author

jaydson commented Feb 3, 2015

That's a good approach.
I only want assignment to avoid duplicated development.

@UltCombo
Copy link
Member

UltCombo commented Feb 3, 2015

@jaydson yes, we can use GitHub's issue assignment for that purpose. =]
It would also be nice if we make small, incremental commits (to WIP branches) so that we can provide opinions/suggestions/help to one another as well. Of course, if you prefer to make huge commits on things that you can handle yourself, there's no problem either.

@jaydson
Copy link
Contributor Author

jaydson commented Feb 3, 2015

Yep, sounds good 👍

jaydson pushed a commit that referenced this issue Feb 9, 2015
@jaydson
Copy link
Contributor Author

jaydson commented Feb 9, 2015

WIP > 432977c

Basic example using it:

var Harmonic = require('harmonic');
var mysite = new Harmonic('./path');
mysite.init()
.then(function(data) {
    console.log(data);
});

mysite.newPost()
.then(function(data) {
    console.log(data);
});


mysite.build()
.then(function(data) {
    console.log(data);
});

One of the benefits of a promise-based API: we can use async/await.

(async function(){
  let mysite = new Harmonic('path');
  await mysite.init();
  await mysite.newPost();
  await mysite.build();
}());

@UltCombo
Copy link
Member

UltCombo commented Feb 9, 2015

Nice! 👍
Also see 432977c#commitcomment-9663682

@UltCombo
Copy link
Member

UltCombo commented Feb 9, 2015

While at it, perhaps we should do some major refactoring/code organization? Maybe parser.js could become the main Harmonic class.

@jaydson
Copy link
Contributor Author

jaydson commented Feb 10, 2015

Yes, i was thinking exactly the same.

@jaydson
Copy link
Contributor Author

jaydson commented Feb 10, 2015

#117

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants