extract scripts into directive