Skip to content

Commit

Permalink
Support for set last modified
Browse files Browse the repository at this point in the history
For #120
  • Loading branch information
mfikes committed Apr 18, 2021
1 parent e13166f commit f9907dd
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 2 deletions.
7 changes: 6 additions & 1 deletion Clojure/src/ambly/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,12 @@
expected-clojurescript-version ".\n"))))))
(repl/evaluate-form repl-env env "<cljs repl>"
'(set! *print-newline* true))
{:merge-opts {:output-dir webdav-mount-point}})
{:merge-opts {:output-dir webdav-mount-point
:set-last-modified (fn [^File file last-modified]
(repl/evaluate-form repl-env env "<cljs repl>"
`(js/AMBLY_SET_LAST_MODIFIED
~(subs (str file) (count webdav-mount-point))
~last-modified)))}})
(catch Throwable t
(tear-down repl-env)
(throw t))))
Expand Down
1 change: 1 addition & 0 deletions ObjectiveC/Ambly Demo/Ambly Demo CLI/App.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ - (BOOL)setup {
[self.contextManager setUpConsoleLog];
[self.contextManager setUpTimerFunctionality];
[self.contextManager setUpAmblyImportScript];
[self.contextManager setUpAmblySetLastModified];

self.replServer = [[ABYServer alloc] initWithContext:self.contextManager.context
compilerOutputDirectory:compilerOutputDirectory];
Expand Down
1 change: 1 addition & 0 deletions ObjectiveC/Ambly Demo/Ambly Demo/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[self.contextManager setUpConsoleLog];
[self.contextManager setUpTimerFunctionality];
[self.contextManager setUpAmblyImportScript];
[self.contextManager setUpAmblySetLastModified];

self.replServer = [[ABYServer alloc] initWithContext:self.contextManager.context
compilerOutputDirectory:compilerOutputDirectory];
Expand Down
5 changes: 5 additions & 0 deletions ObjectiveC/src/ABYContextManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
*/
- (void)setUpAmblyImportScript;

/**
Sets up `AMBLY_SET_LAST_MODIFIED` capability for the managed context.
*/
-(void)setUpAmblySetLastModified;

/**
Bootstraps the JavaScript environment so that goog require is set up to work properly.
Intended for use in dev when an app bundles up JavaScript files compiled using :optimizations :none.
Expand Down
36 changes: 36 additions & 0 deletions ObjectiveC/src/ABYContextManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,42 @@ -(void)setUpAmblyImportScript

}

-(void)setUpAmblySetLastModified
{
NSString* compilerOutputDirectoryPath = self.compilerOutputDirectory.path;

[ABYUtils installGlobalFunctionWithBlock:

^JSValueRef(JSContextRef ctx, size_t argc, const JSValueRef argv[]) {

if (argc == 2
&& JSValueGetType (ctx, argv[0]) == kJSTypeString
&& JSValueGetType (ctx, argv[1]) == kJSTypeNumber)
{
JSStringRef pathStrRef = JSValueToStringCopy(ctx, argv[0], NULL);
NSString* path = (__bridge_transfer NSString *) JSStringCopyCFString( kCFAllocatorDefault, pathStrRef );
JSStringRelease(pathStrRef);

double timestamp = JSValueToNumber(ctx, argv[1], NULL);
NSDate* lastModifiedDate = [NSDate dateWithTimeIntervalSince1970:timestamp/1000.0];

NSString* fullPath = [NSString stringWithFormat:@"%@/%@", compilerOutputDirectoryPath, path];

NSLog(@"SetLastModified: %@ %f", fullPath, timestamp);

NSDictionary* attr = [NSDictionary dictionaryWithObjectsAndKeys: lastModifiedDate, NSFileModificationDate, NULL];

[[NSFileManager defaultManager] setAttributes: attr ofItemAtPath: fullPath error: NULL];
}

return JSValueMakeUndefined(ctx);
}
name:@"AMBLY_SET_LAST_MODIFIED"
argList:@"path,timestamp"
inContext:_context];

}

-(void)bootstrapWithDepsFilePath:(NSString*)depsFilePath googBasePath:(NSString*)googBasePath
{
// Setup CLOSURE_IMPORT_SCRIPT
Expand Down
2 changes: 1 addition & 1 deletion deps.edn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{:paths ["Clojure/src"]
:deps
{org.clojure/clojurescript {:mvn/version "1.10.339"}
{org.clojure/clojurescript {:git/url "https://github.com/clojure/clojurescript" :sha "87b8177228132dce6eaf68524decafbee83f5b34"}
org.jmdns/jmdns {:mvn/version "3.5.5"}}}

0 comments on commit f9907dd

Please sign in to comment.